@Test public void testPixelRescaleFull() throws Exception { BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_GRAY); bi.getRaster().getDataBuffer().setElemDouble(0, 0, 10); RenderedImage result = ImageUtilities.applyRescaling(new Double[] {10d}, new Double[] {1d}, bi, null); assertEquals(DataBuffer.TYPE_DOUBLE, result.getSampleModel().getDataType()); assertThat(result.getColorModel(), CoreMatchers.instanceOf(ComponentColorModel.class)); double[] pixel = new double[1]; result.getData().getPixel(0, 0, pixel); assertEquals(101, pixel[0], 0d); }
public static RenderedImage applyRescaling( Double[] scales, Double[] offsets, RenderedImage image, Hints hints) { if (scales == null && offsets == null) { return image; } int numBands = image.getSampleModel().getNumBands(); double[] pscales = toPrimitiveArray(scales, numBands, 1); double[] poffsets = toPrimitiveArray(offsets, numBands, 0); boolean hasRescaling = false; for (int i = 0; i < numBands && !hasRescaling; i++) { hasRescaling = poffsets[i] != 0 || pscales[i] != 1; } if (!hasRescaling) { return image; } RenderingHints localHints = hints != null ? hints.clone() : (RenderingHints) JAI.getDefaultInstance().getRenderingHints().clone(); final ImageLayout layout = Optional.ofNullable((ImageLayout) localHints.get(JAI.KEY_IMAGE_LAYOUT)) .map(il -> (ImageLayout) il.clone()) .orElse(new ImageLayout2(image)); SampleModel sm = RasterFactory.createBandedSampleModel( DataBuffer.TYPE_DOUBLE, image.getTileWidth(), image.getTileHeight(), image.getSampleModel().getNumBands()); layout.setSampleModel(sm); layout.setColorModel( new ComponentColorModel( new BogusColorSpace(numBands), false, false, Transparency.OPAQUE, DataBuffer.TYPE_DOUBLE)); localHints.put(JAI.KEY_IMAGE_LAYOUT, layout); ImageWorker iw = new ImageWorker(image); iw.setRenderingHints(localHints); iw.rescale(pscales, poffsets); return iw.getRenderedImage(); }
ImageUtilities { public static RenderedImage applyRescaling( Double[] scales, Double[] offsets, RenderedImage image, Hints hints) { if (scales == null && offsets == null) { return image; } int numBands = image.getSampleModel().getNumBands(); double[] pscales = toPrimitiveArray(scales, numBands, 1); double[] poffsets = toPrimitiveArray(offsets, numBands, 0); boolean hasRescaling = false; for (int i = 0; i < numBands && !hasRescaling; i++) { hasRescaling = poffsets[i] != 0 || pscales[i] != 1; } if (!hasRescaling) { return image; } RenderingHints localHints = hints != null ? hints.clone() : (RenderingHints) JAI.getDefaultInstance().getRenderingHints().clone(); final ImageLayout layout = Optional.ofNullable((ImageLayout) localHints.get(JAI.KEY_IMAGE_LAYOUT)) .map(il -> (ImageLayout) il.clone()) .orElse(new ImageLayout2(image)); SampleModel sm = RasterFactory.createBandedSampleModel( DataBuffer.TYPE_DOUBLE, image.getTileWidth(), image.getTileHeight(), image.getSampleModel().getNumBands()); layout.setSampleModel(sm); layout.setColorModel( new ComponentColorModel( new BogusColorSpace(numBands), false, false, Transparency.OPAQUE, DataBuffer.TYPE_DOUBLE)); localHints.put(JAI.KEY_IMAGE_LAYOUT, layout); ImageWorker iw = new ImageWorker(image); iw.setRenderingHints(localHints); iw.rescale(pscales, poffsets); return iw.getRenderedImage(); } }
ImageUtilities { public static RenderedImage applyRescaling( Double[] scales, Double[] offsets, RenderedImage image, Hints hints) { if (scales == null && offsets == null) { return image; } int numBands = image.getSampleModel().getNumBands(); double[] pscales = toPrimitiveArray(scales, numBands, 1); double[] poffsets = toPrimitiveArray(offsets, numBands, 0); boolean hasRescaling = false; for (int i = 0; i < numBands && !hasRescaling; i++) { hasRescaling = poffsets[i] != 0 || pscales[i] != 1; } if (!hasRescaling) { return image; } RenderingHints localHints = hints != null ? hints.clone() : (RenderingHints) JAI.getDefaultInstance().getRenderingHints().clone(); final ImageLayout layout = Optional.ofNullable((ImageLayout) localHints.get(JAI.KEY_IMAGE_LAYOUT)) .map(il -> (ImageLayout) il.clone()) .orElse(new ImageLayout2(image)); SampleModel sm = RasterFactory.createBandedSampleModel( DataBuffer.TYPE_DOUBLE, image.getTileWidth(), image.getTileHeight(), image.getSampleModel().getNumBands()); layout.setSampleModel(sm); layout.setColorModel( new ComponentColorModel( new BogusColorSpace(numBands), false, false, Transparency.OPAQUE, DataBuffer.TYPE_DOUBLE)); localHints.put(JAI.KEY_IMAGE_LAYOUT, layout); ImageWorker iw = new ImageWorker(image); iw.setRenderingHints(localHints); iw.rescale(pscales, poffsets); return iw.getRenderedImage(); } private  ImageUtilities(); }
ImageUtilities { public static RenderedImage applyRescaling( Double[] scales, Double[] offsets, RenderedImage image, Hints hints) { if (scales == null && offsets == null) { return image; } int numBands = image.getSampleModel().getNumBands(); double[] pscales = toPrimitiveArray(scales, numBands, 1); double[] poffsets = toPrimitiveArray(offsets, numBands, 0); boolean hasRescaling = false; for (int i = 0; i < numBands && !hasRescaling; i++) { hasRescaling = poffsets[i] != 0 || pscales[i] != 1; } if (!hasRescaling) { return image; } RenderingHints localHints = hints != null ? hints.clone() : (RenderingHints) JAI.getDefaultInstance().getRenderingHints().clone(); final ImageLayout layout = Optional.ofNullable((ImageLayout) localHints.get(JAI.KEY_IMAGE_LAYOUT)) .map(il -> (ImageLayout) il.clone()) .orElse(new ImageLayout2(image)); SampleModel sm = RasterFactory.createBandedSampleModel( DataBuffer.TYPE_DOUBLE, image.getTileWidth(), image.getTileHeight(), image.getSampleModel().getNumBands()); layout.setSampleModel(sm); layout.setColorModel( new ComponentColorModel( new BogusColorSpace(numBands), false, false, Transparency.OPAQUE, DataBuffer.TYPE_DOUBLE)); localHints.put(JAI.KEY_IMAGE_LAYOUT, layout); ImageWorker iw = new ImageWorker(image); iw.setRenderingHints(localHints); iw.rescale(pscales, poffsets); return iw.getRenderedImage(); } private  ImageUtilities(); static ImageLayout getImageLayout(final RenderedImage image); static RenderingHints getRenderingHints(final RenderedImage image); static Dimension toTileSize(final Dimension size); static ImageLayout createIntersection(
            final ImageLayout layout, final List<RenderedImage> sources); static Interpolation toInterpolation(final Object type); static String getInterpolationName(Interpolation interp); static RenderedOp tileImage(final RenderedOp image); static void fill(final WritableRenderedImage image, final Number value); static boolean isMediaLibAvailable(); static void disposePlanarImageChain(PlanarImage pi); static RenderedImage maskColor(final Color transparentColor, final RenderedImage image); static ImageReadParam cloneImageReadParam(ImageReadParam param); static Rectangle2D layoutHelper(
            RenderedImage source,
            float scaleX,
            float scaleY,
            float transX,
            float transY,
            Interpolation interp); static ReferencedEnvelope getReferencedEnvelopeFromGeographicBoundingBox(
            final GeographicBoundingBox geographicBBox); static ReferencedEnvelope getWGS84ReferencedEnvelope(
            final GeneralEnvelope coverageEnvelope); static Rectangle getDimension(
            final int imageIndex, final ImageInputStream inStream, final ImageReader reader); static final boolean checkEmptySourceRegion(
            final ImageReadParam readParameters, final Rectangle dimensions); static Number[] getBackgroundValues(
            final SampleModel sampleModel, final double[] backgroundValues); static void disposeImage(RenderedImage inputImage); static void disposeSinglePlanarImage(PlanarImage planarImage); static String getDatabufferTypeName(int dataType); static RenderedImage applyRescaling(
            Double[] scales, Double[] offsets, RenderedImage image, Hints hints); }
