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

java.awt.image.RescaleOp produces incorrect results

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Build:
      b01
    • Introduced In Version:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      java version "1.8.0_271"
      Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
      Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)

      Bug occurred on OSX as well as on CentOS.

      A DESCRIPTION OF THE PROBLEM :
      The java.awt.image.RescaleOp class produces incorrect results for certain PNG images.

      The operation is applied only to a subset of the source image, with greyed out background where a transparent background is expected.

      With Oracle JDK 1.8.0_251 the results are still as expected.

      This bug occurred with a PNG encoded source image with transparent background.


      REGRESSION : Last worked in JDK 1.8.0_251

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See https://github.com/agawecki/java-rescale-op-test



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Rescale operation applied homogeneously to source image and leaves the transparent background intact.
      ACTUAL -
      The rescale operation is applied to a subset of the source image and garbles the transparent background.

      ---------- BEGIN SOURCE ----------
      package test;

      import javax.imageio.ImageIO;
      import java.awt.image.BufferedImage;
      import java.awt.image.RescaleOp;
      import java.io.File;

      public class Main {

        public static void main(String[] args) {
          System.out.println(System.getProperty("java.version"));

          String imageFileName = "test.png";
          try {
            File imageFile = new File(imageFileName);
            BufferedImage image = ImageIO.read(imageFile);
            rescale(image, 1.0f, 50.0f);

            File outputFile = new File(imageFile.getParent(), "rescaled-" + imageFile.getName());
            ImageIO.write(image, "png", outputFile);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }

        static BufferedImage rescale(BufferedImage img,
                                     float factor,
                                     float offset) {
          RescaleOp rescaleOp = new RescaleOp(factor, offset, null);
          return rescaleOp.filter(img, img);
        }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

        1. Main.java
          0.9 kB
        2. rescaled-test.png
          rescaled-test.png
          52 kB
        3. test.png
          test.png
          59 kB

          Issue Links

            Activity

              People

              Assignee:
              skodandarama Suman Rajkumaar Kodandarama
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: