Skip to content

Commit

Permalink
accept buffer pointer
Browse files Browse the repository at this point in the history
Summary:
To be able to pass views over raw pixel buffers we cannot use the current API.

We cannot yet use std::span due to  old C++ version support
For now let's just allow to pass the const pointer to the raw buffer

Reviewed By: georges-berenger

Differential Revision: D63975867

fbshipit-source-id: e83d47437f73ca708976eac344f3077dbe54f5bb
  • Loading branch information
Pierluigi Taddei authored and facebook-github-bot committed Oct 8, 2024
1 parent efd5600 commit eb414c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions vrs/utils/PixelFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ class PixelFrame {
vector<uint8_t>& outBuffer,
uint32_t quality);

/// Same as previous version, with an external pixel buffer.
static bool jpgCompress(
const ImageContentBlockSpec& pixelSpec,
const uint8_t* pixels,
vector<uint8_t>& outBuffer,
uint32_t quality);

/// Read a JPEG-XL encoded frame into the internal buffer.
/// @return True if the frame type is supported & the frame was read.
/// Returns false, if no decoder was installed, or the data couldn't be decoded correctly.
Expand Down
12 changes: 10 additions & 2 deletions vrs/utils/PixelFrameJpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ bool PixelFrame::jpgCompress(
const vector<uint8_t>& pixels,
vector<uint8_t>& outBuffer,
uint32_t quality) {
return jpgCompress(pixelSpec, pixels.data(), outBuffer, quality);
}

/// Replace with a function accepting a std::span
bool PixelFrame::jpgCompress(
const ImageContentBlockSpec& pixelSpec,
const uint8_t* pixels,
vector<uint8_t>& outBuffer,
uint32_t quality) {
if (!XR_VERIFY(pixelSpec.getImageFormat() == ImageFormat::RAW) ||
!XR_VERIFY(
pixelSpec.getPixelFormat() == PixelFormat::RGB8 ||
Expand All @@ -119,14 +128,13 @@ bool PixelFrame::jpgCompress(
const bool isGrey8 = (pixelSpec.getChannelCountPerPixel() == 1);
long unsigned int jpegDataSize = 0;
unsigned char* jpegData = nullptr;
const uint8_t* input = pixels.data();

tjhandle _jpegCompressor = tjInitCompress();

if (!XR_VERIFY(
tjCompress2(
_jpegCompressor,
input,
pixels,
pixelSpec.getWidth(),
pixelSpec.getStride(),
pixelSpec.getHeight(),
Expand Down

0 comments on commit eb414c5

Please sign in to comment.