Skip to content

Commit

Permalink
Enable multi-threaded jxl decompression
Browse files Browse the repository at this point in the history
Summary: There are helper methods to makde jxl decompression multi-threaded, just use them.

Reviewed By: kiminoue7

Differential Revision: D51542155

fbshipit-source-id: b66bb3ee95bfad0c70d422f5d26f8b973b3b4db4
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Nov 29, 2023
1 parent 19eec8b commit 405eec3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion vrs/utils/PixelFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace std;

namespace {

static const uint8_t kNaNPixel = 0;
const uint8_t kNaNPixel = 0;

/// normalize floating point pixels to grey8
template <class Float>
Expand Down
11 changes: 9 additions & 2 deletions vrs/utils/PixelFrameJxl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <jxl/decode_cxx.h>
#include <jxl/encode.h>
#include <jxl/encode_cxx.h>
#include <jxl/thread_parallel_runner_cxx.h>
#include <jxl/types.h>
#endif

Expand Down Expand Up @@ -140,10 +141,16 @@ bool PixelFrame::readJxlFrame(RecordReader* reader, const uint32_t sizeBytes) {

bool PixelFrame::readJxlFrame(const vector<uint8_t>& jxlBuf, bool decodePixels) {
#ifdef JXL_IS_AVAILABLE
auto dec = getThreadJxlDecoder();
JxlDecoder* dec = getThreadJxlDecoder();
if (!XR_VERIFY(dec != nullptr)) {
return false;
}

size_t hw_threads = JxlThreadParallelRunnerDefaultNumWorkerThreads();
JxlThreadParallelRunnerPtr runner_fixed =
JxlThreadParallelRunnerMake(nullptr, std::min<size_t>(hw_threads, 4));
DEC_CHECK(JxlDecoderSetParallelRunner(dec, JxlThreadParallelRunner, runner_fixed.get()));

DEC_CHECK(JxlDecoderSubscribeEvents(
dec, JXL_DEC_BASIC_INFO | JXL_DEC_COLOR_ENCODING | JXL_DEC_FULL_IMAGE));

Expand Down Expand Up @@ -338,7 +345,7 @@ bool PixelFrame::jxlCompress(
}
ENC_CHECK(JxlEncoderSetColorEncoding(enc, &color_encoding));

auto settings = JxlEncoderFrameSettingsCreate(enc, nullptr);
JxlEncoderFrameSettings* settings = JxlEncoderFrameSettingsCreate(enc, nullptr);
ENC_CHECK(JxlEncoderFrameSettingsSetOption(settings, JXL_ENC_FRAME_SETTING_EFFORT, effort));
ENC_CHECK(JxlEncoderFrameSettingsSetOption(
settings, JXL_ENC_FRAME_SETTING_DECODING_SPEED, decoding_speed_tier));
Expand Down

0 comments on commit 405eec3

Please sign in to comment.