Skip to content

Commit

Permalink
PNG: only create cICP chunk if ColorEncoding is primary (libjxl#3880)
Browse files Browse the repository at this point in the history
Also fix the detection of the primary encoding.

(cherry picked from commit 0306df3)
  • Loading branch information
sboukortt authored and mo271 committed Nov 26, 2024
1 parent ed371a7 commit d3544a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/extras/dec/jxl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,21 +387,19 @@ bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size,
fprintf(stderr, "JxlDecoderGetICCProfileSize failed\n");
}
if (icc_size != 0) {
ppf->primary_color_representation = PackedPixelFile::kIccIsPrimary;
ppf->icc.resize(icc_size);
if (JXL_DEC_SUCCESS != JxlDecoderGetColorAsICCProfile(
dec, target, ppf->icc.data(), icc_size)) {
fprintf(stderr, "JxlDecoderGetColorAsICCProfile failed\n");
return false;
}
}
if (JXL_DEC_SUCCESS == JxlDecoderGetColorAsEncodedProfile(
if (JXL_DEC_SUCCESS != JxlDecoderGetColorAsEncodedProfile(
dec, target, &ppf->color_encoding)) {
ppf->primary_color_representation =
PackedPixelFile::kColorEncodingIsPrimary;
} else {
ppf->color_encoding.color_space = JXL_COLOR_SPACE_UNKNOWN;
}
ppf->primary_color_representation =
PackedPixelFile::kColorEncodingIsPrimary;
icc_size = 0;
target = JXL_COLOR_PROFILE_TARGET_ORIGINAL;
if (JXL_DEC_SUCCESS !=
Expand All @@ -416,6 +414,7 @@ bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size,
fprintf(stderr, "JxlDecoderGetColorAsICCProfile failed\n");
return false;
}
ppf->primary_color_representation = PackedPixelFile::kIccIsPrimary;
}
} else if (status == JXL_DEC_FRAME) {
auto frame_or = jxl::extras::PackedFrame::Create(ppf->info.xsize,
Expand Down
5 changes: 4 additions & 1 deletion lib/extras/enc/apng.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,10 @@ Status APNGEncoder::EncodePackedPixelFileToAPNG(
PNG_FILTER_TYPE_BASE);
if (count == 0 && !encode_extra_channels) {
if (!MaybeAddSRGB(ppf.color_encoding, png_ptr, info_ptr)) {
MaybeAddCICP(ppf.color_encoding, png_ptr, info_ptr);
if (ppf.primary_color_representation !=
PackedPixelFile::kIccIsPrimary) {
MaybeAddCICP(ppf.color_encoding, png_ptr, info_ptr);
}
if (!ppf.icc.empty()) {
png_set_benign_errors(png_ptr, 1);
png_set_iCCP(png_ptr, info_ptr, "1", 0, ppf.icc.data(),
Expand Down

0 comments on commit d3544a9

Please sign in to comment.