diff --git a/ChangeLog b/ChangeLog index 2a1959e2c..948116681 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-04-21 Eric Wasylishen + + * Source/tiff.m: + * Source/nsimage-tiff.h: + * Source/NSBitmapImageRep.m: Read DPI metadata in TIFF files and use this + to set the point size of the image rep + 2011-04-20 Eric Wasylishen * Source/NSImage.m (-nativeDrawInRect:...): Make the cache window diff --git a/Source/NSBitmapImageRep.m b/Source/NSBitmapImageRep.m index 9a7e29f06..3afae4139 100644 --- a/Source/NSBitmapImageRep.m +++ b/Source/NSBitmapImageRep.m @@ -1930,6 +1930,13 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width, [_properties setObject: [NSNumber numberWithFloat: _comp_factor] forKey: NSImageCompressionFactor]; + if (info->xdpi > 0 && info->ydpi > 0) + { + NSSize pointSize = NSMakeSize((info->width / info->xdpi) * 72.0, + (info->height / info->ydpi) * 72.0); + [self setSize: pointSize]; + } + if (NSTiffRead(image, info, [self bitmapData])) { free(info); diff --git a/Source/nsimage-tiff.h b/Source/nsimage-tiff.h index 24a32c287..6f3fdd0ce 100644 --- a/Source/nsimage-tiff.h +++ b/Source/nsimage-tiff.h @@ -55,6 +55,8 @@ typedef struct { int quality; /* compression quality (for jpeg) 1 to 255 */ int numImages; /* number of images in tiff */ int error; + float xdpi; + float ydpi; } NSTiffInfo; typedef struct { diff --git a/Source/tiff.m b/Source/tiff.m index 09dc29e21..33067feb9 100644 --- a/Source/tiff.m +++ b/Source/tiff.m @@ -320,6 +320,26 @@ NSTiffGetInfo(int imageNumber, TIFF* image) info->photoInterp == PHOTOMETRIC_RGB ? "RGB" : "min-is-black"); } + { + uint16 resolution_unit; + float xres, yres; + if (TIFFGetField(image, TIFFTAG_XRESOLUTION, &xres) + && TIFFGetField(image, TIFFTAG_YRESOLUTION, &yres)) + { + TIFFGetFieldDefaulted(image, TIFFTAG_RESOLUTIONUNIT, &resolution_unit); + if (resolution_unit == 2) // Inch + { + info->xdpi = xres; + info->ydpi = yres; + } + else if (resolution_unit == 3) // Centimeter + { + info->xdpi = xres * 2.54; + info->ydpi = yres * 2.54; + } + } + } + return info; }