comparison Framework/Inputs/HierarchicalTiff.cpp @ 296:559499b80da8

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Jul 2023 06:45:44 +0200
parents 20a730889ae2
children c1687b8fc800
comparison
equal deleted inserted replaced
295:92b88fa3e631 296:559499b80da8
97 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 97 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
98 } 98 }
99 } 99 }
100 100
101 101
102 bool HierarchicalTiff::GetCurrentCompression(ImageCompression& compression) 102 bool HierarchicalTiff::GetCurrentDirectoryInformation(TIFF* tiff,
103 ImageCompression& compression,
104 Orthanc::PixelFormat& pixelFormat,
105 Orthanc::PhotometricInterpretation& photometric)
103 { 106 {
104 uint16_t c; 107 uint16_t c;
105 if (!TIFFGetField(tiff_, TIFFTAG_COMPRESSION, &c)) 108 if (!TIFFGetField(tiff, TIFFTAG_COMPRESSION, &c))
106 { 109 {
107 return false; 110 return false;
108 } 111 }
109 112
110 switch (c) 113 switch (c)
111 { 114 {
112 case COMPRESSION_NONE: 115 case COMPRESSION_NONE:
113 compression = ImageCompression_None; 116 compression = ImageCompression_None;
114 return true; 117 break;
115 118
116 case COMPRESSION_JPEG: 119 case COMPRESSION_JPEG:
117 compression = ImageCompression_Jpeg; 120 compression = ImageCompression_Jpeg;
118 return true; 121 break;
119 122
120 default: 123 default:
121 return false; 124 return false;
122 } 125 }
123 } 126
124
125
126 bool HierarchicalTiff::GetCurrentPixelFormat(Orthanc::PixelFormat& pixelFormat,
127 Orthanc::PhotometricInterpretation& photometric,
128 ImageCompression compression)
129 {
130 // http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html 127 // http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
131 128
132 uint16_t channels, photometricTiff, bpp, planar; 129 uint16_t channels, photometricTiff, bpp, planar;
133 if (!TIFFGetField(tiff_, TIFFTAG_SAMPLESPERPIXEL, &channels) || 130 if (!TIFFGetField(tiff, TIFFTAG_SAMPLESPERPIXEL, &channels) ||
134 channels == 0 || 131 channels == 0 ||
135 !TIFFGetField(tiff_, TIFFTAG_PHOTOMETRIC, &photometricTiff) || 132 !TIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &photometricTiff) ||
136 !TIFFGetField(tiff_, TIFFTAG_BITSPERSAMPLE, &bpp) || 133 !TIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &bpp) ||
137 !TIFFGetField(tiff_, TIFFTAG_PLANARCONFIG, &planar)) 134 !TIFFGetField(tiff, TIFFTAG_PLANARCONFIG, &planar))
138 { 135 {
139 return false; 136 return false;
140 } 137 }
141 138
142 if (compression == ImageCompression_Jpeg && 139 if (compression == ImageCompression_Jpeg &&
158 155
159 default: 156 default:
160 LOG(ERROR) << "Unknown photometric interpretation in TIFF: " << photometricTiff; 157 LOG(ERROR) << "Unknown photometric interpretation in TIFF: " << photometricTiff;
161 return false; 158 return false;
162 } 159 }
160 }
161 else if (compression == ImageCompression_None &&
162 channels == 3 && // This is a color image
163 bpp == 8 &&
164 planar == PLANARCONFIG_CONTIG) // This is interleaved RGB
165 {
166 pixelFormat = Orthanc::PixelFormat_RGB24;
167 photometric = Orthanc::PhotometricInterpretation_RGB;
168 return true;
163 } 169 }
164 else if (compression == ImageCompression_Jpeg && 170 else if (compression == ImageCompression_Jpeg &&
165 channels == 1 && // This is a grayscale image 171 channels == 1 && // This is a grayscale image
166 bpp == 8) 172 bpp == 8)
167 { 173 {
196 TIFFGetField(tiff_, TIFFTAG_TILELENGTH, &th) && 202 TIFFGetField(tiff_, TIFFTAG_TILELENGTH, &th) &&
197 w > 0 && 203 w > 0 &&
198 h > 0 && 204 h > 0 &&
199 tw > 0 && 205 tw > 0 &&
200 th > 0 && 206 th > 0 &&
201 GetCurrentCompression(compression) && 207 GetCurrentDirectoryInformation(tiff_, compression, pixelFormat, photometric))
202 GetCurrentPixelFormat(pixelFormat, photometric, compression))
203 { 208 {
204 if (first) 209 if (first)
205 { 210 {
206 tileWidth_ = tw; 211 tileWidth_ = tw;
207 tileHeight_ = th; 212 tileHeight_ = th;