@Nonnull @Override protected PlanarImage execute (final @Nonnull ConvertColorProfileOp operation, final @Nonnull EditableImage image, final @Nonnull PlanarImage planarImage) { log.info("execute({}) - {} ", operation, planarImage.getSampleModel()); if (operation.getRenderingIntent() != PERCEPTUAL) { throw new IllegalArgumentException("Can only use PERCEPTUAL intent, was " + operation.getRenderingIntent()); } final ICC_Profile iccProfile = operation.getIccProfile(); final RenderingHints hints = new RenderingHints(Collections.<RenderingHints.Key, Object>emptyMap()); hints.put(KEY_COLOR_RENDERING, VALUE_COLOR_RENDER_QUALITY); final PlanarImage result = ColorConvertDescriptor.create(planarImage, JAIUtils.getColorModel(planarImage, iccProfile), hints); JAIUtils.logImage(log, ">>>> returning", planarImage); return result; } }
/******************************************************************************* * * If the current image is not sRGB, apply a ColorConvert operation to convert * it to sRGB. * * @param colorModel the target color model (must be a sRGB color space) * @param hints the RenderingHints * ******************************************************************************/ public static PlanarImage jaiConvertTosRGBColorProfile (final PlanarImage source, final ColorModel colorModel, final RenderingHints hints) { boolean is_sRGB = source.getColorModel().getColorSpace().isCS_sRGB(); logger.finer(">>>> planarImage.is_sRGB: " + is_sRGB); if (!is_sRGB) { // Convert color as last, since if the image has been scaled there are less pixels to convert logger.finer(">>>> Applying ColorConvertDescriptor"); PlanarImage result = ColorConvertDescriptor.create(source, colorModel, hints); logImage(logger, ">>>>>>>> planarImage", result); return result; } else { return source; } }
/******************************************************************************* * * If the current image is not sRGB, apply a ColorConvert operation to convert * it to sRGB. * * @param colorModel the target color model (must be a sRGB color space) * @param hints the RenderingHints * ******************************************************************************/ public static PlanarImage jaiConvertTosRGBColorProfile (final PlanarImage source, final ColorModel colorModel, final RenderingHints hints) { boolean is_sRGB = source.getColorModel().getColorSpace().isCS_sRGB(); log.debug(">>>> planarImage.is_sRGB: {}", is_sRGB); if (!is_sRGB) { // Convert color as last, since if the image has been scaled there are less pixels to convert log.debug(">>>> Applying ColorConvertDescriptor"); PlanarImage result = ColorConvertDescriptor.create(source, colorModel, hints); logImage(log, ">>>>>>>> planarImage", result); return result; } else { return source; } }
/******************************************************************************* * * @inheritDoc * ******************************************************************************/ protected PlanarImage execute (ConvertColorProfileOp operation, final EditableImage image, PlanarImage planarImage) { ICC_Profile iccProfile = operation.getICCProfile(); logger.fine("convertColorProfile(" + ImageUtils.getICCProfileName(iccProfile) + ") - " + planarImage.getSampleModel()); planarImage = ColorConvertDescriptor.create(planarImage, JAIUtils.getColorModel(planarImage, iccProfile), null); // FIXME: RenderingHints JAIUtils.logImage(logger, ">>>> convertColorProfile() returning", planarImage); return planarImage; } }
/** * Forces the {@linkplain #image} color model to the * {@linkplain ColorSpace#CS_GRAY GRAYScale color space}. If the current * color space is already of {@linkplain ColorSpace#TYPE_GRAY type}, then * this method does nothing. * * @return this {@link ImageWorker}. * * @see #isColorSpaceGRAYScale * @see ColorConvertDescriptor */ public final ImageWorker forceColorSpaceGRAYScale() { if (!isColorSpaceRGB()) { final ColorModel cm = new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); image = ColorConvertDescriptor.create(image, cm, getRenderingHints()); invalidateStatistics(); } // All post conditions for this method contract. assert isColorSpaceGRAYScale(); return this; }
/** * Forces the {@linkplain #image} color model to the * {@linkplain ColorSpace#CS_GRAY GRAYScale color space}. If the current * color space is already of {@linkplain ColorSpace#TYPE_GRAY type}, then * this method does nothing. * * @return this {@link ImageWorker}. * * @see #isColorSpaceGRAYScale * @see ColorConvertDescriptor */ public final ImageWorker forceColorSpaceGRAYScale() { if (!isColorSpaceRGB()) { final ColorModel cm = new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); image = ColorConvertDescriptor.create(image, cm, getRenderingHints()); invalidateStatistics(); } // All post conditions for this method contract. assert isColorSpaceGRAYScale(); return this; }
/** * Forces the {@linkplain #image} color model to the * {@linkplain ColorSpace#CS_sRGB RGB color space}. If the current color * space is already of {@linkplain ColorSpace#TYPE_RGB RGB type}, then this * method does nothing. This operation may loose the alpha channel. * * @return this {@link ImageWorker}. * * @see #isColorSpaceRGB * @see ColorConvertDescriptor */ public final ImageWorker forceColorSpaceRGB() { if (!isColorSpaceRGB()) { final ColorModel cm = new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); image = ColorConvertDescriptor.create(image, cm, getRenderingHints()); invalidateStatistics(); } // All post conditions for this method contract. assert isColorSpaceRGB(); return this; }
/** Forces the provided {@link ColorModel} via the JAI ColorConvert operation.*/ private void forceColorModel(final ColorModel cm){ final org.jaitools.imageutils.ImageLayout2 il = new org.jaitools.imageutils.ImageLayout2(image); il.setColorModel(cm); il.setSampleModel(cm.createCompatibleSampleModel(image.getWidth(), image.getHeight())); final RenderingHints oldRi = this.getRenderingHints(); final RenderingHints newRi = (RenderingHints) oldRi.clone(); newRi.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, il)); setRenderingHints(newRi); image = ColorConvertDescriptor.create(image, cm, getRenderingHints()); // restore RI this.setRenderingHints(oldRi); // invalidate stats invalidateStatistics(); }
imageCalculated = javax.media.jai.operator.ColorConvertDescriptor.create(image, colorModel, null); } else {