Slick Forums

Discuss the Slick 2D Library
It is currently Sat Apr 20, 2019 6:33 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: [Bug] Image.getColor
PostPosted: Sat Apr 28, 2012 1:23 pm 
Offline

Joined: Fri Apr 27, 2012 11:33 pm
Posts: 4
Image.getColor(int x, int y) doesn't work properly if the image is flipped. It returns the color of the pixel above/left of the desired one, causing an ArrayIndexOutOfBoundsException on getColor(0, 0) if the image is flipped vertically and its width and height are power of 2 values.

Code:
new Image(16, 16).getFlippedCopy(false, true).getColor(0, 0);

Code:
java.lang.ArrayIndexOutOfBoundsException: 1024
   at org.newdawn.slick.Image.getColor(Image.java:1364)
   at test.TestState.update(TestState.java:63)
   at org.newdawn.slick.state.StateBasedGame.update(StateBasedGame.java:268)
   at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
   at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
   at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
   at test.Test.main(Test.java:37)


This makes it impossible to take a screenshot (1024*512) of my Application.


Top
 Profile  
 
 Post subject: Re: [Bug] Image.getColor
PostPosted: Sat May 12, 2012 6:16 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
getColor acts on the backing texture, which itself isn't being flipped/scaled, i.e. along those lines image.getScaledCopy(..).getColor(..) will not work as expected. I'll clear this up in the docs.

I'll add a check for flipped images, though.

Why do you need this for screenshots, anyways? You would take a screenshot with code that looks like this. I can wrap this as a static method in Slick, if you'd like. :)


Top
 Profile  
 
 Post subject: Re: [Bug] Image.getColor
PostPosted: Sun May 13, 2012 5:37 am 
Offline

Joined: Fri Apr 27, 2012 11:33 pm
Posts: 4
Looks like you're wrong.
Using the attachet image this code:
Code:
        System.out.println(img.getColor(16, 16));
        System.out.println(img.getFlippedCopy(true, false).getColor(16, 16));
        System.out.println(img.getFlippedCopy(false, true).getColor(16, 16));
        System.out.println(img.getFlippedCopy(true, true).getColor(16, 16));

produces this output:
Code:
Color (1.0,0.0,0.0,1.0)
Color (1.0,1.0,0.0,1.0)
Color (0.0,0.0,1.0,1.0)
Color (0.0,1.0,0.0,1.0)


so getFlippedCopy(...).getColor(...) did work kinda like expected.
Nevertheless it returns the color for a wrong pixel.
Code:
        System.out.println(img.getColor(16, 32));
        System.out.println(img.getFlippedCopy(false, true).getColor(16, 32));

Code:
Color (0.0,0.0,1.0,1.0)
Color (0.0,0.0,1.0,1.0)

Returns the same color regardless of wether the image is flipped or not, which shouldn't be possible on that image.
Resulting in the error mentioned in the first post in certain circumstances.

I used this code for screenshots because i found it here.

[edit] Just noticed you fixed it now. So, nevermind.


Attachments:
test2.png
test2.png [ 356 Bytes | Viewed 3910 times ]
Top
 Profile  
 
 Post subject: Re: [Bug] Image.getColor
PostPosted: Sun May 13, 2012 7:30 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
Yeah, I just added it a small change. Let me know if the new code produces problems.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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