Mercurial > hg > orthanc-wsi
changeset 170:cea9a4701fce
Support of grayscale images
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 02 Aug 2019 15:31:19 +0200 |
parents | de783db2a7c3 |
children | 1390d5c87603 |
files | Framework/ImageToolbox.cpp Framework/Outputs/HierarchicalTiffWriter.cpp NEWS |
diffstat | 3 files changed, 26 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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<Orthanc::ImageAccessor> result(Allocate(source.GetFormat(), + std::auto_ptr<Orthanc::ImageAccessor> 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<uint8_t*>(result->GetRow(y)); + uint8_t* q = reinterpret_cast<uint8_t*>(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(); }
--- 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); }
--- 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)