Hello
Im having troubles getting decent performance out of a simple 2d tilescroller. Java alphablending with translucent transparency is god awful slow, as expected.
What I want is simple colorkeying, eg defining a transparent color in the source. Couldn’t find any direct way of doing that. Instead I read up on bitmask transparency.
Im loading image data from RGBA png files. So to get them ready for blitting I converted them like this:
BufferedImage original = ImageIO.read(in);
java.awt.GraphicsEnvironment ge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
java.awt.GraphicsDevice gd = ge.getDefaultScreenDevice();
java.awt.GraphicsConfiguration gc = gd.getDefaultConfiguration();
BufferedImage bim = gc.createCompatibleImage(original.getWidth(), original.getHeight(), Transparency.BITMASK);
Graphics2D g2d = (Graphics2D) bim.getGraphics();
g2d.setComposite(AlphaComposite.Src);
g2d.drawImage(original, 0, 0, null);
To my horror this is for some reason just as slow as Transparency.TRANSLUCENT
I tried reading img data from GIF instead in case Transparency.BITMASK only works for indexed colormodel, with no noticeable speed difference.
Besides i’d still like to able to use 24 color instead of 8 bit, and I don’t think thats whats slowing it down either. I get flawless performance on 24 RGB with Transparency.OPAQUE.
What am I doing wrong? seems like java2d is doing per pixel RGBA blitting when I want it to use BITMASK (colorkeying).
oh and is there anyway of using colorkeying specifying your own color key as a 24 bit RGB value? And can I even assume that the above code auto converts RGBA data from the png to
RGB + transparency bitmask?