From d84bb82e442d57abe65d83c31f56b323e6afb4df Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Tue, 20 Oct 2020 21:28:10 -0700 Subject: [PATCH] Merge duplicated implementations of toLinear(). --- filament/backend/test/test_ReadPixels.cpp | 15 --------------- libs/image/include/image/ColorTransform.h | 15 +++++++++++++++ libs/viewer/src/AutomationEngine.cpp | 15 --------------- samples/frame_generator.cpp | 15 --------------- 4 files changed, 15 insertions(+), 45 deletions(-) diff --git a/filament/backend/test/test_ReadPixels.cpp b/filament/backend/test/test_ReadPixels.cpp index 57a79b3644..cdf9a38a52 100644 --- a/filament/backend/test/test_ReadPixels.cpp +++ b/filament/backend/test/test_ReadPixels.cpp @@ -33,21 +33,6 @@ using namespace image; namespace { -template -static LinearImage toLinear(size_t w, size_t h, size_t bpr, const uint8_t* src) { - LinearImage result(w, h, 4); - math::float4* d = reinterpret_cast(result.getPixelRef(0, 0)); - for (size_t y = 0; y < h; ++y) { - T const* p = reinterpret_cast(src + y * bpr); - for (size_t x = 0; x < w; ++x, p += 4) { - math::float3 sRGB(p[0], p[1], p[2]); - sRGB /= std::numeric_limits::max(); - *d++ = math::float4(sRGBToLinear(sRGB), 1.0f); - } - } - return result; -} - //////////////////////////////////////////////////////////////////////////////////////////////////// // Shaders //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/libs/image/include/image/ColorTransform.h b/libs/image/include/image/ColorTransform.h index 15e2658f02..61ebaed86a 100644 --- a/libs/image/include/image/ColorTransform.h +++ b/libs/image/include/image/ColorTransform.h @@ -346,6 +346,21 @@ inline LinearImage fromLinearToRGBM(const LinearImage& image) { return result; } +template +static LinearImage toLinear(size_t w, size_t h, size_t bpr, const uint8_t* src) { + LinearImage result(w, h, 4); + filament::math::float4* d = reinterpret_cast(result.getPixelRef(0, 0)); + for (size_t y = 0; y < h; ++y) { + T const* p = reinterpret_cast(src + y * bpr); + for (size_t x = 0; x < w; ++x, p += 4) { + filament::math::float3 sRGB(p[0], p[1], p[2]); + sRGB /= std::numeric_limits::max(); + *d++ = filament::math::float4(sRGBToLinear(sRGB), 1.0f); + } + } + return result; +} + } // namespace Image #endif // IMAGE_COLORTRANSFORM_H_ diff --git a/libs/viewer/src/AutomationEngine.cpp b/libs/viewer/src/AutomationEngine.cpp index 87a143be66..b314b04b2c 100644 --- a/libs/viewer/src/AutomationEngine.cpp +++ b/libs/viewer/src/AutomationEngine.cpp @@ -40,21 +40,6 @@ namespace viewer { static std::string gStatus; -template -static LinearImage toLinear(size_t w, size_t h, size_t bpr, const uint8_t* src) { - LinearImage result(w, h, 3); - filament::math::float3* d = reinterpret_cast(result.getPixelRef(0, 0)); - for (size_t y = 0; y < h; ++y) { - T const* p = reinterpret_cast(src + y * bpr); - for (size_t x = 0; x < w; ++x, p += 3) { - filament::math::float3 sRGB(p[0], p[1], p[2]); - sRGB /= std::numeric_limits::max(); - *d++ = sRGBToLinear(sRGB); - } - } - return result; -} - struct ScreenshotState { View* view; std::string filename; diff --git a/samples/frame_generator.cpp b/samples/frame_generator.cpp index 09335a5ec7..a6a2164fbc 100644 --- a/samples/frame_generator.cpp +++ b/samples/frame_generator.cpp @@ -345,21 +345,6 @@ static void setup(Engine* engine, View* view, Scene* scene) { } } -template -static LinearImage toLinear(size_t w, size_t h, size_t bpr, const uint8_t* src) { - LinearImage result(w, h, 3); - filament::math::float3* d = reinterpret_cast(result.getPixelRef(0, 0)); - for (size_t y = 0; y < h; ++y) { - T const* p = reinterpret_cast(src + y * bpr); - for (size_t x = 0; x < w; ++x, p += 3) { - filament::math::float3 sRGB(p[0], p[1], p[2]); - sRGB /= std::numeric_limits::max(); - *d++ = sRGBToLinear(sRGB); - } - } - return result; -} - static void render(Engine*, View*, Scene*, Renderer*) { int frame = g_currentFrame - FRAME_TO_SKIP - 1; if (frame >= 0 && frame < g_materialVariantCount) {