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

BytePackedRaster.setDataElements clips thin scanlines incorrectly

XMLWordPrintable

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

        The setDataElements(int, int, Raster) method of sun.awt.image.BytePackedRaster
      contains code to handle the case where all of the modifications to a scanline
      take place within a single byte. In this case, the bits to the left and to the
      right of the bits being modified must be preserved, which is accomplished via
      a read-modify-write sequence. However, the expression used to compute the
      mask is not correct, resulting in fewer bits being modified than should be.

        The relevant code to compute the mask is as follows:

      int bits = inbit & 7;
                          if (bits != 0) {
                              // Copy partial bytes on left
                              int inbyte = inbit >> 3;
                              int outbyte = outbit >> 3;
                              int mask = 0xff >> bits; // A
                              bits = 8 - bits; // B
                              if (copybits < bits) { // C
                                  mask = mask & (mask << (8 - copybits)); // D
                                  bits = copybits;
                              }
                              for (int j = 0; j < h; j++) {
                                  int element = outData[outbyte];
                                  element &= ~mask;
                                  element |= (inData[inbyte] & mask);
                                  outData[outbyte] = (byte) element;
                                  inbyte += inscan;
                                  outbyte += outscan;
                              }

      At point A, the mask is set to 0xff (8 bits on), and shifted right by
      'bits' positions, where 'bits' is (at this point) the number of bits to
      be skipped on the left side of the output byte. Thus mask has '8 - bits'
      bits set. After point B, we redefine 'bits', so we can say that the
      mask has 'bits' bits set. If we used the mask now, 'bits' bits would
      be modified in the output.

        At point C, we determine whether the data to be written extend at least
      to the end of the first output byte. If not, i.e., copybits < bits,
      we want to alter the mask so that only 'copybits' bits of the output
      will be modified. Thus we want to introduce zeroes into the right side
      of the mask so a total of 'copybits' bits will remain set. Since 'bits'
      bits are already set, we should clear 'bits - copybits' bits. The
      code at point D clears '8 - copybits' bits, which is too many, resulting
      in a failure to write all the desired data.

        This behavior has been observed in the Image I/O PNG plug-in with
      suitable settings on an ImageReadParam.

            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: