On Sun, Nov 12, 2023 at 11:41:23AM +1100, Peter Ross wrote:
> Fixes ticket #10660.
> ---
>
> thanks to the mysterious 'ami_stuff'.
>
> libavcodec/leaddec.c | 38 ++
> 1 file changed, 26 insertions(+), 12 deletions(-)
>
> diff --git a/libavcodec/leaddec.c b/libavcodec/leaddec.c
> index fd2018256d..4f2cc03e65 100644
> --- a/libavcodec/leaddec.c
> +++ b/libavcodec/leaddec.c
> @@ -139,7 +139,7 @@ static int lead_decode_frame(AVCodecContext *avctx,
> AVFrame * frame,
> {
> LeadContext *s = avctx->priv_data;
> const uint8_t * buf = avpkt->data;
> -int ret, format, yuv20p_half = 0, fields = 1, q, size;
> +int ret, format, yuv420p_div = 1, yuv20p_half = 0, fields = 1, q, size;
> GetBitContext gb;
> int16_t dc_pred[3] = {0, 0, 0};
> uint16_t dequant[2][64];
> @@ -149,6 +149,10 @@ static int lead_decode_frame(AVCodecContext *avctx,
> AVFrame * frame,
>
> format = AV_RL16(buf + 4);
> switch(format) {
> +case 0x0:
> +yuv420p_div = 2;
> +avctx->pix_fmt = AV_PIX_FMT_YUV420P;
> +break;
> case 0x8000:
> yuv20p_half = 1;
> // fall-through
> @@ -192,29 +196,39 @@ static int lead_decode_frame(AVCodecContext *avctx,
> AVFrame * frame,
> init_get_bits8(&gb, s->bitstream_buf, size);
>
> if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
> -for (int mb_y = 0; mb_y < (avctx->height + 15) / 16; mb_y++)
> +for (int mb_y = 0; mb_y < (avctx->height + (16 / yuv420p_div - 1)) /
> (16 / yuv420p_div); mb_y++)
> for (int mb_x = 0; mb_x < (avctx->width + 15) / 16; mb_x++)
> -for (int b = 0; b < (yuv20p_half ? 4 : 6); b++) {
> -int luma_block = yuv20p_half ? 2 : 4;
> +for (int b = 0; b < ((yuv420p_div == 2 || yuv20p_half) ? 4 :
> 6); b++) {
> +int luma_block = (yuv420p_div == 2 || yuv20p_half) ? 2 :
> 4;
> const VLCElem * dc_vlc = b < luma_block ?
> luma_dc_vlc.table : chroma_dc_vlc.table;
> int dc_bits= b < luma_block ? LUMA_DC_BITS :
> CHROMA_DC_BITS;
> const VLCElem * ac_vlc = b < luma_block ?
> luma_ac_vlc.table : chroma_ac_vlc.table;
> int ac_bits= b < luma_block ? LUMA_AC_BITS :
> CHROMA_AC_BITS;
> -int plane = b < luma_block ? 0 : b -
> (yuv20p_half ? 1 : 3);
> -int x, y;
> +int plane = b < luma_block ? 0 : b -
> (luma_block - 1);
> +int x, y, yclip;
>
> if (b < luma_block) {
> -y = 16*mb_y + 8*(b >> 1);
> +y = (16 / yuv420p_div)*mb_y + 8*(b >> 1);
> x = 16*mb_x + 8*(b & 1);
> +yclip = 0;
> } else {
> -y = 8*mb_y;
> +y = (8 / yuv420p_div)*mb_y;
> x = 8*mb_x;
> +yclip = (yuv420p_div == 2) && y + 8 >= avctx->height
> / 2;
> }
>
> -ret = decode_block(s, &gb, dc_vlc, dc_bits, ac_vlc,
> ac_bits,
> -dc_pred + plane, dequant[!(b < 4)],
> -frame->data[plane] + y*frame->linesize[plane] + x,
> -(yuv20p_half && b < 2 ? 2 : 1) *
> frame->linesize[plane]);
> +if (!yclip) {
> +ret = decode_block(s, &gb, dc_vlc, dc_bits, ac_vlc,
> ac_bits,
> +dc_pred + plane, dequant[!(b < 4)],
> +frame->data[plane] + y*frame->linesize[plane] +
> x,
> +(yuv20p_half && b < 2 ? 2 : 1) *
> frame->linesize[plane]);
> +} else {
> +uint8_t tmp[64];
> +ret = decode_block(s, &gb, dc_vlc, dc_bits, ac_vlc,
> ac_bits,
> +dc_pred + plane, dequant[!(b < 4)], tmp, 8);
> +for (int yy = 0; yy < 8 && y + yy < avctx->height /
> 2; yy++)
> +memcpy(frame->data[plane] +
> (y+yy)*frame->linesize[plane] + x, tmp + yy, 8);
> +}
> if (ret < 0)
> return ret;
>
will apply in a few days.
-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".