Skip to content

Commit e40faf5

Browse files
authored
Make libpng treat benign errors as warnings (AOMediaCodec#2958)
For example, by default libpng will refuse to write a file with an ICC profile whose PCS illuminant is different from some exact hardcoded string.
1 parent 1e295ed commit e40faf5

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

apps/shared/avifpng.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,9 @@ avifBool avifPNGWrite(const char * outputFilename, const avifImage * avif, uint3
677677
fprintf(stderr, "Cannot init libpng (png): %s\n", outputFilename);
678678
goto cleanup;
679679
}
680+
681+
png_set_benign_errors(png, 1); // Treat benign errors as warnings.
682+
680683
info = png_create_info_struct(png);
681684
if (!info) {
682685
fprintf(stderr, "Cannot init libpng (info): %s\n", outputFilename);

tests/data/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ Source: Personal photo edited with Gimp 2.10.
233233
| 5087 | 0xffe2 APP2 | 612 | `ICC_PROFILE......T........mntrRG chunk 1/1` |
234234
| | | | ... |
235235

236+
### File [paris_exif_xmp_modified_icc.jpg](paris_exif_xmp_modified_icc.jpg)
237+
238+
![](paris_exif_xmp_modified_icc.jpg)
239+
240+
License: [same as libavif](https://github.com/AOMediaCodec/libavif/blob/main/LICENSE)
241+
242+
Source: Same as paris_exif_xmp_icc.jpg but edited to have libpng report 'PCS illuminant is not D50'
243+
(the byte at position 0x1440 was changed from 0x2D to 0x2C).
244+
236245
### File [paris_extended_xmp.jpg](paris_extended_xmp.jpg)
237246

238247
![](paris_extended_xmp.jpg)
19 KB
Loading

tests/test_cmd_metadata.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ source $(dirname "$0")/cmd_test_common.sh || exit
2121
# Input file paths.
2222
INPUT_PNG="${TESTDATA_DIR}/paris_icc_exif_xmp.png"
2323
INPUT_JPG="${TESTDATA_DIR}/paris_exif_xmp_icc.jpg"
24+
INPUT_JPG_WEIRD_ICC="${TESTDATA_DIR}/paris_exif_xmp_modified_icc.jpg"
2425
INPUT_ICC="${TESTDATA_DIR}/sRGB2014.icc"
2526
# Output file names.
2627
ENCODED_FILE="avif_test_cmd_metadata_encoded.avif"
@@ -42,7 +43,7 @@ trap cleanup EXIT
4243
pushd ${TMP_DIR}
4344
# Metadata test.
4445
echo "Testing metadata enc"
45-
for INPUT in "${INPUT_PNG}" "${INPUT_JPG}"; do
46+
for INPUT in "${INPUT_PNG}" "${INPUT_JPG}" "${INPUT_JPG_WEIRD_ICC}"; do
4647
"${AVIFENC}" "${INPUT}" -o "${ENCODED_FILE}"
4748

4849
# Ignoring a metadata chunk should produce a different output file.

0 commit comments

Comments
 (0)