ImageUtilities { public static RenderedImage applyRescaling( Double[] scales, Double[] offsets, RenderedImage image, Hints hints) { if (scales == null && offsets == null) { return image; } int numBands = image.getSampleModel().getNumBands(); double[] pscales = toPrimitiveArray(scales, numBands, 1); double[] poffsets = toPrimitiveArray(offsets, numBands, 0); boolean hasRescaling = false; for (int i = 0; i < numBands && !hasRescaling; i++) { hasRescaling = poffsets[i] != 0 || pscales[i] != 1; } if (!hasRescaling) { return image; } RenderingHints localHints = hints != null ? hints.clone() : (RenderingHints) JAI.getDefaultInstance().getRenderingHints().clone(); final ImageLayout layout = Optional.ofNullable((ImageLayout) localHints.get(JAI.KEY_IMAGE_LAYOUT)) .map(il -> (ImageLayout) il.clone()) .orElse(new ImageLayout2(image)); SampleModel sm = RasterFactory.createBandedSampleModel( DataBuffer.TYPE_DOUBLE, image.getTileWidth(), image.getTileHeight(), image.getSampleModel().getNumBands()); layout.setSampleModel(sm); layout.setColorModel( new ComponentColorModel( new BogusColorSpace(numBands), false, false, Transparency.OPAQUE, DataBuffer.TYPE_DOUBLE)); localHints.put(JAI.KEY_IMAGE_LAYOUT, layout); ImageWorker iw = new ImageWorker(image); iw.setRenderingHints(localHints); iw.rescale(pscales, poffsets); return iw.getRenderedImage(); } private  ImageUtilities(); static ImageLayout getImageLayout(final RenderedImage image); static RenderingHints getRenderingHints(final RenderedImage image); static Dimension toTileSize(final Dimension size); static ImageLayout createIntersection(
            final ImageLayout layout, final List<RenderedImage> sources); static Interpolation toInterpolation(final Object type); static String getInterpolationName(Interpolation interp); static RenderedOp tileImage(final RenderedOp image); static void fill(final WritableRenderedImage image, final Number value); static boolean isMediaLibAvailable(); static void disposePlanarImageChain(PlanarImage pi); static RenderedImage maskColor(final Color transparentColor, final RenderedImage image); static ImageReadParam cloneImageReadParam(ImageReadParam param); static Rectangle2D layoutHelper(
            RenderedImage source,
            float scaleX,
            float scaleY,
            float transX,
            float transY,
            Interpolation interp); static ReferencedEnvelope getReferencedEnvelopeFromGeographicBoundingBox(
            final GeographicBoundingBox geographicBBox); static ReferencedEnvelope getWGS84ReferencedEnvelope(
            final GeneralEnvelope coverageEnvelope); static Rectangle getDimension(
            final int imageIndex, final ImageInputStream inStream, final ImageReader reader); static final boolean checkEmptySourceRegion(
            final ImageReadParam readParameters, final Rectangle dimensions); static Number[] getBackgroundValues(
            final SampleModel sampleModel, final double[] backgroundValues); static void disposeImage(RenderedImage inputImage); static void disposeSinglePlanarImage(PlanarImage planarImage); static String getDatabufferTypeName(int dataType); static RenderedImage applyRescaling(
            Double[] scales, Double[] offsets, RenderedImage image, Hints hints); static final double[][] RGB_TO_GRAY_MATRIX; static final double[][] RGBA_TO_GRAY_MATRIX; static final RenderingHints DONT_REPLACE_INDEX_COLOR_MODEL; static final RenderingHints REPLACE_INDEX_COLOR_MODEL; static final RenderingHints NN_INTERPOLATION_HINT; static final RenderingHints NOCACHE_HINT; static final RenderingHints EXTEND_BORDER_BY_COPYING; static final RenderingHints EXTEND_BORDER_BY_REFLECT; static final String[] INTERPOLATION_NAMES; static final int[] INTERPOLATION_TYPES; static final BorderExtender DEFAULT_BORDER_EXTENDER; static final RenderingHints BORDER_EXTENDER_HINTS; static final String DIRECT_KAKADU_PLUGIN; static final float RATIONAL_TOLERANCE; }