Skip to content

Commit

Permalink
Switching to FORMAT_F32 pixel format in Pfm image loader in case of a…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
janherling authored and facebook-github-bot committed Dec 27, 2024
1 parent 0951261 commit 48a89ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions impl/ocean/media/special/ImagePfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ bool ImagePfm::encodeImage(const Frame& frame, std::vector<uint8_t>& buffer)

std::string header;

if (FrameType::arePixelFormatsCompatible(frame.pixelFormat(), FrameType::genericPixelFormat<float, 1u>()))
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<float, 3u>()))
else if (frame.isPixelFormatCompatible(FrameType::genericPixelFormat<float, 3u>()))
{
header = "PF\n" + String::toAString(frame.width()) + " " + String::toAString(frame.height()) + "\n-1.0\n";
}
Expand Down Expand Up @@ -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<float, 1u>();
pixelFormat = FrameType::FORMAT_F32;
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions impl/ocean/test/testmedia/TestSpecial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ TEST(TestSpecial, BmpImageY8LowerLeft)

TEST(TestSpecial, PfmImageFloat1UpperLeft)
{
EXPECT_TRUE(TestSpecial::testPfmImageEncodeDecode(1920u, 1080u, FrameType::genericPixelFormat<float, 1u>(), 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<float, 1u>(), 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)
Expand Down Expand Up @@ -466,7 +466,7 @@ bool TestSpecial::testPfmImageEncodeDecode(const double testDuration)

const FrameType::PixelFormats pixelFormats =
{
FrameType::genericPixelFormat<float, 1u>(),
FrameType::FORMAT_F32,
FrameType::genericPixelFormat<float, 3u>()
};

Expand Down

0 comments on commit 48a89ec

Please sign in to comment.