Skip to content

Commit

Permalink
Print gain map info in avifenc/avifdec. (AOMediaCodec#1598)
Browse files Browse the repository at this point in the history
In avifenc, the gain map's detailed info like pixel size, yuv format etc. are printed.
In avifdec, only the presence/absence of a gain map in the AVIF file is printed. 
The full info is not available because enableDecodingGainMap is disabled by default,
and it doesn't make sense to enable it since the gain map won't be savec anyway
(saving to jpeg+gainmap is not implemented).
  • Loading branch information
maryla-uc authored Sep 19, 2023
1 parent 1e0205a commit 3669d47
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
6 changes: 5 additions & 1 deletion apps/avifdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,11 @@ int main(int argc, char * argv[])

printf("Image decoded: %s\n", inputFilename);
printf("Image details:\n");
avifImageDump(decoder->image, 0, 0, decoder->progressiveState);
avifBool gainMapPresent = AVIF_FALSE;
#if defined(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP)
gainMapPresent = decoder->gainMapPresent;
#endif
avifImageDump(decoder->image, 0, 0, gainMapPresent, decoder->progressiveState);

if (ignoreICC && (decoder->image->icc.size > 0)) {
printf("[--ignore-icc] Discarding ICC profile.\n");
Expand Down
5 changes: 5 additions & 0 deletions apps/avifenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2472,9 +2472,14 @@ int main(int argc, char * argv[])
}
printf("AVIF to be written:%s\n", lossyHint);
const avifImage * avif = gridCells ? gridCells[0] : image;
avifBool gainMapPresent = AVIF_FALSE;
#if defined(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP)
gainMapPresent = (avif->gainMap.image != NULL);
#endif
avifImageDump(avif,
settings.gridDims[0],
settings.gridDims[1],
gainMapPresent,
settings.layers > 1 ? AVIF_PROGRESSIVE_STATE_AVAILABLE : AVIF_PROGRESSIVE_STATE_UNAVAILABLE);

avifIOStats ioStats = { 0, 0 };
Expand Down
37 changes: 33 additions & 4 deletions apps/shared/avifutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ static void printClapFraction(const char * name, int32_t n, int32_t d)
}
}

static void avifImageDumpInternal(const avifImage * avif, uint32_t gridCols, uint32_t gridRows, avifBool alphaPresent, avifProgressiveState progressiveState)
static void avifImageDumpInternal(const avifImage * avif,
uint32_t gridCols,
uint32_t gridRows,
avifBool alphaPresent,
avifBool gainMapPresent,
avifProgressiveState progressiveState)
{
uint32_t width = avif->width;
uint32_t height = avif->height;
Expand Down Expand Up @@ -124,17 +129,41 @@ static void avifImageDumpInternal(const avifImage * avif, uint32_t gridCols, uin
if (avif->clli.maxCLL > 0 || avif->clli.maxPALL > 0) {
printf(" * CLLI : %hu, %hu\n", avif->clli.maxCLL, avif->clli.maxPALL);
}

#if defined(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP)
printf(" * Gain map : ");
avifImage * gainMap = avif->gainMap.image;
if (gainMap != NULL) {
printf("%ux%u pixels, %u bit, %s, %s Range, Matrix Coeffs. %u \n",
gainMap->width,
gainMap->height,
gainMap->depth,
avifPixelFormatToString(gainMap->yuvFormat),
(gainMap->yuvRange == AVIF_RANGE_FULL) ? "Full" : "Limited",
gainMap->matrixCoefficients);
} else if (gainMapPresent) {
printf("Present (but ignored)\n");
} else {
printf("Absent\n");
}
#else
(void)gainMapPresent;
#endif // AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP
}

void avifImageDump(const avifImage * avif, uint32_t gridCols, uint32_t gridRows, avifProgressiveState progressiveState)
void avifImageDump(const avifImage * avif, uint32_t gridCols, uint32_t gridRows, avifBool gainMapPresent, avifProgressiveState progressiveState)
{
const avifBool alphaPresent = avif->alphaPlane && (avif->alphaRowBytes > 0);
avifImageDumpInternal(avif, gridCols, gridRows, alphaPresent, progressiveState);
avifImageDumpInternal(avif, gridCols, gridRows, alphaPresent, gainMapPresent, progressiveState);
}

void avifContainerDump(const avifDecoder * decoder)
{
avifImageDumpInternal(decoder->image, 0, 0, decoder->alphaPresent, decoder->progressiveState);
avifBool gainMapPresent = AVIF_FALSE;
#if defined(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP)
gainMapPresent = decoder->gainMapPresent;
#endif
avifImageDumpInternal(decoder->image, 0, 0, decoder->alphaPresent, gainMapPresent, decoder->progressiveState);
if ((decoder->progressiveState == AVIF_PROGRESSIVE_STATE_UNAVAILABLE) && (decoder->imageCount > 1)) {
if (decoder->repetitionCount == AVIF_REPETITION_COUNT_INFINITE) {
printf(" * Repeat Count : Infinite\n");
Expand Down
2 changes: 1 addition & 1 deletion apps/shared/avifutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
#define AVIF_FMT_ZU "zu"
#endif

void avifImageDump(const avifImage * avif, uint32_t gridCols, uint32_t gridRows, avifProgressiveState progressiveState);
void avifImageDump(const avifImage * avif, uint32_t gridCols, uint32_t gridRows, avifBool gainMapPresent, avifProgressiveState progressiveState);
void avifContainerDump(const avifDecoder * decoder);
void avifPrintVersions(void);
void avifDumpDiagnostics(const avifDiagnostics * diag);
Expand Down

0 comments on commit 3669d47

Please sign in to comment.