Managing graphics memory

My aim is to manipulate graphics memory directly.

Is there a way to allocate an array of bytex/ints directly into the graphics memory ?

Alternatively, is it possible to “grab” the gfx memory pointer from a managed or volatile image ?

Yes, use DirectX and JNI.
No, otherwise.

Cas :slight_smile:

Gosh… :frowning:

An RFE for

int[] array = GraphicsConfiguration.allocateGraphicsMem(size)

?

//

\//
W AllocVec(size,MEMF_CHIP|MEMF_CLEAR); was Amiga style…

Why would you want to be able to do that?
What will you be able to do that you can’t do with, say, VolatileImage?

I write character generators for desktop video applications.
In order to have a certain degree of performance and flexibility, I must map all my graphics into an array of ints.

With the Bitmap class below (well, a small piece of it), I can create the abstraction of a graphics framebuffer mapped to an array and do all my dirty things and also share the same array with three BufferedImages (see createBufferedImage()): one that covers the whole bitmap, and two which represent the image ODD and EVEN fields respectively.

By using the Graphics2D pointers (graphics ,graphics_field[]) I can use any Java2D feature and still low-level access the array so that, for example, I can copy it on the framebuffer of a video-card, etc.

The main problem with this approach is that the bitmap does not reside in graphics memory and so I cannot get the same hardware acceleration of managed an volatileimages.

Now it would be nice allocate gfx mem directly so that I can still do my dirty tricks while taking advantage of hardware acceleration.
Maybe having a method that gives low-level access the gfx memory of a managed/volatileimage would help in my case and several other. Maybe by using the same mechanism of BufferedImages (Raster/DataBufferInt)…

Any help/suggestion ?


// create a bitmap object from an existing array of ints
public Bitmap(int[] pixels, int sx, int sy, int rowints)
{
      if ((pixels != null) && (pixels.length >= rowints * sy))
      {
            // init fields
            this._v = new Vector();
            this.width    = sx;
            this.height   = sy;
            this.rowints  = rowints;
            this.pix      = pixels;
            this.pixrow   = new int[rowints];
            
            // avoid 0 x 0 images and null pointers
            if ((sx*sy)!=0)
            {
                  // create main image
                  this.image             = createBufferedImage(pixels,sx,sy,rowints);
                  this.image_field[0]      = this.image;
                  this.image_field[1]      = this.image;
                  
                  // create fields
                  if (sy>=2)
                  {
                        int fieldheight_0 = sy/2 + (sy&1);
                        int fieldheight_1 = sy/2;
                        this.image_field[0]      = createBufferedImage(pixels,sx,fieldheight_0,rowints*2,0);
                        this.image_field[1]      = createBufferedImage(pixels,sx,fieldheight_1,rowints*2,sx);
                  }

                  // create the pixrow image for row-buffered operations
                  this.pixrowimage       = createBufferedImage(pixrow,sx,1,rowints);
            }
            else
            {
                  // invalid sx, sy: prepare defaults
                  this.image                  = createBufferedImage(1,1,1);
                  this.image_field[0]      = createBufferedImage(1,1,1);
                  this.image_field[1]      = createBufferedImage(1,1,1);
                  this.pixrowimage    = createBufferedImage(1,1,1);
            }
                  
            // init graphics
            this.graphics = this.image.getGraphics();
            this.graphics_field[0] = this.image_field[0].getGraphics();
            this.graphics_field[1] = this.image_field[1].getGraphics();

            // set rendering hints
//            RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//            ((Graphics2D)this.graphics).setRenderingHints(rh);
//            ((Graphics2D)this.graphics_field[0]).setRenderingHints(rh);
//            ((Graphics2D)this.graphics_field[1]).setRenderingHints(rh);
      
      }
}


      // utility: create a new INT_ARGB bufferedimage with rowints support
      public static final BufferedImage createBufferedImage(int[] pixels, int width, int height, int rowints, int pixoffset)
      {
            // the RGBA color masks
            int[] bm = new int[]{0x00FF0000,0x0000FF00,0x000000FF,0xFF000000};
            // the colormodel
            ColorModel cm = new DirectColorModel(32,bm[0],bm[1],bm[2],bm[3]);
            // allocate bitmap data
            DataBufferInt db = new DataBufferInt(pixels,pixels.length,pixoffset);
            WritableRaster wr = WritableRaster.createPackedRaster(db,width,height,rowints,bm,null);
            // the image
            return new BufferedImage(cm,wr,false,null);
      }

