Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  1.5 'AffineTrans. rotation screwing up colors' bug  (Read 1994 times)
0 Members and 1 Guest are viewing this topic.
Offline Abuse

JGO Knight


Medals: 14


falling into the abyss of reality


« Posted 2004-02-12 20:16:49 »

ok, after several requests to convert this 4K Game.( http://www.pkl.net/~rsc/4KShooter/4KShooter.jar)
So it doesn't use the Windows only Experimental alpha trans.
I decided to do it. It was only 10mins work... and I ended up with this (note the lack of a cool blur effect ;P):-

http://www.pkl.net/~rsc/4KShooter/4KShooterSE.jar

and it runs perfectly on 1.4.2_03

I then tried it on the 1.5beta..... and its bugged :-/

It seems that rotation AffineTransforms are screwing up the ColorModel of the destination image.

The source image is a managed Image (BITMASK),
The destination Image is a managed image (BITMASK).
When the rotation angle is anything but 0, the palette gets screwed up.

the sourcecode is available here (though I have to warn you its size optimised code Tongue):-

http://www.pkl.net/~rsc/4KShooter/A.java

To summarise, im doing this :-

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
//load the image
BufferedImage loadedImage = ImageIO.read(getClass().getResource(STRING_SHIPS_FILENAME));

//copy a portion of it into a smaller image
(objectImages[0][0] = gc.createCompatibleImage(IMAGE_WIDTH,IMAGE_HEIGHT, Transparency.BITMASK))
.createGraphics().drawImage(loadedImage,(IMAGE_WIDTH-SHIP_WIDTH)/2,(IMAGE_HEIGHT-SHIP_HEIGHT)/2,null);

//rotate the smaller image X times (pre-calc of rotation frames)
BufferedImage src = objectImages[0][0];
for(int i =0;i < NUM_ROTATIONS;i++)
{
   (g = (objectImages[0][i] = gc.createCompatibleImage(IMAGE_WIDTH,IMAGE_HEIGHT,Transparency.BITMASK)).createGraphics())
   .rotate(i*ANGLE_INC,IMAGE_WIDTH/2,IMAGE_HEIGHT/2);
   g.drawImage(src,0,0,null);
}

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Abuse

JGO Knight


Medals: 14


falling into the abyss of reality


« Reply #1 - Posted 2004-02-13 08:53:36 »

ok, i've made a testcase demonstrating the bug.

As I said, this bug is not present in 1.4.2_03, it only appears in 1.5beta1.

I've only tested it on WinXP, but i'd wager it appears in on all Windows platforms...

Executable Jar (also containing sourcecode) :-
http://www.pkl.net/~rsc/4KShooter/TestCase.jar

and the sourcecode and image seperately :-

http://www.pkl.net/~rsc/4KShooter/TestCase.java

http://www.pkl.net/~rsc/4KShooter/image.gif
Click to Play



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
public class TestCase extends Frame implements Runnable
{
   
   static final int IMAGE_WIDTH = 32, IMAGE_HEIGHT = 32;
   static final int SHIP_WIDTH = 21, SHIP_HEIGHT = 25;

   static final int NUM_ROTATIONS = 90;
   static final float ANGLE_INC = (float)((Math.PI*2d) / NUM_ROTATIONS);
   
   static final String STRING_SHIPS_FILENAME = "image.gif";
   
   static final int SCREEN_WIDTH = 400,SCREEN_HEIGHT = 300;
   
   BufferedImage loadedImage;
   
   BufferedImage [] objectImages = new BufferedImage[NUM_ROTATIONS];
   
   public TestCase() throws Exception
   {
      super("ManagedImage/AffineTransform bug");
     
      setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
      show();
      GraphicsConfiguration gc = getGraphicsConfiguration();
     
      //load the image
      loadedImage = ImageIO.read(getClass().getResource(STRING_SHIPS_FILENAME));

      //copy it into the centre of the 1st element of the array
      BufferedImage src = gc.createCompatibleImage(IMAGE_WIDTH,IMAGE_HEIGHT, Transparency.BITMASK);
      {
         Graphics2D g = src.createGraphics();
         g.drawImage(loadedImage,(IMAGE_WIDTH-SHIP_WIDTH)/2,(IMAGE_HEIGHT-SHIP_HEIGHT)/2,null);
      }
         
      for(int i =0;i < NUM_ROTATIONS;i++)
      {
         //create rotations
         objectImages[i] = gc.createCompatibleImage(IMAGE_WIDTH,IMAGE_HEIGHT,Transparency.BITMASK);
         Graphics2D g = objectImages[i].createGraphics();
         g.rotate(i*ANGLE_INC,IMAGE_WIDTH/2,IMAGE_HEIGHT/2); //combined, saved 1byte
         g.drawImage(src,0,0,null);
      }
         
      createBufferStrategy(2);
      enableEvents(AWTEvent.WINDOW_EVENT_MASK);
     
      Thread me = new Thread(this);
      me.start();
   }
   
   boolean running = true;
   
   public void processWindowEvent(WindowEvent we)
   {
      if(we.getID()==WindowEvent.WINDOW_CLOSING)
      {
         running = false;
      }
   }
   
   public void run()
   {
      int angle = 80;
      while(running)
      {
         BufferStrategy bs = getBufferStrategy();
         Graphics g = bs.getDrawGraphics();
         g.setColor(Color.black);
         g.fillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
         g.drawImage(objectImages[angle],40,40,null);
         g.setColor(Color.white);
         g.drawString(String.valueOf(angle*4),50,90);
         bs.show();
         
         
         angle=(angle+1)%NUM_ROTATIONS;
         try
         {
            Thread.sleep(50);
         }
         catch(Exception e)
         {
         }
      }
      dispose();
   }
   
   
   public static void main(String [] args)
   {
      try
      {
         new TestCase();
      }
      catch(Exception e)
      {
         System.out.println("Something went wrong");
      }
   }
}

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #2 - Posted 2004-02-13 11:19:57 »

Did you report this to Sun?  Post the bug# when it is available.  Then others might vote for it.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Knight


Medals: 14


falling into the abyss of reality


« Reply #3 - Posted 2004-02-13 11:38:33 »

Quote
Did you report this to Sun?  Post the bug# when it is available.  Then others might vote for it.


yeah, reported it.
Posted here as well, cos generally you get a faster response Wink

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Abuse

JGO Knight


Medals: 14


falling into the abyss of reality


« Reply #4 - Posted 2004-02-13 19:54:32 »

wow!
I take that back, got a response in less than 12hours!

bug ID 4994576

http://developer.java.sun.com/developer/bugParade/bugs/4994576.html

I doubt it'll need any votes for it to get fixed though, it is kinda core functionality :p

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #5 - Posted 2004-02-14 00:45:56 »

I think the Sun folks are going all out to get 1.5 ready for release.  

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (51 views)
2014-11-26 15:22:04

toopeicgaming1999 (43 views)
2014-11-26 15:20:36

toopeicgaming1999 (8 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (25 views)
2014-11-25 11:26:43

Gibbo3771 (23 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (75 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!