From 48a89eced5b8cb365ca66ebc6d5b27f705e72c84 Mon Sep 17 00:00:00 2001 From: Jan Herling Date: Thu, 26 Dec 2024 18:52:54 -0800 Subject: [PATCH] Switching to FORMAT_F32 pixel format in Pfm image loader in case of a one channel image Summary: Previously, we used a generic pixel format (`float` with 1 channel) when loading a 1 channel pfm image. However, we can be more specific as Ocean has a dedicated pixel format for this image type - thus switching. Differential Revision: D67652479 fbshipit-source-id: 05d7ac02b6affb86a0bdbb0b1b56d78fe34fda06 --- impl/ocean/media/special/ImagePfm.cpp | 6 +++--- impl/ocean/test/testmedia/TestSpecial.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/impl/ocean/media/special/ImagePfm.cpp b/impl/ocean/media/special/ImagePfm.cpp index 539c9d759..f5db95691 100644 --- a/impl/ocean/media/special/ImagePfm.cpp +++ b/impl/ocean/media/special/ImagePfm.cpp @@ -66,11 +66,11 @@ bool ImagePfm::encodeImage(const Frame& frame, std::vector& buffer) std::string header; - if (FrameType::arePixelFormatsCompatible(frame.pixelFormat(), FrameType::genericPixelFormat())) + if (frame.isPixelFormatCompatible(FrameType::FORMAT_F32)) { header = "Pf\n" + String::toAString(frame.width()) + " " + String::toAString(frame.height()) + "\n-1.0\n"; } - else if (FrameType::arePixelFormatsCompatible(frame.pixelFormat(), FrameType::genericPixelFormat())) + else if (frame.isPixelFormatCompatible(FrameType::genericPixelFormat())) { header = "PF\n" + String::toAString(frame.width()) + " " + String::toAString(frame.height()) + "\n-1.0\n"; } @@ -127,7 +127,7 @@ bool ImagePfm::readHeader(const uint8_t*& data, size_t& size, FrameType& frameTy } else if (data[0] == 'P' && data[1] == 'f' && data[2] == '\n') { - pixelFormat = FrameType::genericPixelFormat(); + pixelFormat = FrameType::FORMAT_F32; } else { diff --git a/impl/ocean/test/testmedia/TestSpecial.cpp b/impl/ocean/test/testmedia/TestSpecial.cpp index 25388cc79..6ec8b0ccc 100644 --- a/impl/ocean/test/testmedia/TestSpecial.cpp +++ b/impl/ocean/test/testmedia/TestSpecial.cpp @@ -196,12 +196,12 @@ TEST(TestSpecial, BmpImageY8LowerLeft) TEST(TestSpecial, PfmImageFloat1UpperLeft) { - EXPECT_TRUE(TestSpecial::testPfmImageEncodeDecode(1920u, 1080u, FrameType::genericPixelFormat(), FrameType::ORIGIN_UPPER_LEFT, GTEST_TEST_DURATION)); + EXPECT_TRUE(TestSpecial::testPfmImageEncodeDecode(1920u, 1080u, FrameType::FORMAT_F32, FrameType::ORIGIN_UPPER_LEFT, GTEST_TEST_DURATION)); } TEST(TestSpecial, PfmImageFloat1LowerLeft) { - EXPECT_TRUE(TestSpecial::testPfmImageEncodeDecode(1920u, 1080u, FrameType::genericPixelFormat(), FrameType::ORIGIN_LOWER_LEFT, GTEST_TEST_DURATION)); + EXPECT_TRUE(TestSpecial::testPfmImageEncodeDecode(1920u, 1080u, FrameType::FORMAT_F32, FrameType::ORIGIN_LOWER_LEFT, GTEST_TEST_DURATION)); } TEST(TestSpecial, PfmImageFloat3UpperLeft) @@ -466,7 +466,7 @@ bool TestSpecial::testPfmImageEncodeDecode(const double testDuration) const FrameType::PixelFormats pixelFormats = { - FrameType::genericPixelFormat(), + FrameType::FORMAT_F32, FrameType::genericPixelFormat() };