class ProcessingUtils {

   static float getScale(int orig_width, int orig_height, int width, int height)
         throws InconsistentImageScale
   {
      float orig_ratio=(float)orig_width/orig_height;
      float target_pix_number = (float)width*height;
      double target_height = Math.sqrt(target_pix_number/orig_ratio);
      double target_width = target_height * orig_ratio;
      if ((target_height < 1) || (target_width) < 1)
      {
         throw new InconsistentImageScale(
               String.format("Wrong image scale (%.2f,%.2f)", target_width, target_height));
      }
      float scale = (float)(target_height/orig_height);
      return scale;
   }

   private  ProcessingUtils();

}