# HG changeset patch # User Sebastien Jodogne # Date 1520956950 -3600 # Node ID 345725b9350c236b99b4752e08b377f01cf1994d # Parent be1dbb1dcdd6cd7adbb52029ef39c9ffa7349488 back to rounding to fix integration tests diff -r be1dbb1dcdd6 -r 345725b9350c Core/DicomParsing/Internals/DicomImageDecoder.cpp --- a/Core/DicomParsing/Internals/DicomImageDecoder.cpp Tue Mar 13 16:29:20 2018 +0100 +++ b/Core/DicomParsing/Internals/DicomImageDecoder.cpp Tue Mar 13 17:02:30 2018 +0100 @@ -881,7 +881,8 @@ else { ImageProcessing::ShiftScale(*image, static_cast(-a), - 255.0f / static_cast(b - a)); + 255.0f / static_cast(b - a), + true /* TODO - Consider using "false" to speed up */); } // If the source image is not grayscale 8bpp, convert it diff -r be1dbb1dcdd6 -r 345725b9350c Core/Images/ImageProcessing.cpp --- a/Core/Images/ImageProcessing.cpp Tue Mar 13 16:29:20 2018 +0100 +++ b/Core/Images/ImageProcessing.cpp Tue Mar 13 17:02:30 2018 +0100 @@ -227,7 +227,8 @@ - template + template void MultiplyConstantInternal(ImageAccessor& image, float factor) { @@ -246,11 +247,16 @@ for (unsigned int x = 0; x < width; x++, p++) { - // The "round" operation is extremely costly. We use - // truncation instead since Orthanc 1.3.2. - - //int64_t v = boost::math::llround(static_cast(*p) * factor); - int64_t v = static_cast(static_cast(*p) * factor); + int64_t v; + if (UseRound) + { + // The "round" operation is very costly + v = boost::math::llround(static_cast(*p) * factor); + } + else + { + v = static_cast(static_cast(*p) * factor); + } if (v > maxValue) { @@ -269,7 +275,8 @@ } - template + template void ShiftScaleInternal(ImageAccessor& image, float offset, float scaling) @@ -298,12 +305,13 @@ { *p = minPixelValue; } + else if (UseRound) + { + // The "round" operation is very costly + *p = static_cast(boost::math::iround(v)); + } else { - // The "round" operation is extremely costly. We use - // truncation instead since Orthanc 1.3.2. - - //*p = static_cast(boost::math::iround(v)); *p = static_cast(v); } } @@ -806,20 +814,42 @@ void ImageProcessing::MultiplyConstant(ImageAccessor& image, - float factor) + float factor, + bool useRound) { switch (image.GetFormat()) { case PixelFormat_Grayscale8: - MultiplyConstantInternal(image, factor); + if (useRound) + { + MultiplyConstantInternal(image, factor); + } + else + { + MultiplyConstantInternal(image, factor); + } return; case PixelFormat_Grayscale16: - MultiplyConstantInternal(image, factor); + if (useRound) + { + MultiplyConstantInternal(image, factor); + } + else + { + MultiplyConstantInternal(image, factor); + } return; case PixelFormat_SignedGrayscale16: - MultiplyConstantInternal(image, factor); + if (useRound) + { + MultiplyConstantInternal(image, factor); + } + else + { + MultiplyConstantInternal(image, factor); + } return; default: @@ -830,20 +860,42 @@ void ImageProcessing::ShiftScale(ImageAccessor& image, float offset, - float scaling) + float scaling, + bool useRound) { switch (image.GetFormat()) { case PixelFormat_Grayscale8: - ShiftScaleInternal(image, offset, scaling); + if (useRound) + { + ShiftScaleInternal(image, offset, scaling); + } + else + { + ShiftScaleInternal(image, offset, scaling); + } return; case PixelFormat_Grayscale16: - ShiftScaleInternal(image, offset, scaling); + if (useRound) + { + ShiftScaleInternal(image, offset, scaling); + } + else + { + ShiftScaleInternal(image, offset, scaling); + } return; case PixelFormat_SignedGrayscale16: - ShiftScaleInternal(image, offset, scaling); + if (useRound) + { + ShiftScaleInternal(image, offset, scaling); + } + else + { + ShiftScaleInternal(image, offset, scaling); + } return; default: diff -r be1dbb1dcdd6 -r 345725b9350c Core/Images/ImageProcessing.h --- a/Core/Images/ImageProcessing.h Tue Mar 13 16:29:20 2018 +0100 +++ b/Core/Images/ImageProcessing.h Tue Mar 13 17:02:30 2018 +0100 @@ -71,12 +71,16 @@ static void AddConstant(ImageAccessor& image, int64_t value); + // "useRound" is expensive static void MultiplyConstant(ImageAccessor& image, - float factor); + float factor, + bool useRound); + // "useRound" is expensive static void ShiftScale(ImageAccessor& image, float offset, - float scaling); + float scaling, + bool useRound); static void Invert(ImageAccessor& image); };