if (srcColorSpace instanceof ICC_ColorSpace) {
// -- Convert CMYK to RGB
ColorSpace rgbColorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel rgbColorModel = RasterFactory.createComponentColorModel(DataBuffer.TYPE_BYTE, rgbColorSpace,
false, true, Transparency.OPAQUE);
ImageLayout rgbImageLayout = new ImageLayout();
rgbImageLayout.setSampleModel(rgbColorModel.createCompatibleSampleModel(src.getWidth(), src.getHeight()));
RenderingHints rgbHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, rgbImageLayout);
rgbHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
ParameterBlockJAI pb = new ParameterBlockJAI("colorconvert");
pb.addSource(src);
pb.setParameter("colormodel", rgbColorModel);
return JAI.create("colorconvert", pb, rgbHints);
} else {
// get user defined color from ColorProfile data
ColorSpace cmykColorSpace = CMMColorSpace.getInstance(src.getColorModel().getColorSpace().getType());
ColorModel cmykColorModel = RasterFactory.createComponentColorModel(src.getSampleModel().getDataType(),
cmykColorSpace, false, true,
Transparency.OPAQUE);
// replace ColorSpace by format convertor with CMYK ColorSpace
ImageLayout cmykImageLayout = new ImageLayout();
cmykImageLayout.setColorModel(cmykColorModel);
RenderingHints cmykHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, cmykImageLayout);
cmykHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
ParameterBlockJAI pb = new ParameterBlockJAI("format");
pb.addSource(src);
pb.setParameter("datatype", src.getSampleModel().getDataType());
PlanarImage op = JAI.create("format", pb, cmykHints);
// invert CMYK pixel value
pb = new ParameterBlockJAI("invert");
pb.addSource(src);
op = JAI.create("invert", pb, cmykHints);
// -- Convert CMYK to RGB
ColorSpace rgbColorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel rgbColorModel = RasterFactory.createComponentColorModel(DataBuffer.TYPE_BYTE, rgbColorSpace,
false, true, Transparency.OPAQUE);
ImageLayout rgbImageLayout = new ImageLayout();
rgbImageLayout.setSampleModel(rgbColorModel.createCompatibleSampleModel(op.getWidth(), op.getHeight()));
RenderingHints rgbHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, rgbImageLayout);
rgbHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
pb = new ParameterBlockJAI("colorconvert");
pb.addSource(op);
pb.setParameter("colormodel", rgbColorModel);