Hello all.

       I'm having a heck of a time getting my first Image I/O reader done; I'm
hoping someone here can help me out.  I've been using the Image I/O
guide to help me out, and I'm able to properly read in my image now, but
I have not been able to properly construct my BufferedImage to return
from read() yet.
       The image I am dealing with a sprite format for a small game.  It can
hold more then 1 image per file and has a 1024 byte palette at the end
of the file.  I am able to read all the information out correctly, and I
can even write a BMP file to the drive.  But I'm lost in getting all
that data into the BufferedImage.
       Based on looking at the com.sun.imageio.plugins.gif.GIFImageReader
class, I put together the following getImageTypes() function:

  public Iterator getImageTypes(int imageIndex) throws IOException {
    readHeader();

    /** verify the index is valid */
    if (imageIndex < 0 || imageIndex >= imgCount)
      throw new IndexOutOfBoundsException("bad index");

    /** output file is 8-bit */
    int bits = 8;

    int lutLength = 1 << bits;
    byte[] r = new byte[lutLength];
    byte[] g = new byte[lutLength];
    byte[] b = new byte[lutLength];
    byte[] a = new byte[lutLength];

    int rgbIndex = 0;
    for (int i=0; i < sprPalette.length / 4; i++) {
      r[i] = sprPalette[rgbIndex++];
      g[i] = sprPalette[rgbIndex++];
      b[i] = sprPalette[rgbIndex++];
      a[i] = sprPalette[rgbIndex++];
    }

    ImageTypeSpecifier imageType = ImageTypeSpecifier.createIndexed(
            r, g, b, a, bits, DataBuffer.TYPE_BYTE);

    ArrayList list = new ArrayList();
    list.add(imageType);

    return list.iterator();
  }

       I'm almost positive my RPBA order is incorrect, but that *should* just
result in funky colors in my final image.  Yes?

       I thought about including the block of code that I currently have setup
to create my BufferedImage, but why mock myself further. :)  The data I
have is actually very easy to explain... in the uncompressed state, it
is a valid BMP image data block and be written straight out to file as such.
       With a properly constructed ImageTypeSpecifier, how could I take a
valid BMP image data block and construct a BufferedImage suitable for
output?
       I did a short search for the JAI Image I/O API source, for the BMP
reader, but couldn't find it.

       Any help in this matter is greatly appreciated!  I have been fighting
this for days.

       Nick

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to