Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 25, 2013 5:38 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: BUG: ImageBuffer.setRGBA
PostPosted: Mon Apr 26, 2010 9:21 pm 
Offline

Joined: Thu Dec 03, 2009 12:54 pm
Posts: 2
Hello,

There is a bug in ImageBuffer.setRGBA, when writing to the rawData in a little endian machine it does not invert the byte orders.

The bug was found in the latest version to download at the site.

Patch:
Code:
--- ImageBuffer.java    2009-07-05 13:27:48.000000000 -0300
+++ ImageBuffer-fixed.java      2010-04-26 18:14:58.121064102 -0300
@@ -124,9 +124,9 @@
                        rawData[ofs + 2] = (byte) b;
                        rawData[ofs + 3] = (byte) a;
                } else {
-                       rawData[ofs] = (byte) r;
+                       rawData[ofs] = (byte) b;
                        rawData[ofs + 1] = (byte) g;
-                       rawData[ofs + 2] = (byte) b;
+                       rawData[ofs + 2] = (byte) r;
                        rawData[ofs + 3] = (byte) a;
                }
        }


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 13, 2010 7:42 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Fixed in SVN.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 16, 2010 4:56 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
Hmm, doesn't work on my machine. Currently red and blue are swapped. Worked before.

Do I have to set endianness of my machine or how does detection work?

At least on my laptop it seems the old way was right :?

Any tips?

Edit: My machine claims it is little endian.
Code:
       if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
          System.out.println("Big endian");
       } else if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
          System.out.println("Little endian");
       } else
          System.out.println("no idea");


Nevertheless red and blue are now swapped in my ImageBuffer. The old (big endian) way definitely worked properly on my machine whereas the new fix doesn't.

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 19, 2010 7:20 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
I wrote a little test case and would ask you to give feedback what the results are on your machines.

Code:
package net.haaks.theycome;

import java.nio.ByteOrder;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.ImageBuffer;
import org.newdawn.slick.SlickException;

public class ImageBufferEndianTest extends BasicGame {

   ImageBuffer redImageBuffer, blueImageBuffer;
   Image fromRed, fromBlue;
   String endian;
   
   public ImageBufferEndianTest() {
      super("ImageBuffer Endian Test");
   }

   public static void main(String[] args) {
      try {
         AppGameContainer container = new AppGameContainer(new ImageBufferEndianTest());
         container.setDisplayMode(800,600,false);
         container.start();
      } catch (SlickException e) {
         e.printStackTrace();
      }
   }

   @Override
   public void render(GameContainer container, Graphics g) throws SlickException {
      g.setColor(Color.white);
      g.drawString("Endianness is " + endian, 10, 100);
      
      g.drawString("Image below should be red", 10, 200);
      g.drawImage(fromRed, 10, 220);
      g.drawString("Image below should be blue", 410, 200);
      g.drawImage(fromBlue, 410, 220);
   }

   @Override
   public void init(GameContainer container) throws SlickException {
      // detect what endian we have
      if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
             endian = "Big endian";
          } else if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
             endian = "Little endian";
          } else
             endian = "no idea";
      
      redImageBuffer = new ImageBuffer(100,100);
      fillImageBufferWithColor(redImageBuffer, Color.red, 100, 100);
      
      blueImageBuffer = new ImageBuffer(100,100);
      fillImageBufferWithColor(blueImageBuffer, Color.blue, 100, 100);
      
      fromRed = redImageBuffer.getImage();
      fromBlue = blueImageBuffer.getImage();
   }
   
   private void fillImageBufferWithColor(ImageBuffer buffer, Color c, int width, int height) {
      for (int x = 0; x < width; x++) {
         for (int y = 0; y < height; y++) {
            buffer.setRGBA(x, y, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
         }
      }
   }

   @Override
   public void update(GameContainer container, int delta) throws SlickException {
      // nothing to do
   }

}


On my machine it gives a blue square where a red one should be and vice versa and it claims to be a little endian machine.

Screenshot:
Image

Thanks,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2010 4:02 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Very strange, works perfectly on my linux box here and it's little endian.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2010 4:09 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Added the test into SVN so other people can try it easily.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2010 7:12 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
kevglass wrote:
Very strange, works perfectly on my linux box here and it's little endian.

Kev


Yes, it's working since a few weeks with the SVN version of Slick.
Because you already swapped the interesting lines in ImageBuffer.java back to "normal" in revision 1364 on October 19th.

Question is: does the version before revision 1364 (1319 to be precise) also work correctly on your machine?

Thanks for testing it and looking at it :wink:

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2010 9:17 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Can't see anything wrong with this at the moment.

Kev


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group