Using video ram to store images?

Hi i know video ram is the best place to store images, bliting from video ram into the current buffer should be heaps quicker.

The question is how do you load the image into the video ram?

Is it being done automaticlly?

What is the best design to load and blit images?

Thanks heaps for any help!
Harley.

First off you’ll have to be using 1.4, otherwise you won’t be able to take advantage. Secondly have a look for VolatileImage, which is stored only in vRam and which you need to do management of image loss manually. However there are a couple of snafus that may trip you up with volative images, namely i dont think you can do any sort of transparency :o

There’s also ‘AutomaticImages’ which are regular BufferedImages which the VM will attempt to cache in vRam, and handle management itself. With the correct massaging you can also get these to have 1-bit transparency and still be hardware accelerated.

A code snippit from my (now on permanent hold, :-[ ) Phoenix project:


      /** Loads image, creates automatic image/buffered image and copies it into it.
        * Currently only tested with gifs, so undefined if any other file path is passed to it.
        */
      public BufferedImage loadImage(String filename, boolean solid)
      {
            // Load image from file.
            Image tempImage = new ImageIcon(filename).getImage();
            
            BufferedImage sprite = null;
            
            // Get dimensions of image
            int spriteW = tempImage.getWidth(null);
            int spriteH = tempImage.getHeight(null);
            
            if (spriteW != -1)
            {
                  // If a solid tile, load as such. Otherwise use bitmask transparency
                  if (solid)
                              sprite = graphicsConfig.createCompatibleImage(spriteW, spriteH, Transparency.OPAQUE);
                  else
                              sprite = graphicsConfig.createCompatibleImage(spriteW, spriteH, Transparency.BITMASK);
                  
                  
                  // Copy from Image to BufferedImage
                  Graphics2D g = (Graphics2D)sprite.getGraphics();
                  
                  g.drawImage(tempImage, null, null);
                  g.dispose();
            }
            else
            {
                  System.out.println("Error loading images: " + filename + " not found");
            }
            
            return sprite;
      }

Jeff et al, if you’re reading this - how long until we see a full site with the articles section up again?

So the key method is createCompatibleImage, which is used to create AutomaticImages.

Is there much difference between normal awt.Images, loaded from ImageIO, to automatic images?
Assuming the sprites are tranparent.

Thanks.

Currently none of the images loaded with ImageIO are accelerated, as opposed to those loaded with Toolkit.getImage() , for example.

Also, note that in order to take advantage of those images being accelerated, you need to copy them to the accelerated back-buffer. You should use VolatileImage for the back-buffer.
Check out the articles on
http://java.sun.com/products/java-media/2D/
for more info.

I hope that the Toolkit.getImage methods will soon be replaced under the hood with the ImageIO stuff anyway… it will get rid of some redundant code… If so, I assume that ImageIo based images will be accelerated… maybe for 1.5?

Yep, that’s the plan.