PR #26399 opened by Forgejo_Fairy URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26399 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26399.patch
Addresses the frame-subchunk portion of #26326. The first commit implements the DOS Animator word-run (1), skip/run delta (10) and initial palette (14) operations. Runs can cross visible scanlines. All three RGB frames of the generated 320×200 FLI, including its loop-back frame, matched the original DOS decompression routines in emulation with the Animator startup palette expanded to eight bits. [Original DOS Animator dispatch](https://github.com/AnimatorPro/Animator-DOS/blob/11529c6b46ad33f1a8c35e2f218780d5b6381cf0/src/V/FLI.C#L47) The second commit accepts packed 8-bit COPY rows with an optional final alignment byte and preserves support for rows padded to four bytes. A packed 6×2 frame decodes at c06bdc60c90d and is rejected at de1a0d43595b. The third commit writes the SS2 last-pixel update at the visible right edge. [FLC - Animator Pro Flic Files, COPY](https://github.com/AnimatorPro/Animator-Pro-SDL/blob/2c1b5debf65b6c5e83a6d8fad2993f0de22163d7/src/doc/FLCFILES.TXT#L368) · [SS2](https://github.com/AnimatorPro/Animator-Pro-SDL/blob/2c1b5debf65b6c5e83a6d8fad2993f0de22163d7/src/doc/FLCFILES.TXT#L485) All five tests in `make fate-flic SAMPLES=/opt/fate-suite` passed. The two new FATE tests generate their inputs locally. The 5×3 example exercises a packed COPY, a one-pixel SS2 update and a row-padded COPY loop-back frame. From 1fe3619abfcf81c05ed393783ee963f6b0f29eb6 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 27 Nov 2026 14:05:31 +0000 Subject: [PATCH 1/3] avcodec/flicvideo: decode three legacy DOS Animator chunks Implement the word-run, skip/run delta and initial palette operations used by the original 320x200 DOS Animator. Runs address consecutive visible pixels and can cross scanlines. Follow the original COMP.ASM signed 16-bit WRUN count and expand the initial VGA palette like FLI_COLOR. Exercise literal and repeated data, a delta crossing a row boundary, and the ring frame in FATE. Assisted-by: Fairy --- libavcodec/flicvideo.c | 110 +++++++++++++++++++++++++++++++++++++ tests/fate/video.mak | 11 +++- tests/flic-gen.sh | 65 ++++++++++++++++++++++ tests/ref/fate/flic-legacy | 8 +++ 4 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 tests/flic-gen.sh create mode 100644 tests/ref/fate/flic-legacy diff --git a/libavcodec/flicvideo.c b/libavcodec/flicvideo.c index d00ff9610d6..212b7dcad85 100644 --- a/libavcodec/flicvideo.c +++ b/libavcodec/flicvideo.c @@ -43,11 +43,14 @@ #include "decode.h" #include "mathops.h" +#define FLI_WRUN 1 #define FLI_256_COLOR 4 #define FLI_DELTA 7 +#define FLI_SBSRSC 10 #define FLI_COLOR 11 #define FLI_LC 12 #define FLI_BLACK 13 +#define FLI_ICOLORS 14 #define FLI_BRUN 15 #define FLI_COPY 16 #define FLI_MINI 18 @@ -366,6 +369,97 @@ static int flic_decode_frame_1BPP(AVCodecContext *avctx, return buf_size; } +/* Six-bit startup palette used by the DOS Animator, expanded as in FLI_COLOR. */ +static const uint32_t fli_initial_palette[256] = { + 0xff000000, 0xff080808, 0xff101010, 0xff181818, 0xff202020, 0xff282828, + 0xff303030, 0xff383838, 0xff414141, 0xff494949, 0xff515151, 0xff595959, + 0xff616161, 0xff696969, 0xff717171, 0xff797979, 0xff868686, 0xff8e8e8e, + 0xff969696, 0xff9e9e9e, 0xffa6a6a6, 0xffaeaeae, 0xffb6b6b6, 0xffbebebe, + 0xffc7c7c7, 0xffcfcfcf, 0xffd7d7d7, 0xffdfdfdf, 0xffe7e7e7, 0xffefefef, + 0xfff7f7f7, 0xffffffff, 0xffffcfcf, 0xffffffcf, 0xffcfffcf, 0xffcfffff, + 0xffcfcfff, 0xffffcfff, 0xffff9e9e, 0xffffcf9e, 0xffffff9e, 0xffcfff9e, + 0xff9eff9e, 0xff9effcf, 0xff9effff, 0xff9ecfff, 0xff9e9eff, 0xffcf9eff, + 0xffff9eff, 0xffff9ecf, 0xffff6d6d, 0xffff9e6d, 0xffffcf6d, 0xffffff6d, + 0xffcfff6d, 0xff9eff6d, 0xff6dff6d, 0xff6dff9e, 0xff6dffcf, 0xff6dffff, + 0xff6dcfff, 0xff6d9eff, 0xff6d6dff, 0xff9e6dff, 0xffcf6dff, 0xffff6dff, + 0xffff6dcf, 0xffff6d9e, 0xffff3c3c, 0xffff6d3c, 0xffff9e3c, 0xffffcf3c, + 0xffffff3c, 0xffcfff3c, 0xff9eff3c, 0xff6dff3c, 0xff3cff3c, 0xff3cff6d, + 0xff3cff9e, 0xff3cffcf, 0xff3cffff, 0xff3ccfff, 0xff3c9eff, 0xff3c6dff, + 0xff3c3cff, 0xff6d3cff, 0xff9e3cff, 0xffcf3cff, 0xffff3cff, 0xffff3ccf, + 0xffff3c9e, 0xffff3c6d, 0xffff0c3c, 0xffff0c0c, 0xffff3c0c, 0xffff6d0c, + 0xffff9e0c, 0xffffcf0c, 0xffffff0c, 0xffcfff0c, 0xff9eff0c, 0xff6dff0c, + 0xff3cff0c, 0xff0cff0c, 0xff0cff3c, 0xff0cff6d, 0xff0cff9e, 0xff0cffcf, + 0xff0cffff, 0xff0ccfff, 0xff0c9eff, 0xff0c6dff, 0xff0c3cff, 0xff0c0cff, + 0xff3c0cff, 0xff6d0cff, 0xff9e0cff, 0xffcf0cff, 0xffff0cff, 0xffff0ccf, + 0xffff0c9e, 0xffff0c6d, 0xffcf0c3c, 0xffcf0c0c, 0xffcf3c0c, 0xffcf6d0c, + 0xffcf9e0c, 0xffcfcf0c, 0xff9ecf0c, 0xff6dcf0c, 0xff3ccf0c, 0xff0ccf0c, + 0xff0ccf3c, 0xff0ccf6d, 0xff0ccf9e, 0xff0ccfcf, 0xff0c9ecf, 0xff0c6dcf, + 0xff0c3ccf, 0xff0c0ccf, 0xff3c0ccf, 0xff6d0ccf, 0xff9e0ccf, 0xffcf0ccf, + 0xffcf0c9e, 0xffcf0c6d, 0xff9e0c3c, 0xff9e0c0c, 0xff9e3c0c, 0xff9e6d0c, + 0xff9e9e0c, 0xff6d9e0c, 0xff3c9e0c, 0xff0c9e0c, 0xff0c9e3c, 0xff0c9e6d, + 0xff0c9e9e, 0xff0c6d9e, 0xff0c3c9e, 0xff0c0c9e, 0xff3c0c9e, 0xff6d0c9e, + 0xff9e0c9e, 0xff9e0c6d, 0xff6d0c3c, 0xff6d0c0c, 0xff6d3c0c, 0xff6d6d0c, + 0xff3c6d0c, 0xff0c6d0c, 0xff0c6d3c, 0xff0c6d6d, 0xff0c3c6d, 0xff0c0c6d, + 0xff3c0c6d, 0xff6d0c6d, 0xff3c0c0c, 0xff3c3c0c, 0xff0c3c0c, 0xff0c3c3c, + 0xff0c0c3c, 0xff3c0c3c, 0xff6d3c3c, 0xff6d6d3c, 0xff3c6d3c, 0xff3c6d6d, + 0xff3c3c6d, 0xff6d3c6d, 0xff9e3c3c, 0xff9e6d3c, 0xff9e9e3c, 0xff6d9e3c, + 0xff3c9e3c, 0xff3c9e6d, 0xff3c9e9e, 0xff3c6d9e, 0xff3c3c9e, 0xff6d3c9e, + 0xff9e3c9e, 0xff9e3c6d, 0xffcf3c3c, 0xffcf6d3c, 0xffcf9e3c, 0xffcfcf3c, + 0xff9ecf3c, 0xff6dcf3c, 0xff3ccf3c, 0xff3ccf6d, 0xff3ccf9e, 0xff3ccfcf, + 0xff3c9ecf, 0xff3c6dcf, 0xff3c3ccf, 0xff6d3ccf, 0xff9e3ccf, 0xffcf3ccf, + 0xffcf3c9e, 0xffcf3c6d, 0xffcf6d6d, 0xffcf9e6d, 0xffcfcf6d, 0xff9ecf6d, + 0xff6dcf6d, 0xff6dcf9e, 0xff6dcfcf, 0xff6d9ecf, 0xff6d6dcf, 0xff9e6dcf, + 0xffcf6dcf, 0xffcf6d9e, 0xffcf9e9e, 0xffcfcf9e, 0xff9ecf9e, 0xff9ecfcf, + 0xff9e9ecf, 0xffcf9ecf, 0xff9e6d6d, 0xff9e9e6d, 0xff6d9e6d, 0xff6d9e9e, + 0xff6d6d9e, 0xff9e6d9e, 0xff0c0c0c, 0xff3c3c3c, 0xff6d6d6d, 0xff9e9e9e, + 0xffcfcfcf, 0xffffffff, 0xffff590c, 0xff9e1c14, 0xff9292ff, 0xff000000, + 0xff595959, 0xff9a9a9a, 0xffd3d3d3, 0xffff0000, +}; + +/* These DOS Animator packets address a contiguous 320x200 screen. + * A single packet may span scanlines in the output frame. */ +static int decode_fli_legacy_run(AVFrame *frame, GetByteContext *gb, + int type, int end) +{ + const int word_run = type == FLI_WRUN; + const int unit = word_run ? 2 : 1; + int pos, packets; + + if (end - bytestream2_tell(gb) < (word_run ? 2 : 4)) + return AVERROR_INVALIDDATA; + + pos = word_run ? 0 : bytestream2_get_le16u(gb); + packets = bytestream2_get_le16u(gb); + for (int i = 0; i < packets; i++) { + int count, repeat, bytes, src_size; + const uint8_t *src; + + if (end - bytestream2_tell(gb) < 2) + return AVERROR_INVALIDDATA; + if (word_run) { + count = sign_extend(bytestream2_get_le16u(gb), 16); + repeat = count >= 0; + } else { + pos += bytestream2_get_byteu(gb); + count = sign_extend(bytestream2_get_byteu(gb), 8); + repeat = count < 0; + } + + bytes = abs(count) * unit; + src_size = repeat ? unit : bytes; + if (bytes > 320 * 200 - pos || src_size > end - bytestream2_tell(gb)) + return AVERROR_INVALIDDATA; + + src = gb->buffer; + bytestream2_skipu(gb, src_size); + for (int j = 0; j < bytes; j++, pos++) { + uint8_t *row = frame->data[0] + (ptrdiff_t)(pos / 320) * frame->linesize[0]; + row[pos % 320] = src[repeat ? j % unit : j]; + } + } + return 0; +} + static int flic_decode_frame_8BPP(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, const uint8_t *buf, int buf_size) @@ -438,6 +532,22 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx, chunk_type = bytestream2_get_le16(&g2); switch (chunk_type) { + case FLI_WRUN: + case FLI_SBSRSC: + if (s->fli_type != FLI_TYPE_CODE || avctx->width != 320 || avctx->height != 200) + break; + ret = decode_fli_legacy_run(s->frame, &g2, chunk_type, stream_ptr_after_chunk); + if (ret < 0) + return ret; + break; + + case FLI_ICOLORS: + if (s->fli_type != FLI_TYPE_CODE) + break; + memcpy(s->palette, fli_initial_palette, sizeof(s->palette)); + s->new_palette = 1; + break; + case FLI_256_COLOR: case FLI_COLOR: /* check special case: If this file is from the Magic Carpet diff --git a/tests/fate/video.mak b/tests/fate/video.mak index e663b807a84..1d954301017 100644 --- a/tests/fate/video.mak +++ b/tests/fate/video.mak @@ -189,9 +189,18 @@ fate-flic-af12: CMD = framecrc -i $(TARGET_SAMPLES)/fli/jj00c2.fli -pix_fmt rgb2 FATE_FLIC += fate-flic-magiccarpet fate-flic-magiccarpet: CMD = framecrc -i $(TARGET_SAMPLES)/fli/intel.dat -pix_fmt rgb24 -vf scale +tests/data/flic-%.fli: TAG = GEN +tests/data/flic-%.fli: $(SRC_PATH)/tests/flic-gen.sh | tests/data + $(M)sh $< $* > $@ + +FATE_FLIC_GEN-$(call FRAMECRC, FLIC, FLIC, SCALE_FILTER) += fate-flic-legacy +fate-flic-legacy: tests/data/flic-legacy.fli +fate-flic-legacy: CMD = framecrc -i $(TARGET_PATH)/tests/data/flic-legacy.fli -pix_fmt rgb24 -vf scale +FATE_FFMPEG += $(FATE_FLIC_GEN-yes) + FATE_FLIC-$(call FRAMECRC, FLIC, FLIC, SCALE_FILTER) += $(FATE_FLIC) FATE_VIDEO += $(FATE_FLIC-yes) -fate-flic: $(FATE_FLIC-yes) +fate-flic: $(FATE_FLIC-yes) $(FATE_FLIC_GEN-yes) FATE_VIDEO-$(call FRAMECRC, AVI, FRWU) += fate-frwu fate-frwu: CMD = framecrc -i $(TARGET_SAMPLES)/frwu/frwu.avi diff --git a/tests/flic-gen.sh b/tests/flic-gen.sh new file mode 100644 index 00000000000..0aa2db3a2dd --- /dev/null +++ b/tests/flic-gen.sh @@ -0,0 +1,65 @@ +#!/bin/sh +# Generate small palettized FLICs with packets that span scanlines. +set -e + +bytes() +{ + printf '%b' "$(printf '\\0%03o' "$@")" +} + +le16() +{ + for value do + bytes $((value & 255)) $(((value >> 8) & 255)) + done +} + +le32() +{ + le16 $(($1 & 65535)) $(($1 >> 16)) +} + +zeros() +{ + dd if=/dev/zero bs="$1" count=1 2>/dev/null +} + +frame() +{ + le32 "$1" + le16 0xf1fa "$2" + zeros 8 +} + +chunk() +{ + le32 "$1" + le16 "$2" +} + +wrun() +{ + chunk 22 1 + le16 3 + le16 159; bytes 32 33 + le16 65534; bytes 34 35 36 37 # literal pair of words across a row boundary + le16 31839; bytes 38 39 +} + +case "$1" in +legacy) + le32 246 + le16 0xaf11 2 320 200 8 3 5 + zeros 110 + frame 44 2 + chunk 6 14 # initial palette + wrun + frame 36 1 + chunk 20 10 + le16 318 2 # initial pixel offset and packet count + bytes 1 4 255 253 252 251 1 253 250 0 + frame 38 1 # ring frame + wrun + ;; +*) exit 1 ;; +esac diff --git a/tests/ref/fate/flic-legacy b/tests/ref/fate/flic-legacy new file mode 100644 index 00000000000..df93db5e32e --- /dev/null +++ b/tests/ref/fate/flic-legacy @@ -0,0 +1,8 @@ +#tb 0: 1/14 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 320x200 +#sar 0: 0/1 +0, 0, 0, 1, 192000, 0xd17a27bd +0, 1, 1, 1, 192000, 0x935620aa +0, 2, 2, 1, 192000, 0xd17a27bd -- 2.54.1 From 81688b2fcbeb48a564af29eff43b3c1f4803ccd5 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 27 Nov 2026 14:05:57 +0000 Subject: [PATCH 2/3] avcodec/flicvideo: accept packed rows in palettized COPY chunks Select the four-byte aligned row pitch when it matches the payload. Otherwise accept the contiguous width by height image specified for Animator Pro, including its optional trailing alignment byte. Assisted-by: Fairy --- libavcodec/flicvideo.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/libavcodec/flicvideo.c b/libavcodec/flicvideo.c index 212b7dcad85..a064f0a2afd 100644 --- a/libavcodec/flicvideo.c +++ b/libavcodec/flicvideo.c @@ -755,22 +755,28 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx, } break; - case FLI_COPY: - /* copy the chunk (uncompressed frame) */ - if (chunk_size - 6 != FFALIGN(s->avctx->width, 4) * s->avctx->height) { - av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \ + case FLI_COPY: { + int stride = avctx->width; + int64_t packed_size = (int64_t)stride * avctx->height; + + /* Animator Pro stores consecutive pixels. Other writers pad each + * row to four bytes. A packed chunk may end with one pad byte. */ + if (chunk_size - 6 == (int64_t)FFALIGN(stride, 4) * avctx->height) { + stride = FFALIGN(stride, 4); + } else if (chunk_size - 6 != packed_size && + chunk_size - 6 != FFALIGN(packed_size, 2)) { + av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " "has incorrect size, skipping chunk\n", chunk_size - 6); - bytestream2_skip(&g2, chunk_size - 6); - } else { - for (y_ptr = 0; check_pixel_ptr(y_ptr, s->avctx->width, pixel_lo, pixel_hi) == 0; - y_ptr += s->frame->linesize[0]) { - bytestream2_get_buffer(&g2, &pixels[y_ptr], - s->avctx->width); - if (s->avctx->width & 3) - bytestream2_skip(&g2, 4 - (s->avctx->width & 3)); - } + break; + } + + for (int y = 0; y < avctx->height; y++) { + bytestream2_get_buffer(&g2, pixels + (ptrdiff_t)y * s->frame->linesize[0], + avctx->width); + bytestream2_skip(&g2, stride - avctx->width); } break; + } case FLI_MINI: /* some sort of a thumbnail? disregard this chunk... */ -- 2.54.1 From b58fb8bc14e76a5d29e8a94cbe921d907265ba61 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 27 Nov 2026 14:06:24 +0000 Subject: [PATCH 3/3] avcodec/flicvideo: write the SS2 last pixel at the visible right edge The optional SS2 last-byte operation sets the last pixel in the current row. Use the image width independently of the output buffer pitch. Cover it together with packed and padded COPY layouts in a 5x3 FATE fixture. Assisted-by: Fairy --- libavcodec/flicvideo.c | 4 ++-- tests/fate/video.mak | 4 +++- tests/flic-gen.sh | 21 +++++++++++++++++++++ tests/ref/fate/flic-odd-width | 8 ++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 tests/ref/fate/flic-odd-width diff --git a/libavcodec/flicvideo.c b/libavcodec/flicvideo.c index a064f0a2afd..7cf6aff372d 100644 --- a/libavcodec/flicvideo.c +++ b/libavcodec/flicvideo.c @@ -613,8 +613,8 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "Undefined opcode (%x) in DELTA_FLI\n", line_packets); } else if ((line_packets & 0xC000) == 0x8000) { // "last byte" opcode - pixel_ptr= y_ptr + s->frame->linesize[0] - 1; - CHECK_PIXEL_PTR(0); + pixel_ptr = y_ptr + avctx->width - 1; + CHECK_PIXEL_PTR(1); pixels[pixel_ptr] = line_packets & 0xff; } else { compressed_lines--; diff --git a/tests/fate/video.mak b/tests/fate/video.mak index 1d954301017..df84f7cc1e3 100644 --- a/tests/fate/video.mak +++ b/tests/fate/video.mak @@ -193,9 +193,11 @@ tests/data/flic-%.fli: TAG = GEN tests/data/flic-%.fli: $(SRC_PATH)/tests/flic-gen.sh | tests/data $(M)sh $< $* > $@ -FATE_FLIC_GEN-$(call FRAMECRC, FLIC, FLIC, SCALE_FILTER) += fate-flic-legacy +FATE_FLIC_GEN-$(call FRAMECRC, FLIC, FLIC, SCALE_FILTER) += fate-flic-legacy fate-flic-odd-width fate-flic-legacy: tests/data/flic-legacy.fli fate-flic-legacy: CMD = framecrc -i $(TARGET_PATH)/tests/data/flic-legacy.fli -pix_fmt rgb24 -vf scale +fate-flic-odd-width: tests/data/flic-odd-width.fli +fate-flic-odd-width: CMD = framecrc -i $(TARGET_PATH)/tests/data/flic-odd-width.fli -pix_fmt rgb24 -vf scale FATE_FFMPEG += $(FATE_FLIC_GEN-yes) FATE_FLIC-$(call FRAMECRC, FLIC, FLIC, SCALE_FILTER) += $(FATE_FLIC) diff --git a/tests/flic-gen.sh b/tests/flic-gen.sh index 0aa2db3a2dd..7aeba9d83ac 100644 --- a/tests/flic-gen.sh +++ b/tests/flic-gen.sh @@ -61,5 +61,26 @@ legacy) frame 38 1 # ring frame wrun ;; +odd-width) + le32 262 + le16 0xaf12 2 5 3 8 3 + le32 40 + zeros 60 + le32 128 + le32 188 + zeros 40 + frame 60 2 + chunk 22 4 + le16 1 + bytes 0 4 0 0 0 255 0 0 0 255 0 0 0 255 + chunk 22 16 + bytes 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 0 # one pad byte after the image + frame 28 1 + chunk 12 7 + le16 1 0x8003 0 # change only the rightmost pixel of the first line + frame 46 1 + chunk 30 16 + bytes 0 1 2 3 0 0 0 0 1 2 3 0 1 0 0 0 2 3 0 1 2 0 0 0 # padded rows + ;; *) exit 1 ;; esac diff --git a/tests/ref/fate/flic-odd-width b/tests/ref/fate/flic-odd-width new file mode 100644 index 00000000000..d40f4379ffd --- /dev/null +++ b/tests/ref/fate/flic-odd-width @@ -0,0 +1,8 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 5x3 +#sar 0: 0/1 +0, 0, 0, 1, 45, 0xf10e0af5 +0, 1, 1, 1, 45, 0x0ffe0bf4 +0, 2, 2, 1, 45, 0xf10e0af5 -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
