Hello all.  Amazingly this is kind of related to Java3D, since I am
trying to do this to load textures.  But mostly, nobody else has replied
to me on the forums, so I am hoping someone here can. :)

I've been working on an Image I/O plugin for an image format containing
multiple images in a single file. I have everything reading in
correctly, but I am having a really hard time getting the image to
reconstruct correctly. I have been using the following guide to help me
through:
http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/imageio_guideTOC.fm.html

I am positive I am getting all the data correctly, since I have a
working Perl script to convert the items into seperate BMPs. I can
output the data I am getting to a file and the two image files match.

What I have is a 1024 bit palette and a compressed data block (using
RLE). I uncompress the data block and then try to construct the output
WriterRaster and BufferedImage according to the above guide.

Here is the code block which should create the output objects. Just
below this, I return 'dst'.

    /** create the output buffered image */
    BufferedImage dst = getDestination(param,
getImageTypes(imageIndex), sizeX, sizeY);

    int bytesPerRow = sizeX * bandOffsets.length;
    DataBufferByte rowDataBuffer = new DataBufferByte(bytesPerRow);
    WritableRaster rowRaster =
Raster.createInterleavedRaster(rowDataBuffer, sizeX, 1, bytesPerRow,
bandOffsets.length, bandOffsets, new Point(0,0));

    byte[] rowBuffer = rowDataBuffer.getData();

    /** create a single pixel int[] */
    int[] pixel = rowRaster.getPixel(0, 0, (int[])null);

    WritableRaster imgRaster = dst.getWritableTile(0, 0);

    /** bmpData = uncompressed data, suitable for export to BMP */
    ByteArrayInputStream dataStream = new
ByteArrayInputStream(bmpData.getBytes());
    for (int srcY=0; srcY < sizeY; srcY++) {
      /** read in a row of the compressed data */
      try {
        dataStream.read(rowBuffer);
      } catch (IOException e) {
        throw new IIOException("Error reading line " + srcY, e);
      }

      int dstY = srcY;

      for (int srcX=0; srcX < sizeX; srcX++) {
        int dstX = srcX;

        rowRaster.getPixel(srcX, 0, pixel);
        imgRaster.setPixel(dstX, dstY, pixel);
      }
    }


Here is my 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");

    ImageTypeSpecifier imageType = ImageTypeSpecifier.createInterleaved(
            ColorSpace.getInstance(ColorSpace.CS_sRGB), bandOffsets,
DataBuffer.TYPE_BYTE, true, false);

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

    return list.iterator();
  }


I am assuming that part of my problem is the "ColorSpace.getInstance(...)" call -- which I should replace with my color palette (if I understand it correctly). However, again as I understand it, I should get the correct picture with wrong colors if my image construction is correct. Yes?

I also realize that my current construction is "wasteful". I plan
ImageReadParam support later, which (according to the guide) is made
easier with the line-by-line copy. At the moment I am not concerned with
speed; I am concerned with function. :)

Please (please, please, oh please), if you see anything in the code or
maybe have another working example, any help is greatly appreciated!

Thanks very much!

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

Reply via email to