avcodec/png: set correct alpha mode

PNG always uses straight alpha.

cf. https://www.w3.org/TR/PNG-Rationale.html

> Although each form of alpha storage has its advantages, we did not want to
> require all PNG viewers to handle both forms. We standardized on non-
> premultiplied alpha as being the lossless and more general case.
This commit is contained in:
Niklas Haas
2025-02-19 20:35:20 +01:00
parent 02d531ca05
commit d6ce720765
2 changed files with 11 additions and 0 deletions
+5
View File
@@ -998,6 +998,11 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s,
s->bpp += byte_depth;
}
/* PNG spec mandates independent alpha channel */
if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
avctx->alpha_mode = AVALPHA_MODE_STRAIGHT;
ff_progress_frame_unref(&s->picture);
if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
/* We only need a buffer for the current picture. */
+6
View File
@@ -1255,6 +1255,9 @@ const FFCodec ff_png_encoder = {
AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A,
AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_YA16BE,
AV_PIX_FMT_MONOBLACK),
.alpha_modes = (const enum AVAlphaMode[]) {
AVALPHA_MODE_STRAIGHT, AVALPHA_MODE_UNSPECIFIED
},
.p.priv_class = &pngenc_class,
.caps_internal = FF_CODEC_CAP_ICC_PROFILES,
};
@@ -1275,6 +1278,9 @@ const FFCodec ff_apng_encoder = {
AV_PIX_FMT_PAL8,
AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A,
AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_YA16BE),
.alpha_modes = (const enum AVAlphaMode[]) {
AVALPHA_MODE_STRAIGHT, AVALPHA_MODE_UNSPECIFIED
},
.p.priv_class = &pngenc_class,
.caps_internal = FF_CODEC_CAP_ICC_PROFILES,
};