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

[macosx] Multi resolution image: should it be possible to load tiff?

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:

      Description

      Not sure if a bug, just in case:

      was checked with Quartz Debug emulation for HiDPI.

      please run the following code:

      import java.awt.*;
      import java.awt.event.*;
      import java.awt.image.*;
      import java.io.File;
      import javax.imageio.ImageIO;


      public class Test extends Frame {

          static Image img;
          public Test() { EventQueue.invokeLater(this::CreateUI); }

          private static final int sz = 100;
          private static final String name1x = "image.png";
          private static final String name2x = "image@2x.png";

          static void generateImages() throws Exception {
              if (!new File(name1x).exists()) { generateImage(1); }
              if (!new File(name2x).exists()) { generateImage(2); }
          }

          static void generateImage(int scale) throws Exception {
              BufferedImage image = new BufferedImage(scale * sz, scale * sz, BufferedImage.TYPE_INT_RGB);
              Graphics g = image.getGraphics();
              g.setColor(scale == 1 ? Color.GREEN : Color.BLUE);
              g.fillRect(0, 0, scale * sz, scale * sz);
              File file = new File(scale == 1 ? name1x : name2x);
              ImageIO.write(image, "png", file);
          }

          private void CreateUI() {
              addWindowListener(new WindowAdapter() {
                  @Override
                  public void windowClosing(WindowEvent e) { dispose(); }
              });

              setSize(300, 300);
              setVisible(true);
          }

          @Override
          public void paint(Graphics gr) {
              Graphics2D g = (Graphics2D) gr;
              if (g != null) {
                  File imageFile = new File(name1x);
                  //File imageFile = new File("image.tiff");
                  String fileName = imageFile.getAbsolutePath();
                  img = Toolkit.getDefaultToolkit().getImage(fileName);
                  g.drawImage(img, 0, 0, this);
              }
          }

          public static void main(String[] args) throws Exception {
              System.out.println(System.getProperty("java.vm.version"));
              Robot r = new Robot();
              generateImages();
              r.delay(1000);
              new Test();
          }
      }


      The behavior is as expected (blue square for HiDPI, green - for the default display resolution).


      Then please merge "image.png" + "image@2x.png" pair using tiffutil and then remove png-files:
      tiffutil -cathidpicheck image.png image@2x.png -out image.tiff
      rm *.png

      Please return to the test code and replace
      "File imageFile = new File(name1x);"
      with
      "File imageFile = new File("image.tiff");"
      and comment out generateImages call in main. No image is drawn when running (as Toolkit.getImage() does not support TIFF for now). JDK9 b77 is used; OS: Mac OS X 10.10.3

      The tiff image is correct and contains two images (checked using macosx Preview).


      The following cocoa code displays the tiff file correctly (blue/green square, depending on is HiDPI emulation id on or off):

      echo '#import <Cocoa/Cocoa.h>
      int main() {
          [NSAutoreleasePool new];
          [NSApplication sharedApplication];
          [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
          id appName = [[NSProcessInfo processInfo] processName];

          id img = [NSImage imageNamed:@"image.tiff"];

          NSRect frame = NSMakeRect(0, 0, 400, 400);
          NSUInteger styleMask = NSTitledWindowMask;
          NSRect rect = [NSWindow contentRectForFrameRect:frame styleMask:styleMask];
          id window = [[NSWindow alloc] initWithContentRect:rect styleMask:styleMask backing:NSBackingStoreBuffered defer:false];

          id imView = [[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)];
          [imView setImage:img];
          [imView setImageScaling:NSImageScaleProportionallyDown];

          [window setContentView:imView];
          [window makeKeyAndOrderFront:nil];
          [window cascadeTopLeftFromPoint:NSMakePoint(20, 20)];
          [window setTitle:appName];
          [NSApp activateIgnoringOtherApps:YES];
          [NSApp run];
          return 0;
      }' | gcc -framework Cocoa -x objective-c -o runTest - ; ./runTest

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bpb Brian Burkhalter
              Reporter:
              avstepan Alexander Stepanov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: