This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit d5174f9e5b701d4f272011a93677889d31986dbe Author: Niklas Haas <[email protected]> AuthorDate: Mon Dec 8 13:04:23 2025 +0100 Commit: Niklas Haas <[email protected]> CommitDate: Mon Dec 15 14:31:58 2025 +0000 swscale/format: add source format info to ff_sws_encode_colors() Specifically, I need access to this for generating a better dither matrix. --- libswscale/format.c | 28 +++++++++++++++------------- libswscale/format.h | 3 ++- libswscale/graph.c | 2 +- libswscale/tests/sws_ops.c | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/libswscale/format.c b/libswscale/format.c index 66ea5c00f6..7b4500ace4 100644 --- a/libswscale/format.c +++ b/libswscale/format.c @@ -1157,15 +1157,16 @@ static bool trc_is_hdr(enum AVColorTransferCharacteristic trc) } static int fmt_dither(SwsContext *ctx, SwsOpList *ops, - const SwsPixelType type, const SwsFormat fmt) + const SwsPixelType type, + const SwsFormat src, const SwsFormat dst) { SwsDither mode = ctx->dither; SwsDitherOp dither; if (mode == SWS_DITHER_AUTO) { /* Visual threshold of perception: 12 bits for SDR, 14 bits for HDR */ - const int jnd_bits = trc_is_hdr(fmt.color.trc) ? 14 : 12; - const int bpc = fmt.desc->comp[0].depth; + const int jnd_bits = trc_is_hdr(dst.color.trc) ? 14 : 12; + const int bpc = dst.desc->comp[0].depth; mode = bpc >= jnd_bits ? SWS_DITHER_NONE : SWS_DITHER_BAYER; } @@ -1319,11 +1320,12 @@ int ff_sws_decode_colors(SwsContext *ctx, SwsPixelType type, } int ff_sws_encode_colors(SwsContext *ctx, SwsPixelType type, - SwsOpList *ops, const SwsFormat fmt, bool *incomplete) + SwsOpList *ops, const SwsFormat src, + const SwsFormat dst, bool *incomplete) { - const AVLumaCoefficients *c = av_csp_luma_coeffs_from_avcsp(fmt.csp); + const AVLumaCoefficients *c = av_csp_luma_coeffs_from_avcsp(dst.csp); - switch (fmt.csp) { + switch (dst.csp) { case AVCOL_SPC_RGB: break; case AVCOL_SPC_UNSPECIFIED: @@ -1386,20 +1388,20 @@ int ff_sws_encode_colors(SwsContext *ctx, SwsPixelType type, RET(ff_sws_op_list_append(ops, &(SwsOp) { .type = type, .op = SWS_OP_LINEAR, - .lin = fmt_encode_range(fmt, incomplete), + .lin = fmt_encode_range(dst, incomplete), })); - if (!(fmt.desc->flags & AV_PIX_FMT_FLAG_FLOAT)) { + if (!(dst.desc->flags & AV_PIX_FMT_FLAG_FLOAT)) { SwsConst range = {0}; - const bool is_ya = fmt.desc->nb_components == 2; - for (int i = 0; i < fmt.desc->nb_components; i++) { + const bool is_ya = dst.desc->nb_components == 2; + for (int i = 0; i < dst.desc->nb_components; i++) { /* Clamp to legal pixel range */ const int idx = i * (is_ya ? 3 : 1); - range.q4[idx] = Q((1 << fmt.desc->comp[i].depth) - 1); + range.q4[idx] = Q((1 << dst.desc->comp[i].depth) - 1); } - RET(fmt_dither(ctx, ops, type, fmt)); + RET(fmt_dither(ctx, ops, type, src, dst)); RET(ff_sws_op_list_append(ops, &(SwsOp) { .op = SWS_OP_MAX, .type = type, @@ -1416,7 +1418,7 @@ int ff_sws_encode_colors(SwsContext *ctx, SwsPixelType type, return ff_sws_op_list_append(ops, &(SwsOp) { .type = type, .op = SWS_OP_CONVERT, - .convert.to = fmt_pixel_type(fmt.format), + .convert.to = fmt_pixel_type(dst.format), }); } diff --git a/libswscale/format.h b/libswscale/format.h index e6a1fd7116..fbb65d6805 100644 --- a/libswscale/format.h +++ b/libswscale/format.h @@ -169,6 +169,7 @@ int ff_sws_encode_pixfmt(SwsOpList *ops, enum AVPixelFormat fmt); int ff_sws_decode_colors(SwsContext *ctx, SwsPixelType type, SwsOpList *ops, const SwsFormat fmt, bool *incomplete); int ff_sws_encode_colors(SwsContext *ctx, SwsPixelType type, SwsOpList *ops, - const SwsFormat fmt, bool *incomplete); + const SwsFormat src, const SwsFormat dst, + bool *incomplete); #endif /* SWSCALE_FORMAT_H */ diff --git a/libswscale/graph.c b/libswscale/graph.c index cf44710c2d..9d9ca53b00 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -502,7 +502,7 @@ static int add_convert_pass(SwsGraph *graph, SwsFormat src, SwsFormat dst, ret = ff_sws_decode_colors(ctx, type, ops, src, &graph->incomplete); if (ret < 0) goto fail; - ret = ff_sws_encode_colors(ctx, type, ops, dst, &graph->incomplete); + ret = ff_sws_encode_colors(ctx, type, ops, src, dst, &graph->incomplete); if (ret < 0) goto fail; ret = ff_sws_encode_pixfmt(ops, dst.format); diff --git a/libswscale/tests/sws_ops.c b/libswscale/tests/sws_ops.c index 06fb87e3ae..1c17cf24a0 100644 --- a/libswscale/tests/sws_ops.c +++ b/libswscale/tests/sws_ops.c @@ -48,7 +48,7 @@ static int run_test(SwsContext *const ctx, AVFrame *frame, goto fail; if (ff_sws_decode_colors(ctx, SWS_PIXEL_F32, ops, src, &incomplete) < 0) goto fail; - if (ff_sws_encode_colors(ctx, SWS_PIXEL_F32, ops, dst, &incomplete) < 0) + if (ff_sws_encode_colors(ctx, SWS_PIXEL_F32, ops, src, dst, &incomplete) < 0) goto fail; if (ff_sws_encode_pixfmt(ops, dst.format) < 0) goto fail; _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
