Skip to main content

Reading TIFF files with many color bands -> ColorModel == null

1 reply [Last post]
gdenchev
Offline
Joined: 2007-05-08

Hello,

I hope I am posting in the right forum ...

I am trying to read TIFF file generated by Photoshop, which contains SPOT colors.
The TIFF file is CMYK + 2 Pantone SPOT colors, no compression.

I use the following code:
___
RenderedOp source = JAI.create("fileload", "images/TestSpot.tif");
___

The image loads and "getSampleModel().getNumBands()" is indeed 6.
(By the way, the image only loads properly using JAI 1.1.2, an exception is thrown when using JAI 1.1.3).

But the loaded image has no ColorModel.
This is a problem for me, because I want to create multi-page TIFF, using the code:
___
ImageMIPMap imgMipMap = new ImageMIPMap(
source,
AffineTransform.getScaleInstance(0.75, 0.75),
new InterpolationNearest() );

ImageWriter writer = ImageIO.getImageWritersByFormatName("tif").next();

File outputFile = new File("images/TestSpotOutput.tif");
outputFile.delete();

ImageOutputStream ios = ImageIO.createImageOutputStream(outputFile);
writer.setOutput(ios);

ImageWriteParam iwp = writer.getDefaultWriteParam();

writer.prepareWriteSequence(null);

RenderedImage image = imgMipMap.getImage(0);
writer.writeToSequence(new IIOImage(image, null, null), iwp);
image = imgMipMap.getImage(1);
writer.writeToSequence(new IIOImage(image, null, null), iwp);

writer.endWriteSequence();

ios.close();
___

The result is:
Exception in thread "main" java.lang.IllegalArgumentException: colorModel == null!

Does JAI support TIFF images with more that 4 bands properly?
If yes, what am I doing wrong?

Thanks in advance,
Georgi

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gdenchev
Offline
Joined: 2007-05-08

Oops, maybe posted too soon ...

Changed reading routine to:
___
ImageReader reader = ImageIO.getImageReadersByFormatName("tif").next();
ImageInputStream iis = ImageIO.createImageInputStream( new File("images/TestSpot.tif") );
reader.setInput(iis);
BufferedImage img = reader.read(0);
___

The whole program works now, and although Photoshop does not display the image properly, the bands are there, as far as I can see.

Will post the final result after verifying, maybe this can be useful for someone...

Best,
Georgi