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

Restrict BufferedImage.TYPE_BYTE_BINARY to 1, 2, and 4 bit images

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.3.0, 1.4.0
    • client-libs
    • None
    • 2d
    • beta
    • generic
    • solaris_7

        The BufferedImage type TYPE_BYTE_BINARY is currently used for 1, 2, 4, or
      8 bit images using an IndexColorModel and a BytePackedRaster. There are several
      problems with the current state of affairs:

      1) The documentation is not explicit on how 2- or 4-bit indexed color
         images are to be represented. Current practice is to use a BufferedImage
         type of TYPE_BYTE_BINARY (as opposed to TYPE_CUSTOM), but this is
         poorly documented.

         The documentation for BufferedImage.TYPE_BYTE_BINARY should be changed
         to indicate that it is to be used for 1, 2, and 4-bit sample depths
         only.

      2) 1-banded byte images with a single 8-bit sample per pixel may be represented
         by a BufferedImage type of TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED.
         Internally, they may be represented by either a BytePackedRaster or a
         ByteInterleavedRaster. This duplication results in extra effort for
         developers and possibly unexpected behavior for users when seemingly
         equivalent images fdo not ineroperate properly.

         At the user-visible API level, this may be fixed by disallowing
         the use of TYPE_BYTE_BINARY for 8-bit images. The only way that such
         an image could have been generated with the current implementation
         is if the application first created a BytePackedRaster via a factory
         method of Raster. By changing the Raster code to return a
         ByteInterleavedRaster for 8-bit data, this case may be avoided.

         User code that expected a particular image type from BufferedImage
         will be affected, but such code was not conformant to the specification
         to begin with.

      3) 1-bit TYPE_BYTE_BIANRY images may have a custom color map supplied using a
         special BufferedImage constructor, whereas the color map of 2- or 4-bit
         indexed color images can be set by the user only by roundabout means, namely
         by first constructing a Raster with the desired IndexColorModel.

         This should be fixed for the sake of convenience and consistency.
         The BufferedImage constructor should detect the desired bit depth
         by examining the number of color map entries and using a bit depth
         of 1 for 1 or 2 entries, 2 for 3 or 4 entries, or 4 for 5 to 16 entries.
         More than 16 entries should result in an IllegalArgumentException.
         
      Ideally, TYPE_BYTE_BINARY would refer to 1-bit deep images only and a
      different type or types would be used for 2 and 4 bit gray or indexed
      color images. However, compatibility and time constraints make this too
      difficult at the present time.

            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: