Calculating scale factor with limit of pixel amount

@param metadata  image metadata
@param maxPixels limit for pixels
@return scale factor
17961
private static int getScaleFactor(ImageMetadata metadata, int maxPixels) {
        int scale = 1;
        int scaledW = metadata.getW();
        int scaledH = metadata.getH();
        while (scaledW * scaledH > maxPixels) {
            scale *= 2;
            scaledH /= 2;
            scaledW /= 2;
        }
        return scale;
    }
721651
private void CheckTransparencyMask(IfdTags metadata, int n) {
    // Samples per pixel
    if (!metadata.containsTagId(TiffTags.getTagId("SamplesPerPixel"))) {
      validation.addErrorLoc("Missing Samples Per Pixel", "IFD" + n);
    } else {
      long spp = metadata.get(TiffTags.getTagId("SamplesPerPixel")).getFirstNumericValue();
      if (spp != 1) {
        validation.addError("Invalid Samples Per Pixel", "IFD" + n, spp);
      }
    }

    // BitsPerSample
    if (!metadata.containsTagId(TiffTags.getTagId("BitsPerSample"))) {
      validation.addErrorLoc("Missing BitsPerSample", "IFD" + n);
    } else {
      long bps = metadata.get(TiffTags.getTagId("BitsPerSample")).getFirstNumericValue();
      if (bps != 1) {
        validation.addError("Invalid BitsPerSample", "IFD" + n, bps);
      }
    }
  }
41143
public Point measureImage(Resources resources) {
        BitmapFactory.Options justBoundsOptions = new BitmapFactory.Options();
        justBoundsOptions.inJustDecodeBounds = true;

        if (bitmap != null) {
            return new Point(bitmap.getWidth(), bitmap.getHeight());
        } else if (resId != null) {
            BitmapFactory.decodeResource(resources, resId, justBoundsOptions);
            float scale = (float) justBoundsOptions.inTargetDensity / justBoundsOptions.inDensity;
            return new Point((int) (justBoundsOptions.outWidth * scale + 0.5f), (int) (justBoundsOptions.outHeight * scale + 0.5f));
        } else if (fileToBitmap != null) {
            BitmapFactory.decodeFile(fileToBitmap.getAbsolutePath(), justBoundsOptions);
        } else if (inputStream != null) {
            BitmapFactory.decodeStream(inputStream, null, justBoundsOptions);
            try {
                inputStream.reset();
            } catch (IOException ignored) {
            }
        } else if (view != null) {
            return new Point(view.getWidth(), view.getHeight());
        }
        return new Point(justBoundsOptions.outWidth, justBoundsOptions.outHeight);
    }
114267
protected static int getBytesPerPixel(Bitmap.Config config) {
        if (config == Bitmap.Config.ARGB_8888) {
            return 4;
        } else if (config == Bitmap.Config.RGB_565) {
            return 2;
        } else if (config == Bitmap.Config.ARGB_4444) {
            return 2;
        } else if (config == Bitmap.Config.ALPHA_8) {
            return 1;
        }
        return 1;
    }
600477
public CmsJspImageBean getSrcSetMaxImage() {

        CmsJspImageBean result = this;
        if (m_srcSet != null) {
            result = m_srcSet.lastEntry().getValue();
        }
        return result;
    }
831870
public static Bitmap loadBitmapOptimized(Uri uri, Context context) throws ImageLoadException {
        return loadBitmapOptimized(uri, context, MAX_PIXELS);
    }
725948
public static GrayF32 denseDisparitySubpixel(GrayU8 rectLeft , GrayU8 rectRight ,
												 int regionSize ,
												 int minDisparity , int maxDisparity )
	{
		// A slower but more accuracy algorithm is selected
		// All of these parameters should be turned
		StereoDisparity<GrayU8,GrayF32> disparityAlg =
				FactoryStereoDisparity.regionSubpixelWta(DisparityAlgorithms.RECT_FIVE,
						minDisparity, maxDisparity, regionSize, regionSize, 25, 1, 0.2, GrayU8.class);

		// process and return the results
		disparityAlg.process(rectLeft,rectRight);

		return disparityAlg.getDisparity();
	}
902438
public static Bitmap loadBitmapOptimized(String fileName, int limit) throws ImageLoadException {
        return loadBitmapOptimized(new FileSource(fileName), limit);
    }
