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

BILINEAR and BICUBIC interpolation broken for scales less than 1

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P4
    • None
    • 5.0
    • client-libs
    • 2d
    • x86
    • windows_xp

    Description

      FULL PRODUCT VERSION :
      java version "1.5.0_09"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_09-b03, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      BILINEAR and BICUBIC interpolation seems to be broken when downsampling images (for example when producing thumbnails). Scales slightly less than one produce more-or-less acceptable results, but the results get progressively worse as the scale reduces. At scales of around 0.333 the image is visually identical to nearest neighbour interpolation.

      My interest is in downsampling at the moment. I have not experimented to see whether there are situations when scaling up produces unacceptable results.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      In the attached code sample, try adjusting the value of the 'scale' variable. Suggested values are:

      0.66666
      0.5
      0.33333

      Compare the resulting image files. The quality of the image degrades significantly as the scale decreases.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Bilinear and bicubic interpolation should work for all scales - iIncluding those less than 1.
      ACTUAL -
      Results degrade markedly as the scale reduces.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
            BufferedImage duke = ImageIO.read(new File(args[0]));
            int w = duke.getWidth(null);
            int h = duke.getHeight(null);
            double scale = 0.6666666;
            BufferedImage nearest = new BufferedImage((int)(w*scale), (int)(h*scale), BufferedImage.TYPE_INT_RGB);
            BufferedImage bilinear = new BufferedImage((int)(w*scale), (int)(h*scale), BufferedImage.TYPE_INT_RGB);
            BufferedImage bicubic = new BufferedImage((int)(w*scale), (int)(h*scale), BufferedImage.TYPE_INT_RGB);

            Graphics2D bg = nearest.createGraphics();
            bg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
            bg.scale(scale, scale);
            bg.drawImage(duke, 0, 0, null);
            bg.dispose();
            ImageIO.write(nearest, "png", new File("nearest_"+scale+".png"));

            bg = bilinear.createGraphics();
            bg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            bg.scale(scale, scale);
            bg.drawImage(duke, 0, 0, null);
            bg.dispose();
            ImageIO.write(bilinear, "png", new File("bilinear_"+scale+".png"));

            bg = bicubic.createGraphics();
            bg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            bg.scale(scale, scale);
            bg.drawImage(duke, 0, 0, null);
            bg.dispose();
            ImageIO.write(bicubic, "png", new File("bicubic_"+scale+".png"));


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

      CUSTOMER SUBMITTED WORKAROUND :
      No known workaround other than using alternative code for downsampling images.

      Attachments

        Issue Links

          Activity

            People

              campbell Christopher Campbell (Inactive)
              prr Philip Race
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: