Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (113)
games submitted by our members
Games in WIP (562)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java 2D / Graphics.copyArea bug? on: 2012-01-17 11:36:11
Hello,

I have a problem when using copyArea to scroll an image with a negative dx value (that is, scroll an image to the left) with an opaque picture format.

Here is a simple test I performed in a JFrame:

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  
public class TestFrame extends javax.swing.JFrame
{

    private BufferedImage buffer = null;
    /**
     * Creates new form TestFrame
     */

    public TestFrame()
    {
        try
        {
            BufferedImage img = ImageIO.read(new File("/home/lauwenmark/tmp/test.jpg"));
            this.buffer = new BufferedImage(1600, 1200, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = this.buffer.createGraphics();
            g2d.drawImage(img, 0, 0, this);
            g2d.dispose();
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
            this.buffer = new BufferedImage(1600, 1200, BufferedImage.TYPE_INT_RGB);
        }
    }

    @Override
    public void paint(Graphics g)
    {
        Graphics2D g2d = (Graphics2D)g;
        super.paint(g);
        g2d.drawImage(this.buffer, 0, 0, this);
    }


And I scroll using this:

1  
2  
3  
4  
        Graphics2D g2d = buffer.createGraphics();
        g2d.copyArea(64, 0, this.buffer.getWidth()-64, this.buffer.getHeight(), -64, 0);
        g2d.dispose();
        this.repaint();


When this.buffer is of TYPE_INT_ARGB, it works as expected. However, when using TYPE_INT_RGB, it doesn't and ends up corrupting the display like this:



Uploaded with ImageShack.us

Where am I doing it wrong? Or is it a bug in copyArea?
2  Java Game APIs & Engines / Java 2D / Re: Colour->Grayscale conversion failure using ColorConvertOp on Mustang on: 2006-08-20 07:39:31
Thanks a lot for your help ! Here are two images that triggered the bug on my system:



3  Java Game APIs & Engines / Java 2D / Re: Colour->Grayscale conversion failure using ColorConvertOp on Mustang on: 2006-08-18 22:22:07
My apologizes, I obviously copied the wrong stack trace - you'll find the correct one below.

I used the following piece of code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
        (...)
        BufferedImageOp operation = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
        try
        {
            System.out.println("BEFORE:"+my_icon);
            my_disabled_icon = operation.filter(my_icon, null);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.out.println("AFTER :"+my_icon);
        }


And got the following results:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
my_icon BEFORE:BufferedImage@5aaa4bf8: type = 0 ColorModel: #pixelBits = 16 numComponents = 2 color space = java.awt.color.ICC_ColorSpace@6261b548 transparency = 3 has alpha = true isAlphaPre = false ByteInterleavedRaster: width = 32 height = 32 #numDataElements 2 dataOff[0] = 0

java.lang.NullPointerException
        at java.awt.image.ComponentColorModel.getDataElements(ComponentColorModel.java:1538)
        at sun.awt.image.PixelConverter.rgbToPixel(PixelConverter.java:39)
        at sun.java2d.loops.SurfaceType.pixelFor(SurfaceType.java:400)
        at sun.java2d.SurfaceData.pixelFor(SurfaceData.java:691)
        at sun.java2d.SunGraphics2D.validateColor(SunGraphics2D.java:1646)
        at sun.java2d.SunGraphics2D.<init>(SunGraphics2D.java:242)
        at sun.java2d.SunGraphicsEnvironment.createGraphics(SunGraphicsEnvironment.java:349)
        at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1137)
        at java.awt.image.ColorConvertOp.ICCBIFilter(ColorConvertOp.java:317)
        at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:262)

        (... the rest of the stack is the app-specific location of the error, which is the convert() line.)

my_icon AFTER :BufferedImage@5aaa4bf8: type = 0 ColorModel: #pixelBits = 16 numComponents = 2 color space = java.awt.color.ICC_ColorSpace@6261b548 transparency = 3 has alpha = true isAlphaPre = false ByteInterleavedRaster: width = 32 height = 32 #numDataElements 2 dataOff[0] = 0


I indeed get no error with a JDK 1.5.0-07. Actually, I didn't seem to get that error with an earlier version of the JDK (I think the last one I used before b94 was b85).

Although there is multithreading in the application, there is no modification possible in that block, as there's only one thread that access it, so it isn't an issue.
4  Java Game APIs & Engines / Java 2D / Colour->Grayscale conversion failure using ColorConvertOp on Mustang on: 2006-08-17 09:36:24
Hi,

Here is what I want to do: I have a color BufferedImage, and I want to convert it to a grayscale one. The original image is stored as a PNG. I came up with the following code fragment (I use the Sixlegs PNG library to load PNG files, as it appears that ImageIO sometimes fails to load some of them):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
BufferedImageOp operation = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
BufferedImage my_icon;
BufferedImage my_disabled_icon;

(...)

try
{
    my_icon = new PngImage().read(new File("duke.png"));
    my_disabled_icon = operation.filter(my_icon, null);
}
catch (IOException e)
{
    (...)
}


my_icon indeed contains a valid Image - I verified this by blitting the content of my_icon on screen.
OTOH, my_disabled_icon triggers a NullPointerException with Java Mustang (build 94) at the operation.filter() line. A typical Exception trace starts with:

1  
2  
java.lang.NullPointerException
        at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:238)


I am puzzled by this - did I forget anything, or is that a bug I inadvertantly jumped on ?
Also, maybe there's another, better way to generate a grayscale image from a coloured one ?
5  Java Game APIs & Engines / Java 2D / Resizing problem with Java 1.5, OpenGL and bufferStrategy on: 2006-08-11 15:29:28
Hi,

I'm developping an application that uses bufferStrategy to display its content using double-buffering in a window. But there is indeed a problem I cannot solve when using an 1.5 JVM with the opengl pipeline.

A short example to explain where the problem is. I first took the sample code given in:
http://www.java-gaming.org/forums/index.php?topic=117.0

Then, I changed the content of render() so that it displays a 40x40 image of Duke:

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  
   private void render()
   {
      // If we've lost our video memory, don't bother drawing anything

      if( !bufferStrategy.contentsLost() )
      {
         Graphics2D g = (Graphics2D)(bufferStrategy.getDrawGraphics());
         // Clear the drawing buffer to white
         g.setColor( Color.white );
         g.fillRect( 0, 0, mainFrame.getWidth(), mainFrame.getHeight() );

         // Say hello
         g.translate(0,27);
         g.scale((float)mainFrame.getWidth()/40.0,(float)(mainFrame.getHeight()-27)/40.0);
         g.fillRect( 0, 0, mainFrame.getWidth(), mainFrame.getHeight() );
         g.drawImage(img,0,0,null);
         // We'll stop after 400 frames.
         i++;
         if( i > 400 )
            Running = false;

         bufferStrategy.show();
         g.dispose();
      }
   }


I make a vertical translation of 27 because that's the thickness of my window title - so my Duke isn't partially masked by it. Then I rescale so that the picture will take the whole window space, and finally, I fill the background with white, and finish by drawing the picture.

Under Mustang, that works perfectly:


Same under 1.5 with the "software" rendering pipeline. But now, with the opengl pipeline, that's what I get when resizing the window:


What exactly am I doing wrong ? Is there a solution to this ?
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (15 views)
2014-09-12 09:08:26

Norakomi (45 views)
2014-09-10 13:57:51

TehJavaDev (57 views)
2014-09-10 06:39:09

Tekkerue (26 views)
2014-09-09 02:24:56

mitcheeb (49 views)
2014-09-08 06:06:29

BurntPizza (33 views)
2014-09-07 01:13:42

Longarmx (19 views)
2014-09-07 01:12:14

Longarmx (21 views)
2014-09-07 01:11:22

Longarmx (20 views)
2014-09-07 01:10:19

mitcheeb (30 views)
2014-09-04 23:08:59
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!