My suggestion from your point of view sucks a bit, but I write character generators and realtime tv graphics systems too, and I solved the whole issue by using an API that was designed with high performance rendering in the first place rather than an object oriented kludgy view of the world… so basically: now may be the time to bite the bullet and start using OpenGL.

Cas :slight_smile:

With opengl (you’re referring to LWJGL, I guess) can you overlay text with softshadows over incoming genlocked video ? Can you have perspecitve, semi-transparent objects over video ? No, of course, until you have a specific kind of board that does the overlay for you.

Well, with my approach I can do this in realtime, even if the gfx board doesn’t support OpenGL at all (see Matrox CG2000, Digisuite specs.) Even more I can do this with any hardware graphics frame buffer around…

What I’m asking is basically some low-level access to gfx memory in order to get my translucent (transformed ?) blits hardware accelerated while keeping 100% compatibility with my huge Java2D code base.

[quote]With opengl (you’re referring to LWJGL, I guess) can you overlay text with softshadows over incoming genlocked video? Can you have perspecitve, semi-transparent objects over video ? No, of course, until you have a specific kind of board that does the overlay for you.
[/quote]
Yes, I can, and do. But that’s a trade secret :-* Although I have a feeling we should talk because I think you’ve got some bits and bobs I’d like and I can’t be bothered to code them myself. Particularly fancy font generation.

[quote]Well, with my approach I can do this in realtime, even if the gfx board doesn’t support OpenGL at all (see Matrox CG2000, Digisuite specs.) Even more I can do this with any hardware graphics frame buffer around.
[/quote]
We use a Geforce at the moment (costs $20), but the full monty uses Wildcats. The Matrox cards have an undeserved reputation. The only thing that’s good about them is the output quality; every other conceivable aspect of using Matrox cards makes me want to kill everyone involved.

[quote]What I’m asking is basically some low-level access to gfx memory in order to get my translucent (transformed ?) blits hardware accelerated while keeping 100% compatibility with my huge Java2D code base.
[/quote]
I’m not sure how you’re going to get hardware acceleration just because you’ve got low-level access to memory. If it’s serverside, it’ll run like a dog. If it’s clientside, it’s not accelerated.

Cas :slight_smile:

So let’s talk about a possible cooperation. But I would really like to see your technology at work first :o
Contact me privately.

Talking about Java2D acceleration, I did some tests with accelerated translucent images on 1.4.2_04 and I must admit there’s a fantastic speed increase when setting the java2d.transaccel flag to true. Sadly the acceleration dosn’t take place when you’re using AffineTransforms and/or bilinear interpolation. That’s too bad! OpenGL would greately help in that case, but I would need to rewrite my apps gfx engine from scratch. This is not a solution.

Egoistically speaking, a win32 hardware accelerated Java2D would be one of the best solutions to my speed problems. I saw something about an Java2D on linux and it seems it’s becoming quite fast and stable in 1.5.0 b2 (I just looked at http://developer.java.sun.com/developer/bugParade/bugs/4987370.html comments: “You can crank the delay down to 0ms, enable AlphaComposite, enable Texture, enable Render Quality, enable all the transform options in the demo controls, and you can still get anywhere between 100 and 300 fps with less than 5% CPU usage.”) :o

Would be fantastic if only I could get this on Win too.