Esempio n. 1
0
 /** Creates an SGIImage from the specified data in either RGB or RGBA format. */
 public static SGIImage createFromData(
     final int width, final int height, final boolean hasAlpha, final byte[] data) {
   final Header header = new Header();
   header.xsize = (short) width;
   header.ysize = (short) height;
   header.zsize = (short) (hasAlpha ? 4 : 3);
   final SGIImage image = new SGIImage(header);
   image.data = data;
   return image;
 }
Esempio n. 2
0
  private void decodeImage(final DataInputStream in) throws IOException {
    if (header.storage == 1) {
      // Read RLE compression data; row starts and sizes
      final int x = header.ysize * header.zsize;
      rowStart = new int[x];
      rowSize = new int[x];
      rleEnd = 4 * 2 * x + 512;
      for (int i = 0; i < x; i++) {
        rowStart[i] = in.readInt();
      }
      for (int i = 0; i < x; i++) {
        rowSize[i] = in.readInt();
      }
      tmpRead = new byte[header.xsize * 256];
    }
    tmpData = readAll(in);

    final int xsize = header.xsize;
    final int ysize = header.ysize;
    final int zsize = header.zsize;
    int lptr = 0;

    data = new byte[xsize * ysize * 4];
    final byte[] rbuf = new byte[xsize];
    final byte[] gbuf = new byte[xsize];
    final byte[] bbuf = new byte[xsize];
    final byte[] abuf = new byte[xsize];
    for (int y = 0; y < ysize; y++) {
      if (zsize >= 4) {
        getRow(rbuf, y, 0);
        getRow(gbuf, y, 1);
        getRow(bbuf, y, 2);
        getRow(abuf, y, 3);
        rgbatorgba(rbuf, gbuf, bbuf, abuf, data, lptr);
      } else if (zsize == 3) {
        getRow(rbuf, y, 0);
        getRow(gbuf, y, 1);
        getRow(bbuf, y, 2);
        rgbtorgba(rbuf, gbuf, bbuf, data, lptr);
      } else if (zsize == 2) {
        getRow(rbuf, y, 0);
        getRow(abuf, y, 1);
        latorgba(rbuf, abuf, data, lptr);
      } else {
        getRow(rbuf, y, 0);
        bwtorgba(rbuf, data, lptr);
      }
      lptr += 4 * xsize;
    }
    rowStart = null;
    rowSize = null;
    tmpData = null;
    tmpRead = null;
    format = GL.GL_RGBA;
    header.zsize = 4;
  }
Esempio n. 3
0
 @Override
 public String toString() {
   return header.toString();
 }