Hello Mark,

Could you please provide more info concerning your problem?  It's
difficult to say the exact reason without having complete standalone
testcase with appropriate input data.
The problem that you are describing could be caused by limited precision
of kodak color management library (16 bit fixed point) that we are using
for color conversions. But again I cannot say anything determine without
having complete testcase.

Best Regards,
Alexey

Mark Stephens wrote:
I have some CMYK JPEGs from a PDF which are actually YCCK encoded. I
have read the raster data out using ImageIO so I can then convert to
sRGB.

I am running these through the standard YCC conversion routines, then
adding a CMYK profile and converting to sRGB. Despite using profiles,
I am not getting an exact match.

What am I doing wrong? Is there a better way?

MArkee

/**
      * save raw CMYK data by converting to RGB using algorithm
     method -
      * pdfsages supplied the C source and I have converted -
      * This works very well on most colours but not dark shades
     which are
      * all rolled into black
      *
      */
     public static BufferedImage iccConvertCMYKImageToRGB(
      byte[] buffer,
      int w,
      int h,boolean debug) {


        DeviceCMYKColorSpace cs=new DeviceCMYKColorSpace();

        //get cmyk colorspace using Abobe profile
        ColorSpace CMYK=cs.getColorSpace();

        BufferedImage image = null;

      int pixelCount = w * h*4;

        double c,m,y,k;
        double Y,Cb,Cr,CENTER;

        //turn YCCK in Buffer to CYMK using formula
        for (int i = 0; i < pixelCount; i = i + 4) {

            Y=(buffer[i] & 255);
            Cb = (buffer[i+1] & 255)-128;
       Cr = (buffer[i+2] & 255)-128;
       //CENTER =(buffer[i+3] & 255);

            c =( Y +(1.4020d*Cr));
            if(c<0d)
            c=0d;
            if(c>255d)
            c=255d;

            m =(Y - (0.3441363d*Cb) - (0.71413636d*Cr));
            if(m<0d)
            m=0d;
            if(m>255d)
            m=255d;

            y =(Y + (1.7718d*Cb));
            if(y<0d)
            y=0d;
            if(y>255d)
            y=255d;

            buffer[i]=(byte)(255-c);
            buffer[i+1]=(byte)(255-m);
            buffer[i+2]=(byte)(255-y);
            //buffer[i+3]=(byte)(CENTER);    //just passed through

      }

        /**
         * create CMYK image from buffer
         */
        int[] bands = { 0, 1, 2, 3 };

        WritableRaster raster = Raster.createInterleavedRaster(new
DataBufferByte(buffer,buffer.length), w,h,w * 4,4, bands,null);
        ColorModel cmykModel = new ComponentColorModel( CMYK, new
int[] { 8, 8, 8, 8 }, false, false, ColorModel.OPAQUE,
DataBuffer.TYPE_BYTE);
        image = new BufferedImage(cmykModel, raster, false, null);

        /**
         * convert to sRGB filtering data via .icm profile (the one
Adobe has in Acrobat)
         * Gives exact match on CMYK to sRGB but not YCCK to sRGB
         */
        ICC_Profile rgbProfile =
ICC_Profile.getInstance(ColorSpace.CS_sRGB);
        rgbCS = new ICC_ColorSpace(rgbProfile);
        rgbModel = new ComponentColorModel(rgbCS, new int[] { 8, 8, 8
}, false, false, ColorModel.OPAQUE, DataBuffer.TYPE_BYTE);


        WritableRaster rgbRaster
=rgbModel.createCompatibleWritableRaster(w, h);
        CSToRGB = new ColorConvertOp(cs.getColorSpace(), rgbCS,
ColorSpaces.hints);
        CSToRGB.filter(image.getRaster(), rgbRaster);

        //data now sRGB so create image
        image =new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
        image.setData(rgbRaster);

        return image;
     }

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to