Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4380697

4 bits/pixel BufferedImage incorrectly gets TYPE_BYTE_BINARY

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • client-libs
    • None
    • 2d
    • generic
    • solaris_7

        When a BufferedImage is contsructed using the constructor:

      BufferedImage(ColorModel, WritableRaster, boolean, Hashtable)

      the type of the BufferedImage is inferred from the ColorModel and
      WritableRaster. When an IndexColorModel is used along with a BytePackedRaster,
      the type is taken to be TYPE_BYTE_BINARY, even when the number of bits
      per pixel in the Raster is greater than 1. In this case, TYPE_BYTE_INDEXED
      would seem to be more appropriate.

        Image display does not appear to be affected by this bug.

        A test program exhibiting this behavior is below:


      import java.awt.Dimension;
      import java.awt.Graphics;
      import java.awt.Point;
      import java.awt.image.BufferedImage;
      import java.awt.image.ColorModel;
      import java.awt.image.DataBuffer;
      import java.awt.image.IndexColorModel;
      import java.awt.image.MultiPixelPackedSampleModel;
      import java.awt.image.SampleModel;
      import java.awt.image.Raster;
      import java.awt.image.WritableRaster;

      public class BufferedImageTest {

          public static void main(String[] args) {
              int width = 100;
              int height = 100;
              int bpp = 2;
              int colors = 1 << bpp;

              byte[] red = new byte[colors];
              byte[] green = new byte[colors];
              byte[] blue = new byte[colors];
              ColorModel cm = new IndexColorModel(bpp,
                                                  colors,
                                                  red,
                                                  green,
                                                  blue);

              SampleModel sm =
                  new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                  width,
                                                  height,
                                                  bpp);

              WritableRaster ras = Raster.createWritableRaster(sm, new Point(0, 0));

              BufferedImage bi = new BufferedImage(cm, ras, false, null);
              int type = bi.getType();
              System.out.println("BufferedImage type = " + type);
              System.out.println(" (TYPE_BYTE_BINARY = " +
                                 BufferedImage.TYPE_BYTE_BINARY + ")");
              System.out.println(" (TYPE_BYTE_INDEXED = " +
                                 BufferedImage.TYPE_BYTE_INDEXED + ")");
          }
      }

            dricesunw Daniel Rice (Inactive)
            dricesunw Daniel Rice (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: