/** Optional, throws GLException if not available in profile */
 public final int gluScaleImage(
     int format,
     int widthin,
     int heightin,
     int typein,
     java.nio.Buffer datain,
     int widthout,
     int heightout,
     int typeout,
     java.nio.Buffer dataout) {
   validateMipmap();
   java.nio.ByteBuffer in = null;
   java.nio.ByteBuffer out = null;
   in = copyToByteBuffer(datain);
   if (dataout instanceof java.nio.ByteBuffer) {
     out = (java.nio.ByteBuffer) dataout;
   } else if (dataout instanceof java.nio.ShortBuffer) {
     out = Buffers.newDirectByteBuffer(dataout.remaining() * Buffers.SIZEOF_SHORT);
   } else if (dataout instanceof java.nio.IntBuffer) {
     out = Buffers.newDirectByteBuffer(dataout.remaining() * Buffers.SIZEOF_INT);
   } else if (dataout instanceof java.nio.FloatBuffer) {
     out = Buffers.newDirectByteBuffer(dataout.remaining() * Buffers.SIZEOF_FLOAT);
   } else {
     throw new IllegalArgumentException(
         "Unsupported destination buffer type (must be byte, short, int, or float)");
   }
   int errno =
       Mipmap.gluScaleImage(
           getCurrentGL2ES1(),
           format,
           widthin,
           heightin,
           typein,
           in,
           widthout,
           heightout,
           typeout,
           out);
   if (errno == 0) {
     out.rewind();
     if (out != dataout) {
       if (dataout instanceof java.nio.ShortBuffer) {
         ((java.nio.ShortBuffer) dataout).put(out.asShortBuffer());
       } else if (dataout instanceof java.nio.IntBuffer) {
         ((java.nio.IntBuffer) dataout).put(out.asIntBuffer());
       } else if (dataout instanceof java.nio.FloatBuffer) {
         ((java.nio.FloatBuffer) dataout).put(out.asFloatBuffer());
       } else {
         throw new RuntimeException("Should not reach here");
       }
     }
   }
   return (errno);
 }
 private final java.nio.ByteBuffer copyToByteBuffer(java.nio.Buffer buf) {
   if (buf instanceof java.nio.ByteBuffer) {
     if (buf.position() == 0) {
       return (java.nio.ByteBuffer) buf;
     }
     return Buffers.copyByteBuffer((java.nio.ByteBuffer) buf);
   } else if (buf instanceof java.nio.ShortBuffer) {
     return Buffers.copyShortBufferAsByteBuffer((java.nio.ShortBuffer) buf);
   } else if (buf instanceof java.nio.IntBuffer) {
     return Buffers.copyIntBufferAsByteBuffer((java.nio.IntBuffer) buf);
   } else if (buf instanceof java.nio.FloatBuffer) {
     return Buffers.copyFloatBufferAsByteBuffer((java.nio.FloatBuffer) buf);
   } else {
     throw new IllegalArgumentException(
         "Unsupported buffer type (must be one of byte, short, int, or float)");
   }
 }