# HG changeset patch # User Sebastien Jodogne # Date 1564752679 -7200 # Node ID cea9a4701fce4b41010b4f93608f99ed3e0f47cf # Parent de783db2a7c301d998f0488fa704a0830cb01de1 Support of grayscale images diff -r de783db2a7c3 -r cea9a4701fce Framework/ImageToolbox.cpp --- a/Framework/ImageToolbox.cpp Fri Jul 12 12:53:26 2019 +0200 +++ b/Framework/ImageToolbox.cpp Fri Aug 02 15:31:19 2019 +0200 @@ -326,21 +326,19 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); } - unsigned int channelsCount = source.GetBytesPerPixel(); // OK tx (*) + const unsigned int bytesPerPixel = source.GetBytesPerPixel(); // Corresponds to the number of channels tx (*) - std::auto_ptr result(Allocate(source.GetFormat(), + std::auto_ptr target(Allocate(source.GetFormat(), source.GetWidth() / 2, source.GetHeight() / 2)); - unsigned int bytesPerPixel = source.GetBytesPerPixel(); - - for (unsigned int y = 0; y < source.GetHeight() / 2; y++) + for (unsigned int y = 0; y < target->GetHeight(); y++) { - uint8_t* q = reinterpret_cast(result->GetRow(y)); + uint8_t* q = reinterpret_cast(target->GetRow(y)); - for (unsigned int x = 0; x < source.GetWidth() / 2; x++, q += 3) + for (unsigned int x = 0; x < target->GetWidth(); x++, q += bytesPerPixel) { - for (unsigned int c = 0; c < channelsCount; c++) + for (unsigned int c = 0; c < bytesPerPixel; c++) { if (smooth) { @@ -354,7 +352,7 @@ } } - return result.release(); + return target.release(); } diff -r de783db2a7c3 -r cea9a4701fce Framework/Outputs/HierarchicalTiffWriter.cpp --- a/Framework/Outputs/HierarchicalTiffWriter.cpp Fri Jul 12 12:53:26 2019 +0200 +++ b/Framework/Outputs/HierarchicalTiffWriter.cpp Fri Aug 02 15:31:19 2019 +0200 @@ -160,7 +160,7 @@ switch (pixelFormat) { case Orthanc::PixelFormat_Grayscale8: - if (numberOfComponents != 3) + if (numberOfComponents != 1) { LOG(WARNING) << "The source image does not contain a grayscale image as expected"; } @@ -302,6 +302,23 @@ break; } + case Orthanc::PixelFormat_Grayscale8: + { + uint16_t samplesPerPixel = 1; + uint16_t bpp = 8; + uint16_t photometric = PHOTOMETRIC_MINISBLACK; + + if (TIFFSetField(tiff_, TIFFTAG_SAMPLESPERPIXEL, samplesPerPixel) != 1 || + TIFFSetField(tiff_, TIFFTAG_PHOTOMETRIC, photometric) != 1 || + TIFFSetField(tiff_, TIFFTAG_BITSPERSAMPLE, bpp) != 1) + { + Close(); + throw Orthanc::OrthancException(Orthanc::ErrorCode_CannotWriteFile); + } + + break; + } + default: throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); } diff -r de783db2a7c3 -r cea9a4701fce NEWS --- a/NEWS Fri Jul 12 12:53:26 2019 +0200 +++ b/NEWS Fri Aug 02 15:31:19 2019 +0200 @@ -2,6 +2,7 @@ =============================== * Improved consistency when transcoding/re-encoding is applied +* Support of grayscale images * Fix issue #139 (OrthancWSIDicomizer PixelSpacing) * Fix issue #144 (OrthancWSIDicomizer PhotometricInterpretation)