Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/avifenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef struct
avifBool ignoreExif;
avifBool ignoreXMP;
avifBool ignoreColorProfile;
avifBool ignoreAlpha;

// These settings are only relevant when compiled with AVIF_ENABLE_JPEG_GAIN_MAP_CONVERSION.
avifBool qualityGainMapIsConstrained; // true if qualityGainMap explicitly set by the user
Expand Down Expand Up @@ -256,6 +257,7 @@ static void syntaxLong(void)
printf(" --ignore-exif : If the input file contains embedded Exif metadata, ignore it (no-op if absent)\n");
printf(" --ignore-xmp : If the input file contains embedded XMP metadata, ignore it (no-op if absent)\n");
printf(" --ignore-profile,--ignore-icc : If the input file contains an embedded color profile, ignore it (no-op if absent)\n");
printf(" --ignore-alpha,--noalpha : Discard the alpha channel when encoding.\n");
#if defined(AVIF_ENABLE_JPEG_GAIN_MAP_CONVERSION)
printf(" --ignore-gain-map : If the input file contains an embedded gain map, ignore it (no-op if absent)\n");
printf(" --qgain-map Q : Quality for the gain map in %d..%d where %d is lossless\n",
Expand Down Expand Up @@ -526,6 +528,7 @@ static avifBool avifInputReadImage(avifInput * input,
avifBool ignoreColorProfile,
avifBool ignoreExif,
avifBool ignoreXMP,
avifBool ignoreAlpha,
avifBool allowChangingCicp,
avifBool ignoreGainMap,
avifImage * image,
Expand Down Expand Up @@ -633,6 +636,11 @@ static avifBool avifInputReadImage(avifInput * input,
}
return AVIF_FALSE;
}

if (ignoreAlpha) {
dstImage->alphaPlane = NULL;
dstImage->alphaRowBytes = 0;
}
if (!allowChangingCicp) {
// Restore the previous primaries/transfer in case avifReadImage changed them.
dstImage->colorPrimaries = colorPrimariesBefore;
Expand All @@ -658,6 +666,7 @@ static avifBool avifInputReadImage(avifInput * input,
ignoreColorProfile,
ignoreExif,
ignoreXMP,
ignoreAlpha,
allowChangingCicp,
ignoreGainMap,
image,
Expand Down Expand Up @@ -919,6 +928,7 @@ static avifBool avifEncodeRestOfImageSequence(avifEncoder * encoder,
/*ignoreColorProfile=*/AVIF_TRUE,
/*ignoreExif=*/AVIF_TRUE,
/*ignoreXMP=*/AVIF_TRUE,
settings->ignoreAlpha,
/*allowChangingCicp=*/AVIF_FALSE,
/*ignoreGainMap=*/AVIF_TRUE,
nextImage,
Expand Down Expand Up @@ -1021,6 +1031,7 @@ static avifBool avifEncodeRestOfLayeredImage(avifEncoder * encoder,
/*ignoreColorProfile=*/AVIF_TRUE,
/*ignoreExif=*/AVIF_TRUE,
/*ignoreXMP=*/AVIF_TRUE,
settings->ignoreAlpha,
!settings->cicpExplicitlySet,
/*ignoreGainMap=*/AVIF_TRUE,
nextImage,
Expand Down Expand Up @@ -1418,6 +1429,7 @@ int main(int argc, char * argv[])
settings.ignoreExif = AVIF_FALSE;
settings.ignoreXMP = AVIF_FALSE;
settings.ignoreColorProfile = AVIF_FALSE;
settings.ignoreAlpha = AVIF_FALSE;
settings.ignoreGainMap = AVIF_FALSE;
settings.cicpExplicitlySet = AVIF_FALSE;
settings.inputFormat = AVIF_APP_FILE_FORMAT_UNKNOWN;
Expand Down Expand Up @@ -1824,6 +1836,8 @@ int main(int argc, char * argv[])
goto cleanup;
}
settings.ignoreColorProfile = AVIF_TRUE;
} else if (!strcmp(arg, "--ignore-alpha") || !strcmp(arg, "--noalpha")) {
settings.ignoreAlpha = AVIF_TRUE;
} else if (!strcmp(arg, "--duration") || strpre(arg, "--duration:")) {
// --duration is special, we always treat it as suffixed with :u, so don't print warning for it.
avifOptionSuffixType type = parseOptionSuffix(arg, /*warnNoSuffix=*/AVIF_FALSE);
Expand Down Expand Up @@ -2317,6 +2331,7 @@ int main(int argc, char * argv[])
settings.ignoreColorProfile,
settings.ignoreExif,
settings.ignoreXMP,
settings.ignoreAlpha,
/*allowChangingCicp=*/!settings.cicpExplicitlySet,
ignoreGainMap,
image,
Expand Down Expand Up @@ -2562,6 +2577,7 @@ int main(int argc, char * argv[])
/*ignoreColorProfile=*/AVIF_TRUE,
/*ignoreExif=*/AVIF_TRUE,
/*ignoreXMP=*/AVIF_TRUE,
settings.ignoreAlpha,
/*allowChangingCicp=*/AVIF_FALSE,
settings.ignoreGainMap,
cellImage,
Expand Down
Loading