/** * @param id desired filter to be applied to a bitmap * @param src bitmap source image to be filtered * @return src bitmap with filter applied */ public static Bitmap applyFilter(int id, Bitmap src) { FastBitmap img = new FastBitmap(src); img.toRGB(); // Interface for generic filter IBaseInPlace filter = null; switch (id) { case FILTER_NONE: break; case FILTER_SEPIA: filter = new Sepia(); break; case FILTER_GRAYSCALE: filter = new Grayscale(); break; case FILTER_EMBOSS: filter = new Emboss(); break; case FILTER_INVERT: filter = new Invert(); break; case FILTER_BLUR: filter = new Blur(); break; case FILTER_SHARPEN: filter = new Sharpen(); break; case FILTER_MORPH: filter = new Morph(); break; case FILTER_BRIGHTNESS: filter = new BrightnessCorrection(); break; case FILTER_GAUSSIAN: filter = new GaussianBlur(); break; default: break; } if (filter != null) { filter.applyInPlace(img); } return img.toBitmap(); }
@Override public void applyInPlace(FastBitmap fastBitmap) { if (fastBitmap.isRGB()) { fastBitmap.toGrayscale(); } if (invert) new Invert().applyInPlace(fastBitmap); int size = fastBitmap.getWidth() * fastBitmap.getHeight(); int min = ImageStatistics.Minimum(fastBitmap); int max = ImageStatistics.Maximum(fastBitmap); fastBitmap.toRGB(); for (int i = 0; i < size; i++) { int[] rgb = GrayscaleToHeatMap(fastBitmap.getRed(i), min, max); fastBitmap.setRGB(i, rgb); } }