From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH 2/5] avcodec/ffv1: Add YAF16 support
Date: Sat, 15 Mar 2025 01:00:04 +0100
Message-ID: <20250315000007.1601265-2-michael@niedermayer.cc> (raw)
In-Reply-To: <20250315000007.1601265-1-michael@niedermayer.cc>
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavcodec/ffv1_parse.c | 6 ++++--
libavcodec/ffv1dec.c | 4 ++--
libavcodec/ffv1enc.c | 33 +++++++++++++++++----------------
3 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/libavcodec/ffv1_parse.c b/libavcodec/ffv1_parse.c
index a85b563e98b..a49f1eb6cef 100644
--- a/libavcodec/ffv1_parse.c
+++ b/libavcodec/ffv1_parse.c
@@ -294,9 +294,11 @@ int ff_ffv1_parse_header(FFV1Context *f, RangeCoder *c, uint8_t *state)
} else
return AVERROR(ENOSYS);
} else if (f->transparency && !f->chroma_planes) {
- if (f->avctx->bits_per_raw_sample <= 8)
+ if (f->avctx->bits_per_raw_sample <= 8 && !f->flt) {
f->pix_fmt = AV_PIX_FMT_YA8;
- else
+ } else if (f->avctx->bits_per_raw_sample == 16 && f->flt) {
+ f->pix_fmt = AV_PIX_FMT_YAF16;
+ } else
return AVERROR(ENOSYS);
} else if (f->avctx->bits_per_raw_sample<=8 && !f->transparency) {
switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index d702e36625a..e24c6b8d3a2 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -362,8 +362,8 @@ static int decode_slice(AVCodecContext *c, void *arg)
if (f->transparency)
decode_plane(f, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 2, 1, ac);
} else if (f->colorspace == 0) {
- decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 0, 2, ac);
- decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 1, 2, ac);
+ decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 0, 2, ac);
+ decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + (ps>>1), width, height, p->linesize[0], 1, 1, 2, ac);
} else if (f->use32bit) {
uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
p->data[1] + ps * x + y * p->linesize[1],
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index b8ccda469ec..9fb98c37584 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -301,11 +301,11 @@ static int encode_plane(FFV1Context *f, FFV1SliceContext *sc,
} else {
if (f->packed_at_lsb) {
for (x = 0; x < w; x++) {
- sample[0][x] = ((uint16_t*)(src + stride*y))[x];
+ sample[0][x] = ((uint16_t*)(src + stride*y))[x * pixel_stride];
}
} else {
for (x = 0; x < w; x++) {
- sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - f->bits_per_raw_sample);
+ sample[0][x] = ((uint16_t*)(src + stride*y))[x * pixel_stride] >> (16 - f->bits_per_raw_sample);
}
}
if (sc->remap)
@@ -334,10 +334,10 @@ static void load_plane(FFV1Context *f, FFV1SliceContext *sc,
} else {
if (f->packed_at_lsb) {
for (x = 0; x < w; x++)
- sc->fltmap[remap_index][ ((uint16_t*)(src + stride*y))[x] ] = 1;
+ sc->fltmap[remap_index][ ((uint16_t*)(src + stride*y))[x * pixel_stride] ] = 1;
} else {
for (x = 0; x < w; x++)
- sc->fltmap[remap_index][ ((uint16_t*)(src + stride*y))[x] >> (16 - f->bits_per_raw_sample) ] = 1;
+ sc->fltmap[remap_index][ ((uint16_t*)(src + stride*y))[x * pixel_stride] >> (16 - f->bits_per_raw_sample) ] = 1;
}
}
}
@@ -842,6 +842,7 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx,
case AV_PIX_FMT_YUVA444P16:
case AV_PIX_FMT_YUVA422P16:
case AV_PIX_FMT_YUVA420P16:
+ case AV_PIX_FMT_YAF16:
if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) {
s->bits_per_raw_sample = 16;
} else if (!s->bits_per_raw_sample) {
@@ -926,17 +927,16 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx,
if (s->bits_per_raw_sample >= 16) {
s->use32bit = 1;
}
- s->flt = !!(desc->flags & AV_PIX_FMT_FLAG_FLOAT);
s->version = FFMAX(s->version, 1);
-
- if (s->flt)
- s->version = FFMAX(s->version, 4);
break;
default:
av_log(avctx, AV_LOG_ERROR, "format %s not supported\n",
av_get_pix_fmt_name(pix_fmt));
return AVERROR(ENOSYS);
}
+ s->flt = !!(desc->flags & AV_PIX_FMT_FLAG_FLOAT);
+ if (s->flt)
+ s->version = FFMAX(s->version, 4);
av_assert0(s->bits_per_raw_sample >= 8);
if (s->remap_mode < 0)
@@ -1225,7 +1225,7 @@ retry:
}
if (sc->remap) {
- if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8) {
+ if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8 && c->pix_fmt != AV_PIX_FMT_YAF16) {
const int cx = x >> f->chroma_h_shift;
const int cy = y >> f->chroma_v_shift;
@@ -1240,9 +1240,9 @@ retry:
}
if (f->transparency)
load_plane(f, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 3, 1);
- } else if (c->pix_fmt == AV_PIX_FMT_YA8) {
- load_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2);
- load_plane(f, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2);
+ } else if (c->pix_fmt == AV_PIX_FMT_YA8 || c->pix_fmt == AV_PIX_FMT_YAF16) {
+ load_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2);
+ load_plane(f, sc, p->data[0] + (ps>>1) + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2);
} else if (f->use32bit) {
load_rgb_frame32(f, sc, planes, width, height, p->linesize);
} else
@@ -1265,7 +1265,7 @@ retry:
lsb_size_bytes);
}
- if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8) {
+ if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8 && c->pix_fmt != AV_PIX_FMT_YAF16) {
const int cx = x >> f->chroma_h_shift;
const int cy = y >> f->chroma_v_shift;
@@ -1277,9 +1277,9 @@ retry:
}
if (f->transparency)
ret |= encode_plane(f, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 3, 1, ac);
- } else if (c->pix_fmt == AV_PIX_FMT_YA8) {
- ret = encode_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 0, 2, ac);
- ret |= encode_plane(f, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 1, 2, ac);
+ } else if (c->pix_fmt == AV_PIX_FMT_YA8 || c->pix_fmt == AV_PIX_FMT_YAF16) {
+ ret = encode_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 0, 2, ac);
+ ret |= encode_plane(f, sc, p->data[0] + (ps>>1) + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 1, 2, ac);
} else if (f->use32bit) {
ret = encode_rgb_frame32(f, sc, planes, width, height, p->linesize, ac);
} else {
@@ -1564,6 +1564,7 @@ const FFCodec ff_ffv1_encoder = {
AV_PIX_FMT_GRAY9,
AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
AV_PIX_FMT_YUV440P10, AV_PIX_FMT_YUV440P12,
+ AV_PIX_FMT_YAF16,
AV_PIX_FMT_GBRPF16),
.color_ranges = AVCOL_RANGE_MPEG,
.p.priv_class = &ffv1_class,
--
2.48.1
_______________________________________________
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".
next prev parent reply other threads:[~2025-03-15 0:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-15 0:00 [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1: fix remap without chroma planes Michael Niedermayer
2025-03-15 0:00 ` Michael Niedermayer [this message]
2025-03-15 0:00 ` [FFmpeg-devel] [PATCH 3/5] avcodec/ffv1: Add GRAYF16 support Michael Niedermayer
2025-03-15 0:00 ` [FFmpeg-devel] [PATCH 4/5] avcodec/ffv1enc: Fix signed type handling with remap Michael Niedermayer
2025-03-15 0:00 ` [FFmpeg-devel] [PATCH 5/5] avcodec/ffv1dec: Fix a YUVA issue with remaping Michael Niedermayer
2025-03-17 12:41 ` [FFmpeg-devel] [PATCH 1/5] avcodec/ffv1: fix remap without chroma planes Michael Niedermayer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250315000007.1601265-2-michael@niedermayer.cc \
--to=michael@niedermayer.cc \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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