Mercurial > hg > orthanc
changeset 4080:f18eaade6153
simplification in ImageProcessing::ShiftScale()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 22 Jun 2020 19:04:09 +0200 |
parents | 73c22208272f |
children | 259c33759937 2e1564f57542 |
files | Core/Images/ImageProcessing.cpp |
diffstat | 1 files changed, 34 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Images/ImageProcessing.cpp Mon Jun 22 18:59:45 2020 +0200 +++ b/Core/Images/ImageProcessing.cpp Mon Jun 22 19:04:09 2020 +0200 @@ -386,7 +386,8 @@ // Computes "a * x + b" at each pixel => Note that this is not the - // same convention as in "ShiftScale()" + // same convention as in "ShiftScale()", but it is the convention of + // "ShiftScale2()" template <typename TargetType, typename SourceType, bool UseRound, @@ -1367,15 +1368,14 @@ } - void ImageProcessing::ShiftScale(ImageAccessor& image, - float offset, - float scaling, - bool useRound) + void ImageProcessing::ShiftScale2(ImageAccessor& image, + float offset, + float scaling, + bool useRound) { - // Rewrite "(x + offset) * scaling" as "a * x + b" - + // We compute "a * x + b" const float a = scaling; - const float b = offset * scaling; + const float b = offset; switch (image.GetFormat()) { @@ -1430,16 +1430,15 @@ } - void ImageProcessing::ShiftScale(ImageAccessor& target, - const ImageAccessor& source, - float offset, - float scaling, - bool useRound) + void ImageProcessing::ShiftScale2(ImageAccessor& target, + const ImageAccessor& source, + float offset, + float scaling, + bool useRound) { - // Rewrite "(x + offset) * scaling" as "a * x + b" - + // We compute "a * x + b" const float a = scaling; - const float b = offset * scaling; + const float b = offset; switch (target.GetFormat()) { @@ -1470,36 +1469,30 @@ } - void ImageProcessing::ShiftScale2(ImageAccessor& image, - float offset, - float scaling, - bool useRound) + void ImageProcessing::ShiftScale(ImageAccessor& image, + float offset, + float scaling, + bool useRound) { - if (std::abs(scaling) < 0.001f) - { - Set(image, offset); - } - else - { - ShiftScale(image, offset / scaling, scaling, useRound); - } + // Rewrite "(x + offset) * scaling" as "a * x + b" + + const float a = scaling; + const float b = offset * scaling; + ShiftScale2(image, b, a, useRound); } - void ImageProcessing::ShiftScale2(ImageAccessor& target, - const ImageAccessor& source, - float offset, - float scaling, - bool useRound) + void ImageProcessing::ShiftScale(ImageAccessor& target, + const ImageAccessor& source, + float offset, + float scaling, + bool useRound) { - if (std::abs(scaling) < 0.0001f) - { - Set(target, offset); - } - else - { - ShiftScale(target, source, offset / scaling, scaling, useRound); - } + // Rewrite "(x + offset) * scaling" as "a * x + b" + + const float a = scaling; + const float b = offset * scaling; + ShiftScale2(target, source, b, a, useRound); }