ReinterpretDescriptor extends OperationDescriptorImpl { public static RenderedOp create(RenderedImage source, double factor, double offset, ScalingType scalingType, InterpretationType interpretationType, RenderingHints hints) { final ParameterBlockJAI pb = new ParameterBlockJAI("Reinterpret", RenderedRegistryMode.MODE_NAME); pb.setSource("source0", source); pb.setParameter(PARAM_NAME_FACTOR, factor); pb.setParameter(PARAM_NAME_OFFSET, offset); pb.setParameter(PARAM_NAME_SCALING_TYPE, scalingType); pb.setParameter(PARAM_NAME_INTERPRETATION_TYPE, interpretationType); return JAI.create("Reinterpret", pb, hints); } ReinterpretDescriptor(); static RenderedOp create(RenderedImage source, double factor, double offset,
                                    ScalingType scalingType, InterpretationType interpretationType,
                                    RenderingHints hints); static ImageLayout createTargetImageLayout(RenderedImage source, SampleModel sampleModel); static int getTargetDataType(int sourceDataType, double factor, double offset, ScalingType scalingType,
                                        InterpretationType interpretationType); static final String PARAM_NAME_FACTOR; static final String PARAM_NAME_OFFSET; static final String PARAM_NAME_SCALING_TYPE; static final String PARAM_NAME_INTERPRETATION_TYPE; static final InterpretationType AWT; static final InterpretationType INTERPRET_BYTE_SIGNED; static final InterpretationType INTERPRET_INT_UNSIGNED; static final ScalingType LINEAR; static final ScalingType EXPONENTIAL; static final ScalingType LOGARITHMIC; }
@Test public void testLinearRescaleUShort() { final RenderedImage targetImage = ReinterpretDescriptor.create(sourceImage, 17.0, 11.0, LINEAR, AWT, null); assertNotNull(targetImage); assertEquals(5, targetImage.getWidth()); assertEquals(5, targetImage.getHeight()); assertEquals(DataBuffer.TYPE_FLOAT, targetImage.getSampleModel().getDataType()); final float[] targetData = ((DataBufferFloat) targetImage.getData().getDataBuffer()).getData(); for (int i = 0; i < targetData.length; i++) { assertEquals("i = " + i, 130.0, targetData[i], 0.0); } }
@Test public void testTargetImageRenderingIsSameAsSourceImageRendering() { final RenderedOp targetImage = ReinterpretDescriptor.create(sourceImage, 1.0, 0.0, LINEAR, AWT, null); assertSame(sourceImage.getRendering(), targetImage.getRendering()); }