Mercurial > hg > orthanc-wsi
comparison Framework/Inputs/HierarchicalTiff.cpp @ 166:f0dac1e8f736
access to photometric interpretation of source pyramids
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 12 Jul 2019 09:06:54 +0200 |
parents | 6b8ccfc02051 |
children | 11413cc2b9d6 |
comparison
equal
deleted
inserted
replaced
165:8c279c5b28a3 | 166:f0dac1e8f736 |
---|---|
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 | 124 |
125 bool HierarchicalTiff::GetCurrentPixelFormat(Orthanc::PixelFormat& pixelFormat, | 125 bool HierarchicalTiff::GetCurrentPixelFormat(Orthanc::PixelFormat& pixelFormat, |
126 Orthanc::PhotometricInterpretation& photometric, | |
126 ImageCompression compression) | 127 ImageCompression compression) |
127 { | 128 { |
128 // http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html | 129 // http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html |
129 | 130 |
130 uint16_t channels, photometric, bpp, planar; | 131 uint16_t channels, photometricTiff, bpp, planar; |
131 if (!TIFFGetField(tiff_, TIFFTAG_SAMPLESPERPIXEL, &channels) || | 132 if (!TIFFGetField(tiff_, TIFFTAG_SAMPLESPERPIXEL, &channels) || |
132 channels == 0 || | 133 channels == 0 || |
133 !TIFFGetField(tiff_, TIFFTAG_PHOTOMETRIC, &photometric) || | 134 !TIFFGetField(tiff_, TIFFTAG_PHOTOMETRIC, &photometricTiff) || |
134 !TIFFGetField(tiff_, TIFFTAG_BITSPERSAMPLE, &bpp) || | 135 !TIFFGetField(tiff_, TIFFTAG_BITSPERSAMPLE, &bpp) || |
135 !TIFFGetField(tiff_, TIFFTAG_PLANARCONFIG, &planar)) | 136 !TIFFGetField(tiff_, TIFFTAG_PLANARCONFIG, &planar)) |
136 { | 137 { |
137 return false; | 138 return false; |
138 } | 139 } |
139 | 140 |
140 if (compression == ImageCompression_Jpeg && | 141 if (compression == ImageCompression_Jpeg && |
141 channels == 3 && // This is a color image | 142 channels == 3 && // This is a color image |
142 bpp == 8 && | 143 bpp == 8 && |
143 photometric == PHOTOMETRIC_YCBCR && | |
144 planar == PLANARCONFIG_CONTIG) // This is interleaved RGB | 144 planar == PLANARCONFIG_CONTIG) // This is interleaved RGB |
145 { | 145 { |
146 pixelFormat = Orthanc::PixelFormat_RGB24; | 146 pixelFormat = Orthanc::PixelFormat_RGB24; |
147 | |
148 switch (photometricTiff) | |
149 { | |
150 case PHOTOMETRIC_YCBCR: | |
151 photometric = Orthanc::PhotometricInterpretation_YBRFull422; | |
152 return true; | |
153 | |
154 case PHOTOMETRIC_RGB: | |
155 photometric = Orthanc::PhotometricInterpretation_RGB; | |
156 return true; | |
157 | |
158 default: | |
159 LOG(ERROR) << "Unknown photometric interpretation in TIFF: " << photometricTiff; | |
160 return false; | |
161 } | |
147 } | 162 } |
148 else | 163 else |
149 { | 164 { |
150 return false; | 165 return false; |
151 } | 166 } |
162 do | 177 do |
163 { | 178 { |
164 uint32_t w, h, tw, th; | 179 uint32_t w, h, tw, th; |
165 ImageCompression compression; | 180 ImageCompression compression; |
166 Orthanc::PixelFormat pixelFormat; | 181 Orthanc::PixelFormat pixelFormat; |
182 Orthanc::PhotometricInterpretation photometric; | |
167 | 183 |
168 if (TIFFSetDirectory(tiff_, pos) && | 184 if (TIFFSetDirectory(tiff_, pos) && |
169 TIFFGetField(tiff_, TIFFTAG_IMAGEWIDTH, &w) && | 185 TIFFGetField(tiff_, TIFFTAG_IMAGEWIDTH, &w) && |
170 TIFFGetField(tiff_, TIFFTAG_IMAGELENGTH, &h) && | 186 TIFFGetField(tiff_, TIFFTAG_IMAGELENGTH, &h) && |
171 TIFFGetField(tiff_, TIFFTAG_TILEWIDTH, &tw) && | 187 TIFFGetField(tiff_, TIFFTAG_TILEWIDTH, &tw) && |
173 w > 0 && | 189 w > 0 && |
174 h > 0 && | 190 h > 0 && |
175 tw > 0 && | 191 tw > 0 && |
176 th > 0 && | 192 th > 0 && |
177 GetCurrentCompression(compression) && | 193 GetCurrentCompression(compression) && |
178 GetCurrentPixelFormat(pixelFormat, compression)) | 194 GetCurrentPixelFormat(pixelFormat, photometric, compression)) |
179 { | 195 { |
180 if (first) | 196 if (first) |
181 { | 197 { |
182 tileWidth_ = tw; | 198 tileWidth_ = tw; |
183 tileHeight_ = th; | 199 tileHeight_ = th; |
184 compression_ = compression; | 200 compression_ = compression; |
185 pixelFormat_ = pixelFormat; | 201 pixelFormat_ = pixelFormat; |
202 photometric_ = photometric; | |
186 first = false; | 203 first = false; |
187 } | 204 } |
188 else if (tw != tileWidth_ || | 205 else if (tw != tileWidth_ || |
189 th != tileHeight_ || | 206 th != tileHeight_ || |
190 compression_ != compression || | 207 compression_ != compression || |
191 pixelFormat_ != pixelFormat) | 208 pixelFormat_ != pixelFormat || |
209 photometric_ != photometric) | |
192 { | 210 { |
193 LOG(ERROR) << "The tile size or compression of the TIFF file varies along levels, this is not supported"; | 211 LOG(ERROR) << "The tile size or compression of the TIFF file varies along levels, this is not supported"; |
194 return false; | 212 return false; |
195 } | 213 } |
196 | 214 |