# HG changeset patch # User Sebastien Jodogne # Date 1463226102 -7200 # Node ID e2a3ff770b480ac91e3bbabb874643df1dbf3b5f # Parent 9161e3ef0d175d3f21f2334c88974fcd55f7a64d introducing float32 images diff -r 9161e3ef0d17 -r e2a3ff770b48 Core/Enumerations.cpp --- a/Core/Enumerations.cpp Mon May 09 17:56:32 2016 +0200 +++ b/Core/Enumerations.cpp Sat May 14 13:41:42 2016 +0200 @@ -37,6 +37,7 @@ #include "Toolbox.h" #include +#include namespace Orthanc { @@ -740,6 +741,9 @@ case PixelFormat_SignedGrayscale16: return "Grayscale (signed 16bpp)"; + case PixelFormat_Float32: + return "Grayscale (float 32bpp)"; + default: throw OrthancException(ErrorCode_ParameterOutOfRange); } @@ -913,6 +917,10 @@ case PixelFormat_RGBA32: return 4; + case PixelFormat_Float32: + assert(sizeof(float) == 4); + return 4; + default: throw OrthancException(ErrorCode_ParameterOutOfRange); } diff -r 9161e3ef0d17 -r e2a3ff770b48 Core/Enumerations.h --- a/Core/Enumerations.h Mon May 09 17:56:32 2016 +0200 +++ b/Core/Enumerations.h Sat May 14 13:41:42 2016 +0200 @@ -187,7 +187,13 @@ * {summary}{Graylevel, signed 16bpp image.} * {description}{The image is graylevel. Each pixel is signed and stored in two bytes.} **/ - PixelFormat_SignedGrayscale16 = 5 + PixelFormat_SignedGrayscale16 = 5, + + /** + * {summary}{Graylevel, floating-point image.} + * {description}{The image is graylevel. Each pixel is floating-point and stored in 4 bytes.} + **/ + PixelFormat_Float32 = 6 }; diff -r 9161e3ef0d17 -r e2a3ff770b48 Core/Images/ImageAccessor.cpp --- a/Core/Images/ImageAccessor.cpp Mon May 09 17:56:32 2016 +0200 +++ b/Core/Images/ImageAccessor.cpp Sat May 14 13:41:42 2016 +0200 @@ -65,7 +65,7 @@ for (unsigned int x = 0; x < source.GetWidth(); x++, p++) { - s += boost::lexical_cast(static_cast(*p)) + " "; + s += boost::lexical_cast(static_cast(*p)) + " "; } target.AddChunk(s); @@ -221,6 +221,10 @@ ToMatlabStringInternal(buffer, *this); break; + case PixelFormat_Float32: + ToMatlabStringInternal(buffer, *this); + break; + case PixelFormat_RGB24: RGB24ToMatlabString(buffer, *this); break; diff -r 9161e3ef0d17 -r e2a3ff770b48 Core/Images/ImageProcessing.cpp --- a/Core/Images/ImageProcessing.cpp Mon May 09 17:56:32 2016 +0200 +++ b/Core/Images/ImageProcessing.cpp Sat May 14 13:41:42 2016 +0200 @@ -75,9 +75,26 @@ } + template + static void ConvertGrayscaleToFloat(ImageAccessor& target, + const ImageAccessor& source) + { + for (unsigned int y = 0; y < source.GetHeight(); y++) + { + float* t = reinterpret_cast(target.GetRow(y)); + const SourceType* s = reinterpret_cast(source.GetConstRow(y)); + + for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++) + { + *t = static_cast(*s); + } + } + } + + template static void ConvertColorToGrayscale(ImageAccessor& target, - const ImageAccessor& source) + const ImageAccessor& source) { assert(source.GetFormat() == PixelFormat_RGB24); @@ -378,6 +395,27 @@ return; } + if (target.GetFormat() == PixelFormat_Float32 && + source.GetFormat() == PixelFormat_Grayscale8) + { + ConvertGrayscaleToFloat(target, source); + return; + } + + if (target.GetFormat() == PixelFormat_Float32 && + source.GetFormat() == PixelFormat_Grayscale16) + { + ConvertGrayscaleToFloat(target, source); + return; + } + + if (target.GetFormat() == PixelFormat_Float32 && + source.GetFormat() == PixelFormat_SignedGrayscale16) + { + ConvertGrayscaleToFloat(target, source); + return; + } + if (target.GetFormat() == PixelFormat_Grayscale8 && source.GetFormat() == PixelFormat_RGBA32) {