What is the best way to scale a 2D greyscale image?

I’m working on medical image viewer, and need to rapidly scale 8-bit greyscale images. I’m hoping that there is some way of doing this in jogl so that I can compare the results with J2D. I can create a pbuffer okay, but I don’t know how to set the pbuffer’s format and data type. Should I be using the default (i.e. RGBA) for the pbuffer and just specify greyscale in the glDrawPixels and glReadPixels methods? This feels like a lot of unnecessary conversion to me.

Do you need to read back the scaled data or just display it?

Either way I would probably suggest uploading your data into a texture rather than using glDrawPixels. If you need to draw dynamic data rather than a single static texture over and over again at different zoom levels, I would recommend investigating the Pixel Buffer Object extension.

If you can avoid reading back the frame buffer using glReadPixels your performance will be higher.

thanks for the quick feedback. I don’t need to be drawing anything so I’ll start with a texture.

PBuffers + ARB_texture_non_power_of_two is your friend then. Look them up on the forum… I dont have the time to write an example program, but I might have tonight… work work…

I’m not sure, but you might be better of with a variation of this algorithm:
fastest texture generating algorithm

you dont even need opengl with that. just replace ‘textureWidth’ and ‘textureHeight’ with the height/width you want (at this point, it generates power-of-two textures)

I wrote that to do video -> texture generation. It’s fast.

I need linear interpolation. It doesn’t look like tusaki’s algorithm is interpolating. I tried using glu.gluScaleImage(), but that was flaking out on me. The source byte buffer was being replace by a zero length one before being passed to Mipsmap.gluScaleImage(). I was able to get Mipsmap.gluScaleImage() mostly working, but it’s pure java which sort of defeats the purpose of using OpenGL. I’m curious if anyone can tell me why glu.gluScaleImage() might be choking (I don’t have the source).

  glu.gluScaleImage(  GL.GL_LUMINANCE, src_width, src_height,
        GL.GL_UNSIGNED_BYTE, src_bytes, dst_width, dst_height,
        GL.GL_UNSIGNED_BYTE, scaled_bytes );

It sounds like there might be a bug in the Java port of gluScaleImage for luminance textures. Does the problem disappear if you specify -Djogl.glu.nojava on the command line? If so, could you please file a bug with the JOGL Issue Tracker (you’ll need to be an Observer of the project) and attach it?

I was using ByteBuffer.allocate().put() to create my source and destination buffers rather than ByteBuffer.wrap(). I created an issue #200 to request better exceptions when using Buffer.allocate(). I also added issue #201 to explain some flakyness I saw in Mipsmap.gluScaleImage. I hope these help the cause. Thanks to everyone who responded.