Changeset 7237


Ignore:
Timestamp:
11/23/10 16:50:08 (10 years ago)
Author:
melissa
Message:

Preserve physical pixel sizes when writing vanilla TIFF files.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2/components/bio-formats/src/loci/formats/out/TiffWriter.java

    r7155 r7237  
    3838import loci.formats.tiff.TiffCompression; 
    3939import loci.formats.tiff.TiffParser; 
     40import loci.formats.tiff.TiffRational; 
    4041import loci.formats.tiff.TiffSaver; 
    4142 
     
    183184    ifd.put(new Integer(IFD.IMAGE_LENGTH), new Integer(height)); 
    184185 
     186    Double physicalSizeX = retrieve.getPixelsPhysicalSizeX(series); 
     187    if (physicalSizeX == null) physicalSizeX = 0d; 
     188    else physicalSizeX = 1d / physicalSizeX; 
     189    Double physicalSizeY = retrieve.getPixelsPhysicalSizeY(series); 
     190    if (physicalSizeY == null) physicalSizeY = 0d; 
     191    else physicalSizeY = 1d / physicalSizeY; 
     192 
     193    ifd.put(IFD.RESOLUTION_UNIT, 3); 
     194    ifd.put(IFD.X_RESOLUTION, 
     195      new TiffRational((long) (physicalSizeX * 1000 * 10000), 1000)); 
     196    ifd.put(IFD.Y_RESOLUTION, 
     197      new TiffRational((long) (physicalSizeY * 1000 * 10000), 1000)); 
     198 
    185199    if (!isBigTiff) { 
    186200      isBigTiff = (out.length() + 2 * plane) >= 4294967296L; 
  • trunk/components/bio-formats/src/loci/formats/out/TiffWriter.java

    r7226 r7237  
    3838import loci.formats.tiff.TiffCompression; 
    3939import loci.formats.tiff.TiffParser; 
     40import loci.formats.tiff.TiffRational; 
    4041import loci.formats.tiff.TiffSaver; 
    4142 
     
    183184    ifd.put(new Integer(IFD.IMAGE_LENGTH), new Integer(height)); 
    184185 
     186    Double physicalSizeX = retrieve.getPixelsPhysicalSizeX(series); 
     187    if (physicalSizeX == null) physicalSizeX = 0d; 
     188    else physicalSizeX = 1d / physicalSizeX; 
     189    Double physicalSizeY = retrieve.getPixelsPhysicalSizeY(series); 
     190    if (physicalSizeY == null) physicalSizeY = 0d; 
     191    else physicalSizeY = 1d / physicalSizeY; 
     192 
     193    ifd.put(IFD.RESOLUTION_UNIT, 3); 
     194    ifd.put(IFD.X_RESOLUTION, 
     195      new TiffRational((long) (physicalSizeX * 1000 * 10000), 1000)); 
     196    ifd.put(IFD.Y_RESOLUTION, 
     197      new TiffRational((long) (physicalSizeY * 1000 * 10000), 1000)); 
     198 
    185199    if (!isBigTiff) { 
    186200      isBigTiff = (out.length() + 2 * plane) >= 4294967296L; 
Note: See TracChangeset for help on using the changeset viewer.