Re: [JAVA2D] BMPImageReader fails if the Destination is set

2006-06-05 Thread java2d
Yes, I see that the BMPImageReader only supports TYP_3BYTE_BGR.   It's too bad 
that the generic Image IO framework doesn't handle the sample model conversion 
to read into a generic BufferedImage automatically.  Either way, as you say, it 
isn't failing with the proper exception.
[Message sent by forum member 'swpalmer' (swpalmer)]

http://forums.java.net/jive/thread.jspa?messageID=119453

===
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".


Re: [JAVA2D] BMPImageReader fails if the Destination is set

2006-06-02 Thread java2d
It seems to me that before set TYPE_INT_BGR image as
destination, it worth to check whether image reader
is able to use it.

Please take a look to the setDestioantion method
description: at the time of reading, the destination
image is checked to verify that its ColorModel and
SampleModel  correspond to one of the ImageTypeSpecifiers
returned from the ImageReader's getImageTypes method.
If it does not, the reader will throw an IIOException.

According to this, only image form list of supported image
types can be used as reading destination.

Of course, current behavior of  BMPImageReader is wrong
(actually, BMP reader works in assumption that destination
image is created according to structure of decoded image).
However, the fix could be just some verification of
destination image type and throwing an IIOException if
destination image does not correspond to one of supported
image types.

Thanks,
Andrew.
[Message sent by forum member 'bae' (bae)]

http://forums.java.net/jive/thread.jspa?messageID=118591

===
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".


[JAVA2D] BMPImageReader fails if the Destination is set

2006-06-01 Thread java2d
I tried the code below with a 24bit BMP file saved from the "Paint" program on 
Windows XP.  There are no ImageIO readers installed beyond what is included in 
the JRE/JDK.
The reader that fails is com.sun.imageio.plugins.bmp.BMPImageReader
This fails on Java 5 and Mustang.

[code]
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Iterator;

import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.FileImageInputStream;

/*
 * Created on 25-May-2006
 *
 */

public class ImageIoBug
{

/**
 * @param args
 *the path to an image file use a .BMP to fail.
 */
public static void main(String[] args) throws Exception
{
BufferedImage testImage = null;
if (args.length > 0)
{
String path = args[0];
String ext = path.substring(path.lastIndexOf('.') + 1);
System.out.println("Readers claiming to handle this 
format:");

for (Iterator ri = 
ImageIO.getImageReaders(new FileImageInputStream(new File(path))); 
ri.hasNext();)
System.out.println("  " + 
ri.next().getClass().getCanonicalName());
Iterator readerIt = 
ImageIO.getImageReadersBySuffix(ext);
if (readerIt.hasNext()) /* This code fails for BMP 
files */
{
System.out.println("Using reader for \"" + ext 
+ "\" suffix");
ImageReader reader = (ImageReader) 
readerIt.next();

System.out.println(reader.getClass().getCanonicalName());
reader.setInput(new FileImageInputStream(new 
File(path)));
int width = reader.getWidth(0);
int height = reader.getHeight(0);
System.out.printf("Image is %d x %d", width, 
height);
testImage = new BufferedImage(width, height, 
BufferedImage.TYPE_INT_BGR);
ImageReadParam param = new ImageReadParam();
/* Setting the destination image makes the BMP 
reader fail! */
if (true)  /* Change to false to see that the 
.BMP file CAN be read */
param.setDestination(testImage);
/* this method will throw some exceptions not 
mentioned in
 * the Java docs */
reader.read(0, param);
}
else /* the work-around */
{
System.out.println("ImageIO.read() then copy - 
the path that works.");
testImage = ImageIO.read(new File(path));
/* But I need the image data to be in INT_BGR 
form */
if (testImage != null && testImage.getType() != 
BufferedImage.TYPE_INT_BGR)
{
BufferedImage testDest = new 
BufferedImage(
testImage.getWidth(),
testImage.getHeight(),
BufferedImage.TYPE_INT_BGR);
Graphics g = testDest.getGraphics();
g.drawImage(testImage, 0, 0, null);
g.dispose();
testImage = testDest;
}
}
}
else
{
System.out.println("Usage: java ImageIoBug 
");
}
}

}
[/code]

.. so I guess it's a trip to the bug reporter for me...
[Message sent by forum member 'swpalmer' (swpalmer)]

http://forums.java.net/jive/thread.jspa?messageID=118433

===
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".