From fa410dabf5074388dbd5b37cf361acb5470d9524 Mon Sep 17 00:00:00 2001 From: Yannis Guyon Date: Thu, 9 Jan 2025 12:09:14 +0000 Subject: [PATCH] Print warnings on ignored clap,irot,imir (#2564) --- apps/avifdec.c | 2 +- apps/shared/avifjpeg.c | 20 +++++++++++++++++++- apps/shared/avifpng.c | 20 +++++++++++++++++++- apps/shared/y4m.c | 22 ++++++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/apps/avifdec.c b/apps/avifdec.c index 1a6006d206..f79c31f712 100644 --- a/apps/avifdec.c +++ b/apps/avifdec.c @@ -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; diff --git a/apps/shared/avifjpeg.c b/apps/shared/avifjpeg.c index de0aa7f3fd..5e10d11e88 100644 --- a/apps/shared/avifjpeg.c +++ b/apps/shared/avifjpeg.c @@ -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); @@ -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)) { diff --git a/apps/shared/avifpng.c b/apps/shared/avifpng.c index c2f8a478d6..cb630bf176 100644 --- a/apps/shared/avifpng.c +++ b/apps/shared/avifpng.c @@ -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) { diff --git a/apps/shared/y4m.c b/apps/shared/y4m.c index afdb59f1d7..f569122f9b 100644 --- a/apps/shared/y4m.c +++ b/apps/shared/y4m.c @@ -13,6 +13,7 @@ #include #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 @@ -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) {