Scaling src bitmap to fill dest bitmap with centering. Method keep aspect ratio.

@param src        source bitmap
@param dest       destination bitmap
@param clearColor color for clearing dest before drawing
193410
public static void scaleFill(Bitmap src, Bitmap dest, int clearColor) {
        float ratio = Math.max(dest.getWidth() / (float) src.getWidth(), dest.getHeight() / (float) src.getHeight());
        int newW = (int) (src.getWidth() * ratio);
        int newH = (int) (src.getHeight() * ratio);
        int paddingTop = (dest.getHeight() - (int) (src.getHeight() * ratio)) / 2;
        int paddingLeft = (dest.getWidth() - (int) (src.getWidth() * ratio)) / 2;

        scale(src, dest, clearColor, 0, 0, src.getWidth(), src.getHeight(), paddingLeft, paddingTop,
                newW + paddingLeft,
                newH + paddingTop);
    }
551468
public static void scale(Image srcImage, ImageOutputStream destImageStream, int width, int height, Color fixedColor) throws IORuntimeException {
		writeJpg(scale(srcImage, width, height, fixedColor), destImageStream);
	}
757748
function (width, height, interpolation) {
		this.widthOriginal = parseInt(this.width);
		this.heightOriginal = parseInt(this.height);
		this.targetWidth = Math.abs(parseInt(width) || 0);
		this.targetHeight = Math.abs(parseInt(height) || 0);
		this.colorChannels = 4;
		this.interpolationPass = !!interpolation;

		this.targetWidthMultipliedByChannels = this.targetWidth * this.colorChannels;
		this.originalWidthMultipliedByChannels = this.widthOriginal * this.colorChannels;
		this.originalHeightMultipliedByChannels = this.heightOriginal * this.colorChannels;
		this.widthPassResultSize = this.targetWidthMultipliedByChannels * this.heightOriginal;
		this.finalResultSize = this.targetWidthMultipliedByChannels * this.targetHeight;
		
		
		if (this.widthOriginal == this.targetWidth) { //Bypass the width resizer pass:
			this.resizeWidth = this._bypassResizer;
		}
		else { //Setup the width resizer pass:
			this.ratioWeightWidthPass = this.widthOriginal / this.targetWidth;
			if (this.ratioWeightWidthPass < 1 && this.interpolationPass) {
				this._initializeFirstPassBuffers(true);
				this.resizeWidth = this._resizeWidthInterpolatedRGBA;
			}
			else {
				this._initializeFirstPassBuffers(false);
				this.resizeWidth = this._resizeWidthRGBA;
			}
		}
		if (this.heightOriginal == this.targetHeight) { //Bypass the height resizer pass:
			this.resizeHeight = this._bypassResizer;
		}
		else {	
			//Setup the height resizer pass:
			this.ratioWeightHeightPass = this.heightOriginal / this.targetHeight;
			if (this.ratioWeightHeightPass < 1 && this.interpolationPass) {
				this._initializeSecondPassBuffers(true);
				this.resizeHeight = this._resizeHeightInterpolated;
			}
			else {
				this._initializeSecondPassBuffers(false);
				this.resizeHeight = this._resizeHeightRGBA;
			}
		}
		
		this.data = this.resizeHeight(this.resizeWidth(this.data));
		
		this.width = width;
		this.height = height;
	}
479428
public static void scale(Image srcImg, ImageOutputStream destImageStream, float scale) throws IORuntimeException {
		writeJpg(scale(srcImg, scale), destImageStream);
	}
1103498
private void fillInternalShadowRounded(Graphics2D g, Shape s) {
        g.setPaint(getRoundedShadowGradient(s));
        g.fill(s);
    }
115233
public static void scale(ImageInputStream srcStream, ImageOutputStream destStream, float scale) {
		scale(read(srcStream), destStream, scale);
	}
935214
public static void bufferedToGray(DataBufferUShort buffer , WritableRaster src, GrayI16 dst) {
		short[] srcData = buffer.getData();

		int numBands = src.getNumBands();

		int size = dst.getWidth() * dst.getHeight();

		int srcStride = stride(src);
		int srcOffset = getOffset(src);
		int srcStrideDiff = srcStride-src.getNumDataElements()*dst.width;

		if (numBands == 1) {
			if (dst.startIndex == 0 && dst.width == dst.stride && srcStrideDiff == 0 && srcOffset == 0 )
				System.arraycopy(srcData, 0, dst.data, 0, size);
			else {
				//CONCURRENT_BELOW BoofConcurrency.loopFor(0, dst.height, y -> {
				for (int y = 0; y < dst.height; y++) {
					int indexDst = dst.startIndex + dst.stride * y;
					int indexSrc = srcOffset + srcStride * y;

					System.arraycopy(srcData, indexSrc, dst.data, indexDst, dst.width);
				}
				//CONCURRENT_ABOVE });
			}
		} else {
			throw new RuntimeException("Only single band images are currently support for 16bit");
		}
	}
