Skip to content

Commit

Permalink
Set the streaming mode in cjxl if both input and output are streaming. (
Browse files Browse the repository at this point in the history
  • Loading branch information
szabadka authored Dec 11, 2023
1 parent dca2d5b commit 581b62d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tools/cjxl_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ void PrintMode(jxl::extras::PackedPixelFile& ppf, const double decode_mps,
if (args.lossless_jpeg) {
cmdline.VerbosePrintf(1, "Read JPEG image with %" PRIuS " bytes.\n",
num_bytes);
} else {
} else if (num_bytes > 0) {
cmdline.VerbosePrintf(
1, "Read %" PRIuS "x%" PRIuS " image, %" PRIuS " bytes, %.1f MP/s\n",
static_cast<size_t>(ppf.info.xsize),
Expand Down Expand Up @@ -1049,6 +1049,8 @@ int main(int argc, char** argv) {
std::vector<uint8_t> image_data;
std::vector<uint8_t>* jpeg_bytes = nullptr;
jxl::extras::ChunkedPNMDecoder pnm_dec;
size_t input_bytes = 0;
double decode_mps = 0;
size_t pixels = 0;
if (args.streaming_input) {
pnm_dec.f = f;
Expand All @@ -1060,11 +1062,11 @@ int main(int argc, char** argv) {
args.lossless_jpeg = 0;
pixels = ppf.info.xsize * ppf.info.ysize;
} else {
double decode_mps = 0;
if (!jpegxl::tools::ReadFile(f, &image_data)) {
std::cerr << "Reading image data failed." << std::endl;
exit(EXIT_FAILURE);
}
input_bytes = image_data.size();
if (!jpegxl::tools::IsJPG(image_data)) args.lossless_jpeg = 0;
ProcessFlags(codec, ppf, jpeg_bytes, &cmdline, &args, &params);
if (!args.lossless_jpeg) {
Expand All @@ -1085,9 +1087,6 @@ int main(int argc, char** argv) {
const double t1 = jxl::Now();
decode_mps = pixels * ppf.info.num_color_channels * 1E-6 / (t1 - t0);
}
if (!args.quiet) {
PrintMode(ppf, decode_mps, image_data.size(), args, cmdline);
}

if (args.lossless_jpeg && jpegxl::tools::IsJPG(image_data)) {
if (!cmdline.GetOption(args.opt_lossless_jpeg_id)->matched()) {
Expand All @@ -1101,6 +1100,10 @@ int main(int argc, char** argv) {

ProcessFlags(codec, ppf, jpeg_bytes, &cmdline, &args, &params);

if (!args.quiet) {
PrintMode(ppf, decode_mps, input_bytes, args, cmdline);
}

if (!ppf.metadata.exif.empty()) {
jxl::InterpretExif(ppf.metadata.exif, &ppf.info.orientation);
}
Expand Down Expand Up @@ -1131,6 +1134,11 @@ int main(int argc, char** argv) {
params.runner = JxlThreadParallelRunner;
params.runner_opaque = runner.get();

if (args.streaming_input && args.streaming_output) {
params.options.emplace_back(jxl::extras::JXLOption(
JXL_ENC_FRAME_SETTING_BUFFERING, static_cast<int64_t>(3), 0));
}

jpegxl::tools::SpeedStats stats;
jpegxl::tools::JxlOutputProcessor output_processor;
if (args.streaming_output) {
Expand Down

0 comments on commit 581b62d

Please sign in to comment.