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