예제 #1
0
 /**
  * Return the Image pixels in default Java int ARGB format.
  *
  * @return
  */
 public static int[] getImagePixels(Image image) {
   int[] pixelsARGB = null;
   if (image != null) {
     int imgw = image.getWidth(null);
     int imgh = image.getHeight(null);
     pixelsARGB = new int[imgw * imgh];
     PixelGrabber pg = new PixelGrabber(image, 0, 0, imgw, imgh, pixelsARGB, 0, imgw);
     try {
       pg.grabPixels();
     } catch (Exception e) {
       GLApp.err("Pixel Grabbing interrupted!");
       return null;
     }
   }
   return pixelsARGB;
 }
예제 #2
0
파일: Mipmap.java 프로젝트: rothwell/jogl
  public static int gluScaleImage(
      GL gl,
      int format,
      int widthin,
      int heightin,
      int typein,
      ByteBuffer datain,
      int widthout,
      int heightout,
      int typeout,
      ByteBuffer dataout) {
    int datainPos = datain.position();
    int dataoutPos = dataout.position();
    try {

      int components;
      ByteBuffer beforeimage;
      ByteBuffer afterimage;
      PixelStorageModes psm = new PixelStorageModes();

      if ((widthin == 0) || (heightin == 0) || (widthout == 0) || (heightout == 0)) {
        return (0);
      }
      if ((widthin < 0) || (heightin < 0) || (widthout < 0) || (heightout < 0)) {
        return (GLU.GLU_INVALID_VALUE);
      }
      if (!legalFormat(format) || !legalType(typein) || !legalType(typeout)) {
        return (GLU.GLU_INVALID_ENUM);
      }
      if (!isLegalFormatForPackedPixelType(format, typein)) {
        return (GLU.GLU_INVALID_OPERATION);
      }
      if (!isLegalFormatForPackedPixelType(format, typeout)) {
        return (GLU.GLU_INVALID_OPERATION);
      }
      beforeimage =
          Buffers.newDirectByteBuffer(
              image_size(widthin, heightin, format, GL2GL3.GL_UNSIGNED_SHORT));
      afterimage =
          Buffers.newDirectByteBuffer(
              image_size(widthout, heightout, format, GL2GL3.GL_UNSIGNED_SHORT));
      if (beforeimage == null || afterimage == null) {
        return (GLU.GLU_OUT_OF_MEMORY);
      }

      retrieveStoreModes(gl, psm);
      Image.fill_image(
          psm,
          widthin,
          heightin,
          format,
          typein,
          is_index(format),
          datain,
          beforeimage.asShortBuffer());
      components = elements_per_group(format, 0);
      ScaleInternal.scale_internal(
          components,
          widthin,
          heightin,
          beforeimage.asShortBuffer(),
          widthout,
          heightout,
          afterimage.asShortBuffer());
      Image.empty_image(
          psm,
          widthout,
          heightout,
          format,
          typeout,
          is_index(format),
          afterimage.asShortBuffer(),
          dataout);

      return (0);
    } finally {
      datain.position(datainPos);
      dataout.position(dataoutPos);
    }
  }