Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] lead: support format 0x0
@ 2023-11-12  0:41 Peter Ross
  2024-02-15  8:18 ` Peter Ross
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Ross @ 2023-11-12  0:41 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1: Type: text/plain, Size: 4282 bytes --]

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;
 
-- 
2.42.0

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-15  8:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-12  0:41 [FFmpeg-devel] [PATCH] lead: support format 0x0 Peter Ross
2024-02-15  8:18 ` Peter Ross

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git