Thank you for the code, but with the test images I have, I cannot even
get past the "fileload" operation.

It returns an empty PlanerImage

Bill Ensley
Bear Printing

-----Original Message-----
From: Thomas Kübler [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 19, 2005 11:57 PM
To: Bill Ensley
Subject: Re: [iText-questions] CMYK Image


hallo,

we use jai for converting th einput images in the output colorspace.
we have no trouble with the jai-conversion only if we have a lot of
images to convert we get sometimes, depends on the memory you have in the
machine, an memory error.

we put the code below.

with regards

thomas kübler



   public static void startImageConvert( String inputImageFileNameString,
                                        String outputImageFileNameString,
                                        boolean invert) throws Exception {

     boolean tiffile = false;
     //
     RenderedOp inputImage =
JAI.create("fileload",inputImageFileNameString);
     //
     if ( inputImageFileNameString.endsWith(".tif") ||
inputImageFileNameString.endsWith(".tiff") )
       tiffile = true;
     //
     ColorModel inputColorModel = inputImage.getColorModel();
     //
     if (cat.isDebugEnabled())
       cat.debug("input image... Components [ "
+ inputColorModel.getNumComponents() + " ]");
       cat.debug("input image... ColorSpace [ "
+ getColorSpaceTyp(inputColorModel.getColorSpace().                     
getType()) + " ]");
     //

     JAI.create("filestore", colorConvert( inputImage,
                                          invert,
                                          outputColorSpaceTypInt,
                                          inputColorModel.getNumComponents(),
                                          tiffile), outputImageFileNameString , 
"TIFF" );

     if (cat.isDebugEnabled())
       cat.debug("ready...");
       cat.debug("file save... [ " + outputImageFileNameString + " ]");
   }


   public static BufferedImage colorConvert(  RenderedOp src, boolean
invert,
                        int outcolorspaceInt,int components, boolean filetype) {

     int inputImageColorSpace = ColorSpace.TYPE_RGB;
     ICC_ColorSpace inputICCColorSpace = null;
     //
     if ( src.getColorModel().getNumComponents() == 1 ) {
       inputImageColorSpace = ColorSpace.TYPE_GRAY;
       inputICCColorSpace = defaultGrayColorSpace;
       //
     } else if ( src.getColorModel().getNumComponents() == 3 ) {
       inputImageColorSpace = ColorSpace.TYPE_RGB;
       inputICCColorSpace = defaultRGBColorSpace;
       //
     } else if ( src.getColorModel().getNumComponents() == 4 ) {
       inputImageColorSpace = ColorSpace.TYPE_CMYK;
       inputICCColorSpace = defaultCMYKColorSpace;
       //
     } else {
       // kein unterstützter Farbraum gefunden
       inputImageColorSpace = ColorSpace.TYPE_RGB;
       inputICCColorSpace = defaultRGBColorSpace;
     }

     ICC_ColorSpace outputICCColorSpace = iccOutputColorSpace;

     if ( iccOutputColorSpace.getProfile().getColorSpaceType() ==
outcolorspaceInt ) {
       outputICCColorSpace = iccOutputColorSpace;
       cat.debug("iccOutputColorSpace...");
     } else if ( outcolorspaceInt == ColorSpace.TYPE_RGB ) {
       outputICCColorSpace = defaultRGBColorSpace;
       // outputColorSpaceTypInt = ColorSpace.TYPE_RGB;
       cat.debug("defaultRGBProfile...");
     } else if ( outcolorspaceInt == ColorSpace.TYPE_GRAY ) {
       outputICCColorSpace = defaultGrayColorSpace;
       // outputColorSpaceTypInt = ColorSpace.TYPE_GRAY;
       cat.debug("defaultGrayProfile...");
     } else {
       outputICCColorSpace = iccOutputColorSpace;
       cat.debug("iccOutputColorSpace default...");
     }
     boolean inverttif = false;
     //
     if ( filetype && components == 4 ) {
       src = convertCMYKtoRGB(src);
     }

     // ParamterBlock für das Ausgangs-Color-Format aufbauen
     ParameterBlockJAI pbjai = new ParameterBlockJAI("colorconvert");
     // ausgangsfarbraum ColorSpace aufbauen
     ColorModel inputColorModel = getOutPutColorModel(
         inputICCColorSpace,inputICCColorSpace.getProfile().getColorSpaceTyp
e());
     ColorModel cm =
getOutPutColorModel(outputICCColorSpace,outcolorspaceInt);
     // image zuweisen
     pbjai.addSource(src);
     // colormodel zuweisen
     pbjai.setParameter("colormodel",cm);
     // Image Layout aufbauen
     ImageLayout imagelayout = new ImageLayout();

     imagelayout.setSampleModel(cm.createCompatibleSampleModel(src.getWidth(
),
src.getHeight()));
     // Rendering Hints
     cat.debug("RenderingHints...");
     RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT,
imagelayout);
     // ausführen der transformation
     cat.debug("RenderedOp...");
     RenderedOp output = JAI.create("colorconvert", pbjai, hints);
     // Raster aufbauen
     WritableRaster newImageRaster =
output.getAsBufferedImage(null,null).getRaster();
     //
     // neues image zurück
     //
     if ( inverttif ) {
       cat.debug("Invertieren...");
       byte swap[] = new byte[256];
       for( int i = 0; i < swap.length ; i++){
        swap[i] = (byte)( 255 - i );
       }
       //
       LookupTable lookup = getOutPutLookUpTable(swap);
       LookupOp luop = new LookupOp(lookup, null);
       newImageRaster = luop.filter(newImageRaster,
newImageRaster.createCompatibleWritableRaster());
     }
     //
     return new BufferedImage(cm,newImageRaster,false,null);
     //
   }


