Skip to content

Commit

Permalink
Add image reading convenience methods
Browse files Browse the repository at this point in the history
Summary:
These code changes add a couple convenience methods to remove/simplify common code patterns used when reading images that can be in unspecified image formats.
PixelFrame::readFrame can only read images that aren't image/video, because it doesn't know about image/video frames, but the new VideoRecordFormatStreamPlayer::readFrame can.
The benefit of these new helper functions can be seen in the other parts of code modified to use them. At the end of the day, the resulting code should do about the same thing.

Reviewed By: kiminoue7

Differential Revision: D51451623

fbshipit-source-id: 69ae21d1de140c8f22a8b5683a2be986bd59f6ee
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Nov 21, 2023
1 parent 5e6db80 commit 4a47d1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
11 changes: 3 additions & 8 deletions csrc/reader/MultiVRSReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,9 @@ bool OssMultiVRSReader::MultiVideoRecordFormatStreamPlayer::setBlock(
record.reader->read(data);
block.structuredArray = false;
} else {
std::shared_ptr<utils::PixelFrame> frame;
bool frameValid;
if (contentBlock.image().getImageFormat() == vrs::ImageFormat::VIDEO) {
frame = make_shared<utils::PixelFrame>(contentBlock.image());
frameValid = (tryToDecodeFrame(*frame, record, contentBlock) == 0);
} else {
frameValid = utils::PixelFrame::readFrame(frame, record.reader, contentBlock);
}
std::shared_ptr<utils::PixelFrame> frame =
make_shared<utils::PixelFrame>(contentBlock.image());
bool frameValid = readFrame(*frame, record, contentBlock);
if (XR_VERIFY(frameValid)) {
block.structuredArray = true;
// the image was read & maybe decompressed. Does it need to be converted, too?
Expand Down
10 changes: 2 additions & 8 deletions csrc/reader/VRSReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,8 @@ bool OssVRSReader::setBlock(
record.reader->read(data);
block.structuredArray = false;
} else {
shared_ptr<utils::PixelFrame> frame;
bool frameValid;
if (contentBlock.image().getImageFormat() == ImageFormat::VIDEO) {
frame = make_shared<utils::PixelFrame>(contentBlock.image());
frameValid = (tryToDecodeFrame(*frame, record, contentBlock) == 0);
} else {
frameValid = utils::PixelFrame::readFrame(frame, record.reader, contentBlock);
}
shared_ptr<utils::PixelFrame> frame = make_shared<utils::PixelFrame>(contentBlock.image());
bool frameValid = readFrame(*frame, record, contentBlock);
if (XR_VERIFY(frameValid)) {
block.structuredArray = true;
// the image was read & maybe decompressed. Does it need to be converted, too?
Expand Down

0 comments on commit 4a47d1c

Please sign in to comment.