diff --git a/filament/backend/test/test_ReadPixels.cpp b/filament/backend/test/test_ReadPixels.cpp index 59b947b924..837e62e263 100644 --- a/filament/backend/test/test_ReadPixels.cpp +++ b/filament/backend/test/test_ReadPixels.cpp @@ -129,7 +129,7 @@ TEST_F(BackendTest, ReadPixels) { const size_t width = readRect.width, height = readRect.height; LinearImage image(width, height, 4); if (format == PixelDataFormat::RGBA && type == PixelDataType::UBYTE) { - image = toLinear(width, height, width * 4, (uint8_t*) pixelData); + image = toLinearWithAlpha(width, height, width * 4, (uint8_t*) pixelData); } if (format == PixelDataFormat::RGBA && type == PixelDataType::FLOAT) { memcpy(image.getPixelRef(), pixelData, width * height * sizeof(math::float4)); diff --git a/libs/image/include/image/ColorTransform.h b/libs/image/include/image/ColorTransform.h index 61ebaed86a..334c21b014 100644 --- a/libs/image/include/image/ColorTransform.h +++ b/libs/image/include/image/ColorTransform.h @@ -347,7 +347,7 @@ inline LinearImage fromLinearToRGBM(const LinearImage& image) { } template -static LinearImage toLinear(size_t w, size_t h, size_t bpr, const uint8_t* src) { +static LinearImage toLinearWithAlpha(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) { @@ -361,6 +361,21 @@ static LinearImage toLinear(size_t w, size_t h, size_t bpr, const uint8_t* src) return result; } +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; +} + } // namespace Image #endif // IMAGE_COLORTRANSFORM_H_