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

[TIFF] biased colors for TYPE_USHORT_555_RGB image during a sequential write

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9
    • Fix Version/s: tbd
    • Component/s: client-libs
    • Labels:

      Description

      Please run the following test code:


      import java.io.*;
      import java.awt.*;
      import java.awt.image.BufferedImage;
      import javax.imageio.*;
      import javax.imageio.stream.*;


      public class Test {
          
          private final String format = "tiff";

          private ImageWriter getWriter() {

              java.util.Iterator<ImageWriter> writers =
                  ImageIO.getImageWritersByFormatName(format);
              if (!writers.hasNext()) {
                  throw new RuntimeException("No writers available for " + format);
              }
              return writers.next();
          }
          
          private static final int TYPES[] = {
              BufferedImage.TYPE_USHORT_565_RGB,
              BufferedImage.TYPE_USHORT_555_RGB};
          private static final String NAMES[] = {
              "TYPE_USHORT_565_RGB",
              "TYPE_USHORT_555_RGB"};

          private BufferedImage getImage(int type) {

              int l = 100;
              BufferedImage img = new BufferedImage(l, l, type);
              Graphics g = img.getGraphics();
              g.setColor(Color.BLACK);
              g.fillRect(0, 0, l, l);
              g.setColor(Color.WHITE);
              g.fillRect(15, 15, l - 30, l - 30);
              g.dispose();
              return img;
          }

          private void run() throws IOException {

              ImageWriter writer = getWriter();

              for (int i = 0; i < TYPES.length; i++) {

                  BufferedImage bi = getImage(TYPES[i]);
                  File out = new File("out-" + NAMES[i] + "." + format);
                  ImageOutputStream ios = ImageIO.createImageOutputStream(out);
                  writer.setOutput(ios);
                  writer.write(new IIOImage(bi, null, null));
                  ios.flush();
                  writer.dispose();
              }
          }

          public static void main(String[] args) throws IOException { (new Test()).run(); }
      }

      The colors for out-TYPE_USHORT_555_RGB.tiff will be biased (please see the image attached) - RGB = {255, 125, 255} in the center.

      Then remove "TYPE_USHORT_565_RGB" from TYPES and NAMES - the image will have proper (white) color in the center.

      No issues for, e.g., PNG format.

      JDK/OS: JDK9 b113 + Windows 7

      The issue is closely connected to JDK-8150154 (and is covered by RepeatingWriteTest.java as well).

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jdv Jayathirth D V
              Reporter:
              avstepan Alexander Stepanov
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated: