这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tools/djxl_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ struct DecompressArgs {
"encode a new (lossy) JPEG.",
&pixels_to_jpeg, &SetBooleanTrue, 1);

cmdline->AddOptionFlag(
'J', "reconstruct_jpeg",
"Losslessly reconstruct a JPEG if possible, and fail otherwise.",
&reconstruct_jpeg, &SetBooleanTrue, 1);

opt_jpeg_quality_id = cmdline->AddOptionValue(
'q', "jpeg_quality", "N",
"Sets the JPEG output quality, default is 95. "
Expand Down Expand Up @@ -250,6 +255,7 @@ struct DecompressArgs {
uint32_t downsampling = 0;
bool allow_partial_files = false;
bool pixels_to_jpeg = false;
bool reconstruct_jpeg = false;
size_t jpeg_quality = 95;
bool use_sjpeg = false;
bool render_spotcolors = true;
Expand Down Expand Up @@ -495,6 +501,24 @@ int main(int argc, const char* argv[]) {
!cmdline.GetOption(args.opt_jpeg_quality_id)->matched())) {
args.bits_per_sample = 0;
}
if (args.reconstruct_jpeg) {
// If output is disabled, still try to reconstruct JPEG
if (filename_out.empty()) {
codec = jxl::extras::Codec::kJPG;
}
if (codec != jxl::extras::Codec::kJPG) {
fprintf(stderr,
"Error: --reconstruct_jpeg requires output format to be JPEG.\n");
return EXIT_FAILURE;
}
if (args.pixels_to_jpeg ||
cmdline.GetOption(args.opt_jpeg_quality_id)->matched()) {
fprintf(stderr,
"Error: --pixels_to_jpeg and --jpeg_quality cannot be"
" used with --reconstruct_jpeg.\n");
return EXIT_FAILURE;
}
}

jpegxl::tools::SpeedStats stats;
size_t num_worker_threads = JxlThreadParallelRunnerDefaultNumWorkerThreads();
Expand All @@ -521,6 +545,10 @@ int main(int argc, const char* argv[]) {
if (!DecompressJxlReconstructJPEG(args, compressed, runner.get(), &bytes,
&stats)) {
if (bytes.empty()) {
if (args.reconstruct_jpeg) {
fprintf(stderr, "Error: could not decode losslessly to JPEG.\n");
return EXIT_FAILURE;
}
if (!args.quiet) {
fprintf(stderr,
"Warning: could not decode losslessly to JPEG. Retrying "
Expand Down
Loading