Am Tue, 19 Apr 2005 09:57:50 -0700 schrieb Bill Ensley
<[EMAIL PROTECTED]>:

> I thought so, I had been using it for a while and thought it was
> working properly, but when I went back to update some code I
> did some testing and found that many different types of CMYK images
> were throwing invalid colorspace errors and failing to load.
>
> Unfortunately, I don't have the image knowledge i'd like to have.
>
> I have attached a guilty image to this post, if anyone is feeling
> adventuresome,
> let me know what you find.
>
> Thanks all,
>
> Bill Ensley
> Bear Printing
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of Paulo
> Soares
> Sent: Tuesday, April 19, 2005 1:59 AM
> To: Bill Ensley; iText Mail Group
> Subject: RE: [iText-questions] CMYK Image
>
>
> Won't JAI work?
>
>> -----Original Message-----
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On
>> Behalf Of Bill Ensley
>> Sent: Monday, April 18, 2005 11:56 PM
>> To: iText Mail Group
>> Subject: [iText-questions] CMYK Image
>>
>> I realize this isn't the proper mail group for this question,
>> but does anyone out there have a good way of getting a
>> CMYK image, either tif or jpg, into Java?
>>
>> I heavily use PdfGraphics2D and would like to be able to pass
>> a CMYK image in some cases.
>>
>> Bill Ensley
>> Bear Printing
>>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: New Crystal Reports XI.
> Version 11 adds new functionality designed to reduce time involved in
> creating, integrating, and deploying reporting solutions. Free runtime
> info,
> new features, or free trial, at: http://www.businessobjects.com/devxi/728
> _______________________________________________
> iText-questions mailing list
> iText-questions@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: New Crystal Reports XI.
> Version 11 adds new functionality designed to reduce time involved in
> creating, integrating, and deploying reporting solutions. Free runtime
> info,
> new features, or free trial, at: http://www.businessobjects.com/devxi/728
> _______________________________________________
> iText-questions mailing list
> iText-questions@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/itext-questions



--

Dynamic Document Solution variex
Alt-Marienfelde 25
12277 Berlin

t. + 49 (0)30.723.23.183
f. + 49 (0)30.723.23.185
mobil +49 (0)163 633 36 96

www.variex.de

Ansprechpartner
[EMAIL PROTECTED]



-------------------------------------------------------
This SF.Net email is sponsored by: New Crystal Reports XI.
Version 11 adds new functionality designed to reduce time involved in
creating, integrating, and deploying reporting solutions. Free runtime info,
new features, or free trial, at: http://www.businessobjects.com/devxi/728
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to