LWJGL
May 22, 2012, 14:49:45 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.8.3 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: How can i get the real color in 2d game?  (Read 922 times)
adam_1212
Newbie
*
Posts: 1


« on: May 05, 2010, 20:53:46 »

How can i get the real color in 2d game
Logged
wondersonic
Newbie
*
Posts: 40



« Reply #1 on: May 06, 2010, 03:25:27 »

Hey, I see you tried the wonderful Propotyp project.

In fact, you just suffer from the correction of BUG http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6879279 from JDK 1.6.0_18.

Indeed they changed the type for PNG images so you have to convert back RGBA components.

For example, I do:

Code:
buffImage = ImageIO.read(cl.getResource(path));
final byte[] data = ((DataBufferByte) buffImage.getRaster().getDataBuffer()).getData();
                switch (buffImage.getType()) {
                    case BufferedImage.TYPE_4BYTE_ABGR:
                        convertFromARGBToBGRA(data);
                        break;
                    case BufferedImage.TYPE_3BYTE_BGR:
                        convertFromBGRToRGB(data);
                        break;
                }
...

    private static void convertFromARGBToBGRA(final byte[] data) {
        final int size = data.length;
        for (int i = 0; i < size; i += 4) {
            final int a = data[i] & 0x000000FF;
            final int r = data[i + 1] & 0x000000FF;
            final int g = data[i + 2] & 0x000000FF;
            final int b = data[i + 3] & 0x000000FF;

            data[i] = (byte) b;
            data[i + 1] = (byte) g;
            data[i + 2] = (byte) r;
            data[i + 3] = (byte) a;
        }
    }

    private static void convertFromBGRToRGB(final byte[] data) {
        final int size = data.length;
        for (int i = 0; i < size; i += 3) {
            final int b = data[i] & 0xFF;
            final int g = data[i + 1] & 0xFF;
            final int r = data[i + 2] & 0xFF;

            data[i] = (byte) r;
            data[i + 1] = (byte) g;
            data[i + 2] = (byte) b;
        }
    }

WS
Logged

S.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!