comparison Framework/Outputs/HierarchicalTiffWriter.cpp @ 170:cea9a4701fce

Support of grayscale images
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 Aug 2019 15:31:19 +0200
parents 605247fc8758
children e3cbf890b588
comparison
equal deleted inserted replaced
169:de783db2a7c3 170:cea9a4701fce
158 uint8_t numberOfComponents = GetUint8(tile, i + 9); 158 uint8_t numberOfComponents = GetUint8(tile, i + 9);
159 159
160 switch (pixelFormat) 160 switch (pixelFormat)
161 { 161 {
162 case Orthanc::PixelFormat_Grayscale8: 162 case Orthanc::PixelFormat_Grayscale8:
163 if (numberOfComponents != 3) 163 if (numberOfComponents != 1)
164 { 164 {
165 LOG(WARNING) << "The source image does not contain a grayscale image as expected"; 165 LOG(WARNING) << "The source image does not contain a grayscale image as expected";
166 } 166 }
167 break; 167 break;
168 168
292 if (TIFFSetField(tiff_, TIFFTAG_SAMPLESPERPIXEL, samplesPerPixel) != 1 || 292 if (TIFFSetField(tiff_, TIFFTAG_SAMPLESPERPIXEL, samplesPerPixel) != 1 ||
293 TIFFSetField(tiff_, TIFFTAG_PHOTOMETRIC, photometric) != 1 || 293 TIFFSetField(tiff_, TIFFTAG_PHOTOMETRIC, photometric) != 1 ||
294 TIFFSetField(tiff_, TIFFTAG_BITSPERSAMPLE, bpp) != 1 || 294 TIFFSetField(tiff_, TIFFTAG_BITSPERSAMPLE, bpp) != 1 ||
295 TIFFSetField(tiff_, TIFFTAG_PLANARCONFIG, planar) != 1 || 295 TIFFSetField(tiff_, TIFFTAG_PLANARCONFIG, planar) != 1 ||
296 TIFFSetField(tiff_, TIFFTAG_YCBCRSUBSAMPLING, subsampleHorizontal, subsampleVertical) != 1) 296 TIFFSetField(tiff_, TIFFTAG_YCBCRSUBSAMPLING, subsampleHorizontal, subsampleVertical) != 1)
297 {
298 Close();
299 throw Orthanc::OrthancException(Orthanc::ErrorCode_CannotWriteFile);
300 }
301
302 break;
303 }
304
305 case Orthanc::PixelFormat_Grayscale8:
306 {
307 uint16_t samplesPerPixel = 1;
308 uint16_t bpp = 8;
309 uint16_t photometric = PHOTOMETRIC_MINISBLACK;
310
311 if (TIFFSetField(tiff_, TIFFTAG_SAMPLESPERPIXEL, samplesPerPixel) != 1 ||
312 TIFFSetField(tiff_, TIFFTAG_PHOTOMETRIC, photometric) != 1 ||
313 TIFFSetField(tiff_, TIFFTAG_BITSPERSAMPLE, bpp) != 1)
297 { 314 {
298 Close(); 315 Close();
299 throw Orthanc::OrthancException(Orthanc::ErrorCode_CannotWriteFile); 316 throw Orthanc::OrthancException(Orthanc::ErrorCode_CannotWriteFile);
300 } 317 }
301 318