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

[macosx] ByteLookupTable order of components (differs between JRE 7 and 8)

XMLWordPrintable

    • 2d
    • x86
    • os_x

      FULL PRODUCT VERSION :
      java version "1.8.0_51"
      Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      OS X 10.9.5

      A DESCRIPTION OF THE PROBLEM :
      When filtering a BufferedImage, a LookupOp created with a ByteLookupTable produces different results in Java JRE 8 than 7. This results in incorrect BufferedImage colors. There appear to be differences in how the ByteLookupTable components should be ordered based on native byte order, OS, and JRE version. There is no clear way to know how the components should be ordered other than trial and error.

      More info: http://stackoverflow.com/questions/31859018/bytelookuptable-order-of-components-differs-between-jre-7-and-8

      REGRESSION. Last worked in version 7u80

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.7.0_80"
      Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Run the example code below on Java JRE 7. Record results.

      2) Run the example code below on Java JRE 8. Record results.

      3) Compare results.

      The results differ on OS X. The results differ on Linux. On Windows the results match (the same result as Java JRE 8 on OS X and Linux).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      00000011 00000010 00000001 00000100
      ACTUAL -
      00000100 00000001 00000010 00000011

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Test {

          public static void main(final String[] args) {
              final byte[] lutArrayG = new byte[256];
              final byte[] lutArrayR = new byte[256];
              final byte[] lutArrayA = new byte[256];
              final byte[] lutArrayB = new byte[256];

              Arrays.fill(lutArrayG, (byte) 1);
              Arrays.fill(lutArrayR, (byte) 2);
              Arrays.fill(lutArrayA, (byte) 3);
              Arrays.fill(lutArrayB, (byte) 4);

              final byte[][] lutArrays = new byte[4][];

              // what is the correct order to use? this one...
              lutArrays[0] = lutArrayG;
              lutArrays[1] = lutArrayR;
              lutArrays[2] = lutArrayA;
              lutArrays[3] = lutArrayB;

              // or this one...
              //lutArrays[1] = lutArrayG;
              //lutArrays[0] = lutArrayR;
              //lutArrays[3] = lutArrayA;
              //lutArrays[2] = lutArrayB;

              final ByteLookupTable lut = new ByteLookupTable(0, lutArrays);
              final LookupOp lutOp = new LookupOp(lut, null);
              final BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
              final BufferedImage imageFiltered = lutOp.filter(image, null);
              final int value = imageFiltered.getRGB(0, 0);

              System.out.println(makeNiceBinaryString(value));
          }


          public static String makeNiceBinaryString(final int value) {
              final StringBuffer sb = new StringBuffer(String.format("%32s", Integer.toBinaryString(value)).replace(' ', '0'));
              sb.insert(sb.length() - 32, " ");
              sb.insert(sb.length() - 24, " ");
              sb.insert(sb.length() - 16, " ");
              sb.insert(sb.length() - 8, " ");
              return sb.toString();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Test all possible platforms ahead of time to determine which is the correct component order for that platform.

            scfitch Stephen Fitch
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: