Skip to main content

[JAI-IMAGEIO] It's all gone black: problems tiling JPEG images

4 replies [Last post]
Anonymous

I'm trying to tile a number of JPEG images together into a larger image,
scaling them at the same time. I'm doing this by loading each image
then using an AffineTransformOp to scale and translate them onto the
destination image. If I save the resulting image as a JPEG image all I
get is a black rectangle. If I save it as a PNG image I see the correct
tiled image, if I save it as a TIFF I get an empty file. I'm clearly
doing something dumb, but what? Here's the relevant bits of the code:

ImageReader in = ImageIO.getImageReadersByFormatName("jpeg").next();
BufferedImage dst = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);

// Loop
in.setInput(new FileImageInputStream(tileFile));
BufferedImage src = in.read(0);
AffineTransform at =
AffineTransform.getTranslateInstance(x, y);
at.scale(SCALE_FACTOR, SCALE_FACTOR);
AffineTransformOp ato = new AffineTransformOp(at, hints);
ato.filter(src, dst);
// End loop

ImageIO.write(dst, "jpeg", outFile);

This is with Java 1.6.0_12. I've also tried explicitly setting the JPEG
compression quality, but it makes no difference.

I'm also getting a SEGV during the read process if I try to tile
together hundreds of files, but that's another issue...

Thanks.

--
Alan Burlison
--

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jxc
Offline
Joined: 2005-02-24

> I iterated through the readers and the only reader in there is the
> com.sun.imageio.plugins.jpeg.JPEGImageReader one, which I guess is
> because I don't have jai-imageio installed, right?

If you didn't use -D...disableCodecLib=true, then that's right.

> Is there any particular reason why I might want to install it, apart
> from the ability to write TIFF etc images?

It's for features like TIFF, 12-bit lossy JPEG, JPEG-LOSSLESS, JPEG-LS,
and etc. and for better performance.

Thanks,
-James

jxc
Offline
Joined: 2005-02-24

With dst being of TYPE_INT_ARGB, you might be getting a 4-band JPEG image
file that is not supported by some image viewers.

Try to create dst as TYPE_3BYTE_BGR, and also use the Java SE built-in JPEG
reader, com.sun.imageio.plugins.jpeg.JPEGImageReader. You could either find
it from the returned Iterator from ImageIO.getImageReadersByFormatName("jpeg")
or use -Dcom.sun.media.imageio.disableCodecLib=true .

The default JPEG reader, com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader
when jai-imageio is installed, tends to return a BufferedImage of TYPE_CUSTOM
which doesn't seem to be supported by AffineTransformOp when dst is of
TYPE_3BYTE_BGR.

HTH,
-James

Alan Burlison

jai-imageio@javadesktop.org wrote:

> With dst being of TYPE_INT_ARGB, you might be getting a 4-band JPEG image
> file that is not supported by some image viewers.
>
> Try to create dst as TYPE_3BYTE_BGR, and also use the Java SE built-in JPEG
> reader, com.sun.imageio.plugins.jpeg.JPEGImageReader. You could either find
> it from the returned Iterator from ImageIO.getImageReadersByFormatName("jpeg")
> or use -Dcom.sun.media.imageio.disableCodecLib=true .

That did it, many thanks :-) It also solved the SEGV I was seeing when
tiling 100s of images.

> The default JPEG reader, com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader
> when jai-imageio is installed, tends to return a BufferedImage of TYPE_CUSTOM
> which doesn't seem to be supported by AffineTransformOp when dst is of
> TYPE_3BYTE_BGR.

I iterated through the readers and the only reader in there is the
com.sun.imageio.plugins.jpeg.JPEGImageReader one, which I guess is
because I don't have jai-imageio installed, right?

Is there any particular reason why I might want to install it, apart
from the ability to write TIFF etc images?

> HTH,

It certainly did, once again thanks for the help :-)

--
Alan Burlison
--

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

Ken Warner

I would avoid developing anything that depends on ImageIO Tools for JAI.
It's a separate download and nobody else will be able to run your app/applet
unless they download and install it.

Alan Burlison wrote:
> jai-imageio@javadesktop.org wrote:
>
>> With dst being of TYPE_INT_ARGB, you might be getting a 4-band JPEG image
>> file that is not supported by some image viewers.
>>
>> Try to create dst as TYPE_3BYTE_BGR, and also use the Java SE built-in
>> JPEG
>> reader, com.sun.imageio.plugins.jpeg.JPEGImageReader. You could
>> either find
>> it from the returned Iterator from
>> ImageIO.getImageReadersByFormatName("jpeg")
>> or use -Dcom.sun.media.imageio.disableCodecLib=true .
>
>
> That did it, many thanks :-) It also solved the SEGV I was seeing when
> tiling 100s of images.
>
>> The default JPEG reader,
>> com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader
>> when jai-imageio is installed, tends to return a BufferedImage of
>> TYPE_CUSTOM
>> which doesn't seem to be supported by AffineTransformOp when dst is of
>> TYPE_3BYTE_BGR.
>
>
> I iterated through the readers and the only reader in there is the
> com.sun.imageio.plugins.jpeg.JPEGImageReader one, which I guess is
> because I don't have jai-imageio installed, right?
>
> Is there any particular reason why I might want to install it, apart
> from the ability to write TIFF etc images?
>
>> HTH,
>
>
> It certainly did, once again thanks for the help :-)
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net