MCPcopy Create free account
hub / github.com/AOMediaCodec/libavif / avifEncodeRestOfLayeredImage

Function avifEncodeRestOfLayeredImage

apps/avifenc.c:988–1097  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

986}
987
988static avifBool avifEncodeRestOfLayeredImage(avifEncoder * encoder,
989 const avifSettings * settings,
990 avifInput * input,
991 int layerIndex,
992 const avifImage * firstImage)
993{
994 avifBool success = AVIF_FALSE;
995 int layers = encoder->extraLayerCount + 1;
996 // --progressive only allows one input, so directly read from it.
997 int targetQuality = (settings->overrideQuality != INVALID_QUALITY) ? settings->overrideQuality
998 : input->files[0].settings.quality.value;
999
1000 avifImage * nextImage = NULL;
1001 const avifImage * encodingImage = firstImage;
1002 const avifInputFileSettings * nextSettings = NULL;
1003
1004 if (settings->progressive && avifInputHasRemainingData(input, layerIndex)) {
1005 fprintf(stderr, "ERROR: Automatic layered encoding can only have one input image.\n");
1006 goto cleanup;
1007 }
1008
1009 while (layerIndex < layers) {
1010 if (settings->progressive) {
1011 // reversed lerp, so that last layer reaches exact targetQuality
1012 encoder->quality = targetQuality - (targetQuality - PROGRESSIVE_START_QUALITY) *
1013 (encoder->extraLayerCount - layerIndex) / encoder->extraLayerCount;
1014 // We scaled the first layer by a half (numerator: 1, denominator: 2).
1015 // Don't perform any scaling for the second layer (numerator: 1, denominator: 1).
1016 const avifScalingMode scalingMode = { { 1, 1 }, { 1, 1 } };
1017 encoder->scalingMode = scalingMode;
1018 } else {
1019 const avifInputFile * nextFile = avifInputGetFile(input, layerIndex);
1020 // main() function should set number of layers to number of input,
1021 // so nextFile should not be NULL.
1022 assert(nextFile);
1023
1024 if (nextImage) {
1025 avifImageDestroy(nextImage);
1026 }
1027 nextImage = avifImageCreateEmpty();
1028 if (!nextImage) {
1029 fprintf(stderr, "ERROR: Out of memory\n");
1030 goto cleanup;
1031 }
1032 nextImage->colorPrimaries = firstImage->colorPrimaries;
1033 nextImage->transferCharacteristics = firstImage->transferCharacteristics;
1034 nextImage->matrixCoefficients = firstImage->matrixCoefficients;
1035 nextImage->yuvRange = firstImage->yuvRange;
1036 nextImage->alphaPremultiplied = firstImage->alphaPremultiplied;
1037
1038 // Ignore ICC, Exif and XMP because only the metadata of the first frame is taken into
1039 // account by the libavif API.
1040 // Ignore gain map because the two features are currently incompatible.
1041 if (!avifInputReadImage(input,
1042 layerIndex,
1043 /*ignoreColorProfile=*/AVIF_TRUE,
1044 /*ignoreExif=*/AVIF_TRUE,
1045 /*ignoreXMP=*/AVIF_TRUE,

Callers 1

Calls 11

avifInputGetFileFunction · 0.85
avifImageDestroyFunction · 0.85
avifImageCreateEmptyFunction · 0.85
avifInputReadImageFunction · 0.85
avifPrettyFilenameFunction · 0.85
qualityStringFunction · 0.85
avifEncoderAddImageFunction · 0.85
avifResultToStringFunction · 0.85

Tested by

no test coverage detected