Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [udig-devel] got a performance question

On Friday, 15 March 2013 at 7:51 PM, andrea antonello wrote:
Hi Jody,
funky stuff you found out :)

Were you able to do a test on this to understand how much we would gain?

Nice,
Andrea
For the record I did eventually figure it out:

        BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
        Graphics g = image.getGraphics();
     
// draw draw draw

        // And then convert
        if (image.getType() == BufferedImage.TYPE_4BYTE_ABGR) {
            int width = image.getWidth();
            int height = image.getHeight();
            int bands = image.getColorModel().getColorSpace().getNumComponents() + 1;
            int depth = 32;

            // Use the pixel data straight up!
            byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
            PaletteData paletteData = new PaletteData(0x0000ff, 0x00ff00, 0xff0000);
            ImageData data = "" ImageData(width, height, depth, paletteData, width * bands, pixels);
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    int pixel = image.getRGB(x, y);
                    int alpha_value = (pixel >> 24) & 0x000000FF;
                    data.setAlpha(x, y,  alpha_value );
                }
            }                
            return data;
        }

As for what we will gain, one less "copy" of the byte[] representing the raster data. I was hoping not to have a copy occur at all but do not see a way to safely make that happen.

Jody 


Back to the top