gluScaleImage problems

I get the following error when using gluscaleimage to downscale images that are large than 2048*2048 and are not power of 2.

here’s a snippet:

//gather original image data
byte[] data = getDataFromImage(bufferedImage);
ByteBuffer src = ByteBuffer.allocateDirect(data.length);
src.order(ByteOrder.nativeOrder());
src.put(data, 0, data.length);
src.flip();

//determine largest axis
int max = Math.max(
bufferedImage.getWidth(),
bufferedImage.getHeight()
);

	// we need to scale down
	if( max > SFI_IMAGE_WIDTH)
	{
		float ratio = SFI_IMAGE_WIDTH/(float)max;
		
		int outWidth  = (int)(oldWidth*ratio);
		int outHeight = (int)(oldHeight*ratio);
			
		//allocate new buffer(RGB)
		ByteBuffer dest = ByteBuffer.allocate(outWidth*outHeight*3);
		//dest.order(ByteOrder.nativeOrder());
		
		glu.gluScaleImage(GL.GL_RGB, 
				oldWidth, 
				oldHeight,
				GL.GL_UNSIGNED_BYTE,
				src,
				outWidth, 
				outHeight,
				GL.GL_UNSIGNED_BYTE, 
				dest);
		
	}

but then I get the following error:
java.lang.IndexOutOfBoundsException

which i think is incorrect coz i allocate enough bytes for the buffer
any help would be appreciated

Paul

Could you please post the entire exception stack trace?

Could you make the image available along with a snippet of source code?

Try -Djogl.glu.nojava on the command line; does that work around the problem?

The Java port of the GLU scaling routines has been somewhat problematic mainly because the original SGI sources we started with were buggy. For some reason it seems that the current C GLU implementations on most OSs don’t have the same kinds of bugs the OpenGL reference implementation does. We’re looking at rewriting this code in a future (post-1.0) release of JOGL to be based on Java2D. You may want to consider using Java2D’s scaling routines and bilinear interpolation to resize your image. Look at the source code for the IImageUtil class in the JOGL workspace, in particular the routine which creates a thumbnail; actually, you may be able to use this routine unmodified for what you want to do.