From 3be10d816a9e8eff7fbceabd9a5e221605cdcaf6 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Tue, 8 Jan 2019 07:20:20 -0800 Subject: [PATCH] Cleanup recent change to ImageOps (#678) * Cleanup recent change to ImageOps * Add missing sign --- libs/image/src/ImageOps.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/libs/image/src/ImageOps.cpp b/libs/image/src/ImageOps.cpp index 36da604961..3287f12d14 100644 --- a/libs/image/src/ImageOps.cpp +++ b/libs/image/src/ImageOps.cpp @@ -119,20 +119,15 @@ LinearImage verticalFlip(const LinearImage& image) { return result; } -template , - class Offset = std::ratio<1, 1>> -LinearImage applyScaleOffset(const LinearImage& image) { +template +LinearImage applyScaleOffset(const LinearImage& image, + typename VecT::value_type scale, typename VecT::value_type offset) { const uint32_t width = image.getWidth(), height = image.getHeight(); LinearImage result(width, height, image.getChannels()); auto src = (VecT const*) image.getPixelRef(); auto dst = (VecT*) result.getPixelRef(); - constexpr float scale_f = - static_cast(Scale::num) / static_cast(Scale::den); - constexpr float offset_f = - static_cast(Offset::num) / static_cast(Offset::den); for (uint32_t n = 0, end = width * height; n < end; ++n) { - dst[n] = scale_f * src[n] + VecT(offset_f); + dst[n] = scale * src[n] + VecT{offset}; } return result; } @@ -141,16 +136,16 @@ LinearImage vectorsToColors(const LinearImage& image) { ASSERT_PRECONDITION(image.getChannels() == 3 || image.getChannels() == 4, "Must be a 3 or 4 channel image"); return image.getChannels() == 3 - ? applyScaleOffset, std::ratio<1, 2>>(image) - : applyScaleOffset, std::ratio<1, 2>>(image); + ? applyScaleOffset(image, 0.5f, 0.5f) + : applyScaleOffset(image, 0.5f, 0.5f); } LinearImage colorsToVectors(const LinearImage& image) { ASSERT_PRECONDITION(image.getChannels() == 3 || image.getChannels() == 4, "Must be a 3 or 4 channel image"); return image.getChannels() == 3 - ? applyScaleOffset, std::ratio<-1, 1>>(image) - : applyScaleOffset, std::ratio<-1, 1>>(image); + ? applyScaleOffset(image, 2.0f, -1.0f) + : applyScaleOffset(image, 2.0f, -1.0f); } LinearImage extractChannel(const LinearImage& source, uint32_t channel) {