355073
public VisualizerBuilder setBytesPerPixel(int bytes, long fileLength) {
		Preconditions.checkArgument(bytes > 0);
		double nrOfPixels = fileLength / (double) bytes;
		double pixelsPerRow = Math.floor(settings.fileWidth
				/ (double) settings.pixelSize);
		double pixelsPerCol = Math.ceil(nrOfPixels / (double) pixelsPerRow);
		settings.height = (int) Math.ceil(pixelsPerCol * settings.pixelSize);
		return this;
	}
963671
public static float pixelsFromSpResource(Context context, @DimenRes int sizeRes) {
        final Resources res = context.getResources();
        return res.getDimension(sizeRes) / res.getDisplayMetrics().density;
    }
918349
public static Bitmap shrink(Bitmap bitmap, float scale) {
        if (scale >= 1.0f) {
            return bitmap.copy(bitmap.getConfig(), false);
        }

        Matrix matrix = new Matrix();
        matrix.postScale(scale, scale);

        return Bitmap.createBitmap(bitmap, 0, 0, (int) (scale * bitmap.getWidth()), (int) (scale * bitmap.getHeight()), matrix, true);
    }
426766
public static float pixelToSip(Context context, float pixels) {
        DisplayMetrics metrics = new DisplayMetrics();
        float scaledDensity = metrics.scaledDensity;
        if (pixels == 0 || scaledDensity == 0) {
            return 1;
        }
        return pixels/scaledDensity;
    }
816982
@VisibleForTesting
    protected static Dimension getSize(
            final ScalebarAttributeValues scalebarParams,
            final ScaleBarRenderSettings settings, final Dimension maxLabelSize) {
        final float width;
        final float height;
        if (scalebarParams.getOrientation().isHorizontal()) {
            width = 2 * settings.getPadding()
                    + settings.getIntervalLengthInPixels() * scalebarParams.intervals
                    + settings.getLeftLabelMargin() + settings.getRightLabelMargin();
            height = 2 * settings.getPadding()
                    + settings.getBarSize() + settings.getLabelDistance()
                    + Label.getRotatedHeight(maxLabelSize, scalebarParams.getLabelRotation());
        } else {
            width = 2 * settings.getPadding()
                    + settings.getLabelDistance() + settings.getBarSize()
                    + Label.getRotatedWidth(maxLabelSize, scalebarParams.getLabelRotation());
            height = 2 * settings.getPadding()
                    + settings.getTopLabelMargin()
                    + settings.getIntervalLengthInPixels() * scalebarParams.intervals
                    + settings.getBottomLabelMargin();
        }
        return new Dimension((int) Math.ceil(width), (int) Math.ceil(height));
    }
1229316
function maxRadialRadius(context, options) {
    let pxRatio = SmartCanvas.pixelRatio;

    if (!context.maxRadius) {
        context.maxRadius = context.max
            - options.borderShadowWidth
            - options.borderOuterWidth * pxRatio
            - options.borderMiddleWidth * pxRatio
            - options.borderInnerWidth * pxRatio
            + (options.borderOuterWidth ? 0.5 : 0)
            + (options.borderMiddleWidth ? 0.5 : 0)
            + (options.borderInnerWidth ? 0.5 : 0);
    }

    return context.maxRadius;
}
1367480
@Nonnull
  public FineUploader5Validation setImageMaxHeight (@Nonnegative final int nImageMaxHeight)
  {
    ValueEnforcer.isGE0 (nImageMaxHeight, "ImageMaxHeight");
    m_nValidationImageMaxHeight = nImageMaxHeight;
    return this;
  }
464417
def scale_pixels(color, layer):
    """"""
    pixelmap = []

    # Scaling the pixel offsets.
    for pix_x in range(MAX_X + 1):
        for pix_y in range(MAX_Y + 1):

            # Horizontal pixels
            y1 = pix_y * dotsize[0]
            x1 = pix_x * dotsize[1]

            # Vertical pixels
            y2 = pix_y * dotsize[0] + (dotsize[0] - 1)
            x2 = pix_x * dotsize[1] + (dotsize[1] - 1)

            if (y1 <= MAX_Y) and (y2 <= MAX_Y):
                if (x1 <= MAX_X) and (x2 <= MAX_X):
                    if (pix_x, pix_y) in layer:
                        pixelmap.append([(y1, x1), (y2, x2), color])
    return pixelmap
600166
public static int pixelXToTileX(double pixelX, byte zoomLevel, int tileSize) {
        return (int) Math.min(Math.max(pixelX / tileSize, 0), Math.pow(2, zoomLevel) - 1);
    }