2012.01.09 01:53 "[Tiff] resolution issue when converting jpeg to tiff", by Jingfei Hu

2012.01.09 03:57 "Re: [Tiff] resolution issue when converting jpeg to tiff", by Bob Friesenhahn

Then, I use libjpeg library to read these files. I need to convert these jpeg files into tiff files. I get the x-resolution and y-resolution using libexif(because libjpeg doesn't support this), says 72 dpi, and I use TIFFSetField to set the corresponding field of the tiff to be generated with no error occurred. But the x-resolution is 96dpi when I look up the property of the generated tiff using Windows Property(Right click on the tiff ->Property).

JPEG and libjpeg do support storing image resolution without using
EXIF. This is the code from GraphicsMagick which retrieves it:

if (jpeg_info.saw_JFIF_marker)
  {
    if ((jpeg_info.X_density != 1U) && (jpeg_info.Y_density != 1U))
      {
        /*
          Set image resolution.
        */
        image->x_resolution=jpeg_info.X_density;
        image->y_resolution=jpeg_info.Y_density;
        if (jpeg_info.density_unit == 1)
          image->units=PixelsPerInchResolution;
        if (jpeg_info.density_unit == 2)
          image->units=PixelsPerCentimeterResolution;
      }
  }

You did not show any code for how you set the resolution in the TIFF.
This is the code that GraphicsMagick uses to set the resolution:

{
      unsigned short
        units;

/*
  Set image resolution.
*/
units=RESUNIT_NONE;
if (image->units == PixelsPerInchResolution)
  units=RESUNIT_INCH;
if (image->units == PixelsPerCentimeterResolution)
  units=RESUNIT_CENTIMETER;

(void) TIFFSetField(tiff,TIFFTAG_RESOLUTIONUNIT,(uint16) units);

(void) TIFFSetField(tiff,TIFFTAG_XRESOLUTION,image->x_resolution);

(void) TIFFSetField(tiff,TIFFTAG_YRESOLUTION,image->y_resolution);

}

When I use the utility of libtiff, tiffinfo.exe, to look the information of generated tiff files, it returns (0,0) pixels/inch.

Perhaps you passed wrong data or used libtiff incorrectly. Can you
show us the code you used?

When I open this generated tiff files with Photoshop CS5, it says 72 dpi in image size dialog (opened with Ctrl+Alt+I).

The 72 DPI is likely a default value.

I just doesn't know the reason. Is there a method to set the resolution so that tiffinfo could recognize the resolution correctly.

Yes, there is a method.

The libtiff version you are using (3.8.2) is very old.

Bob
--
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/