Skip to content

Commit

Permalink
Print warnings on ignored clap,irot,imir (#2564)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-guyon authored Jan 9, 2025
1 parent 78b0a28 commit fa410da
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/avifdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ int main(int argc, char * argv[])
goto cleanup;
} else if (outputFormat == AVIF_APP_FILE_FORMAT_Y4M) {
if (decoder->image->icc.size || decoder->image->exif.size || decoder->image->xmp.size) {
printf("Warning: metadata dropped when saving to y4m.\n");
fprintf(stderr, "Warning: metadata dropped when saving to y4m.\n");
}
if (!y4mWrite(outputFilename, decoder->image)) {
goto cleanup;
Expand Down
20 changes: 19 additions & 1 deletion apps/shared/avifjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,21 @@ avifBool avifJPEGWrite(const char * outputFilename, const avifImage * avif, int
write_icc_profile(&cinfo, avif->icc.data, (unsigned int)avif->icc.size);
}

if (avif->transformFlags & AVIF_TRANSFORM_CLAP) {
avifCropRect cropRect;
avifDiagnostics diag;
if (avifCropRectConvertCleanApertureBox(&cropRect, &avif->clap, avif->width, avif->height, avif->yuvFormat, &diag) &&
(cropRect.x != 0 || cropRect.y != 0 || cropRect.width != avif->width || cropRect.height != avif->height)) {
// TODO: https://github.com/AOMediaCodec/libavif/issues/2427 - Implement.
fprintf(stderr,
"Warning: Clean Aperture values were ignored, the output image was NOT cropped to rectangle {%u,%u,%u,%u}\n",
cropRect.x,
cropRect.y,
cropRect.width,
cropRect.height);
}
}

if (avif->exif.data && (avif->exif.size > 0)) {
size_t exifTiffHeaderOffset;
avifResult result = avifGetExifTiffHeaderOffset(avif->exif.data, avif->exif.size, &exifTiffHeaderOffset);
Expand Down Expand Up @@ -1337,7 +1352,10 @@ avifBool avifJPEGWrite(const char * outputFilename, const avifImage * avif, int
avifRWDataFree(&exif);
} else if (avifImageGetExifOrientationFromIrotImir(avif) != 1) {
// There is no Exif yet, but we need to store the orientation.
// TODO(yguyon): Add a valid Exif payload or rotate the samples.
// TODO: https://github.com/AOMediaCodec/libavif/issues/2427 - Add a valid Exif payload or rotate the samples.
fprintf(stderr,
"Warning: Orientation %u was ignored, the output image was NOT rotated or mirrored\n",
avifImageGetExifOrientationFromIrotImir(avif));
}

if (avif->xmp.data && (avif->xmp.size > 0)) {
Expand Down
20 changes: 19 additions & 1 deletion apps/shared/avifpng.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,26 @@ avifBool avifPNGWrite(const char * outputFilename, const avifImage * avif, uint3
rowPointers[y] = row;
row += rowBytes;
}

if (avif->transformFlags & AVIF_TRANSFORM_CLAP) {
avifCropRect cropRect;
avifDiagnostics diag;
if (avifCropRectConvertCleanApertureBox(&cropRect, &avif->clap, avif->width, avif->height, avif->yuvFormat, &diag) &&
(cropRect.x != 0 || cropRect.y != 0 || cropRect.width != avif->width || cropRect.height != avif->height)) {
// TODO: https://github.com/AOMediaCodec/libavif/issues/2427 - Implement.
fprintf(stderr,
"Warning: Clean Aperture values were ignored, the output image was NOT cropped to rectangle {%u,%u,%u,%u}\n",
cropRect.x,
cropRect.y,
cropRect.width,
cropRect.height);
}
}
if (avifImageGetExifOrientationFromIrotImir(avif) != 1) {
// TODO(yguyon): Rotate the samples.
// TODO: https://github.com/AOMediaCodec/libavif/issues/2427 - Rotate the samples.
fprintf(stderr,
"Warning: Orientation %u was ignored, the output image was NOT rotated or mirrored\n",
avifImageGetExifOrientationFromIrotImir(avif));
}

if (rgbDepth > 8) {
Expand Down
22 changes: 22 additions & 0 deletions apps/shared/y4m.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string.h>

#include "avif/avif.h"
#include "avifexif.h"
#include "avifutil.h"

#define Y4M_MAX_LINE_SIZE 2048 // Arbitrary limit. Y4M headers should be much smaller than this
Expand Down Expand Up @@ -492,6 +493,27 @@ avifBool y4mWrite(const char * outputFilename, const avifImage * avif)
fprintf(stderr, "WARNING: writing alpha is currently only supported in 8bpc YUV444, ignoring alpha channel: %s\n", outputFilename);
}

if (avif->transformFlags & AVIF_TRANSFORM_CLAP) {
avifCropRect cropRect;
avifDiagnostics diag;
if (avifCropRectConvertCleanApertureBox(&cropRect, &avif->clap, avif->width, avif->height, avif->yuvFormat, &diag) &&
(cropRect.x != 0 || cropRect.y != 0 || cropRect.width != avif->width || cropRect.height != avif->height)) {
// TODO: https://github.com/AOMediaCodec/libavif/issues/2427 - Implement.
fprintf(stderr,
"Warning: Clean Aperture values were ignored, the output image was NOT cropped to rectangle {%u,%u,%u,%u}\n",
cropRect.x,
cropRect.y,
cropRect.width,
cropRect.height);
}
}
if (avifImageGetExifOrientationFromIrotImir(avif) != 1) {
// TODO: https://github.com/AOMediaCodec/libavif/issues/2427 - Rotate the samples.
fprintf(stderr,
"Warning: Orientation %u was ignored, the output image was NOT rotated or mirrored\n",
avifImageGetExifOrientationFromIrotImir(avif));
}

switch (avif->depth) {
case 8:
switch (avif->yuvFormat) {
Expand Down

0 comments on commit fa410da

Please sign in to comment.