The problem with your first method is that you are creating the image with
your own DataBuffer. This prohibits this image from ever being cached in video
memory since we can not guarantee that the cache will be up to date with the
original image. Thus the image is "unmanageable".
I'm not sure why you need to convert your original image in the first place,
but there is much faster way to do it than your second method.
Instead of doing the color convert op, just draw the src image into the
destination:
[code]
Graphics2D g = (Graphics2D)compatible.getGraphics();
g.setComposite(AlphaComposite.Src);
g.drawImage(image, 0, 0, null);
[/code]
Thanks,
Dmitri
jav...@javadesktop.org wrote:
Of course.
Here is a proc that converts a binary image to a compatible RGB:
public static BufferedImage
convertToSinglePixelPackedSampleModel_BINARY(BufferedImage image) {
int[] bitMasks = new int[]{0x00ff0000, 0x0000ff00, 0x000000ff};
SinglePixelPackedSampleModel sampleModel = new
SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, image.getWidth(),
image.getHeight(), bitMasks);
int[] pixels = image.getRaster().getPixels(0, 0, image.getWidth(),
image.getHeight(), (int [])null);
for(int i=0; i<pixels.length; i++)
if (pixels[i] == 1)
pixels[i] = 0x00ffffff;
DataBufferInt d = new DataBufferInt(pixels, pixels.length);
WritableRaster destRaster = Raster.createWritableRaster(sampleModel, d,
null);
ICC_ColorSpace colorSpace = new
ICC_ColorSpace(ICC_Profile.getInstance(ColorSpace.CS_sRGB));
ColorModel colorModel = new DirectColorModel(colorSpace, 24, bitMasks[0],
bitMasks[1], bitMasks[2], 0, false, DataBuffer.TYPE_INT);
image = new BufferedImage(colorModel, destRaster, false, null);
return image;
}
Now, here is the code that converts to compatible image:
public static BufferedImage toCompatibleImage(final BufferedImage image) {
long now = System.currentTimeMillis();
final BufferedImage compatible = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration()
.createCompatibleImage(image.getWidth(), image.getHeight(),
image.getTransparency());
ColorConvertOp op = new
ColorConvertOp(image.getColorModel().getColorSpace(),
compatible.getColorModel().getColorSpace(), null);
op.filter(image, compatible);
return compatible;
}
If i take a binary image and convert it to RGB (first method), the
BufferedImage i get is faster to render (of course), but still at least 4 times
slower to render than in the case that i later convert to compatible image also.
The image before and after the conversion to compatible are identical.
What do i miss here?
Thank you,
Costas
[Message sent by forum member 'csterg' (csterg)]
http://forums.java.net/jive/thread.jspa?messageID=349435
===========================================================================
To unsubscribe, send email to lists...@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
lists...@java.sun.com and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to lists...@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
lists...@java.sun.com and include in the body of the message "help".