226857
public void fillEllipse(Rectangle rect, Color color) {
		template.saveState();
		setFill(color);
		template.ellipse(origX + rect.getLeft(), origY + rect.getBottom(), origX + rect.getRight(),
				origY + rect.getTop());
		template.fill();
		template.restoreState();
	}
1360304
public static Image scale(Image srcImage, int width, int height, Color fixedColor) {
		return Img.from(srcImage).scale(width, height, fixedColor).getImg();
	}
578580
public synchronized void returnBitmap(Bitmap bitmap) {
        if (bitmap == null || bitmapsBySize.contains(bitmap) ) {
            return;
        } else if(getBitmapSize(bitmap) > sizeLimit || !canBePooled(bitmap)) {
            return;
        }
        bitmapsByLastUse.add(bitmap);
        int pos = Collections.binarySearch(bitmapsBySize, bitmap, BITMAP_COMPARATOR);
        if (pos < 0) {
            pos = -pos - 1;
        }
        bitmapsBySize.add(pos, bitmap);
        currentSize += getBitmapSize(bitmap);
        trim();
    }
644072
private void horizontallyFromSrcToWorkGray(BufferedImage srcImg, byte[][] workPixels, int start, int delta) {
    final
    int[]
      tempPixels =
      new int[srcWidth];   // Used if we work on int based bitmaps, later used to keep channel values
    final byte[] srcPixels = new byte[srcWidth]; // create reusable row to minimize memory overhead

    for (int k = start; k < srcHeight; k = k + delta) {
      ImageUtils.getPixelsBGR(srcImg, k, srcWidth, srcPixels, tempPixels);

      for (int i = dstWidth - 1; i >= 0; i--) {
        final int max = horizontalSubsamplingData.arrN[i];

        float sample0 = 0.0f;
        int index = i * horizontalSubsamplingData.numContributors;
        for (int j = max - 1; j >= 0; j--) {
          float arrWeight = horizontalSubsamplingData.arrWeight[index];
          int pixelIndex = horizontalSubsamplingData.arrPixel[index];

          sample0 += (srcPixels[pixelIndex] & 0xff) * arrWeight;
          index++;
        }

        workPixels[k][i] = toByte(sample0);
      }
    }
  }
402079
public static Bitmap flip(Bitmap src) {
        Matrix m = new Matrix();
        m.preScale(-1, 1);
        return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), m, false);
    }
1187607
public static void setBitmapRange(long[] bitmap, int start, int end) {
    if (start == end) {
      return;
    }
    int firstword = start / 64;
    int endword = (end - 1) / 64;
    if (firstword == endword) {
      bitmap[firstword] |= (~0L << start) & (~0L >>> -end);
      return;
    }
    bitmap[firstword] |= ~0L << start;
    for (int i = firstword + 1; i < endword; i++) {
      bitmap[i] = ~0L;
    }
    bitmap[endword] |= ~0L >>> -end;
  }
465319
@SuppressWarnings("DeprecatedIsStillUsed")
    @Deprecated
    public static Bitmap crop(Drawable drawable, State state, Settings settings) {
        if (drawable == null) {
            return null;
        }

        float zoom = state.getZoom();

        // Computing crop size for base zoom level (zoom == 1)
        int width = Math.round(settings.getMovementAreaW() / zoom);
        int height = Math.round(settings.getMovementAreaH() / zoom);

        // Crop area coordinates within viewport
        Rect pos = new Rect();
        GravityUtils.getMovementAreaPosition(settings, pos);

        Matrix matrix = new Matrix();
        state.get(matrix);
        // Scaling to base zoom level (zoom == 1)
        matrix.postScale(1f / zoom, 1f / zoom, pos.left, pos.top);
        // Positioning crop area
        matrix.postTranslate(-pos.left, -pos.top);

        try {
            // Draw drawable into bitmap
            Bitmap dst = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

            Canvas canvas = new Canvas(dst);
            canvas.concat(matrix);
            drawable.draw(canvas);

            return dst;
        } catch (OutOfMemoryError e) {
            return null; // Not enough memory for cropped bitmap
        }
    }
1368691
public static void clear(Image img) {
        Graphics g = img.getGraphics();
        
        try {
            if (g instanceof Graphics2D) {
                ((Graphics2D) g).setComposite(AlphaComposite.Clear);
            } else {
                g.setColor(new Color(0, 0, 0, 0));
            }
            
            g.fillRect(0, 0, img.getWidth(null), img.getHeight(null));
        } finally {
            g.dispose();
        }
    }
619690
public void set(Rect src) {
        this.left = src.left;
        this.top = src.top;
        this.right = src.right;
        this.bottom = src.bottom;
    }
868858
public void fill(Graphic g, ColorRgba color)
    {
        g.setColor(color);
        g.drawRect(0, 0, source.getWidth(), source.getHeight(), true);
    }