[FFmpeg-cvslog] avcodec/ffv1: Add GRAYF16 support
Michael Niedermayer
git at videolan.org
Mon Mar 17 16:33:09 EET 2025
ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Sat Mar 15 00:49:30 2025 +0100| [276854e1835e16900b3ac5db188130895126f4d8] | committer: Michael Niedermayer
avcodec/ffv1: Add GRAYF16 support
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=276854e1835e16900b3ac5db188130895126f4d8
---
libavcodec/ffv1_parse.c | 5 ++++-
libavcodec/ffv1dec.c | 27 +++++++++++++++++++--------
libavcodec/ffv1enc.c | 2 ++
3 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/libavcodec/ffv1_parse.c b/libavcodec/ffv1_parse.c
index a49f1eb6ce..9745f9de69 100644
--- a/libavcodec/ffv1_parse.c
+++ b/libavcodec/ffv1_parse.c
@@ -288,7 +288,10 @@ int ff_ffv1_parse_header(FFV1Context *f, RangeCoder *c, uint8_t *state)
f->pix_fmt = AV_PIX_FMT_GRAY14;
} else if (f->avctx->bits_per_raw_sample == 16) {
f->packed_at_lsb = 1;
- f->pix_fmt = AV_PIX_FMT_GRAY16;
+ if (f->flt) {
+ f->pix_fmt = AV_PIX_FMT_GRAYF16;
+ } else
+ f->pix_fmt = AV_PIX_FMT_GRAY16;
} else if (f->avctx->bits_per_raw_sample < 16) {
f->pix_fmt = AV_PIX_FMT_GRAY16;
} else
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 4b41b9f852..085dc5abe8 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -128,16 +128,27 @@ static int decode_plane(FFV1Context *f, FFV1SliceContext *sc,
int ret = decode_line(f, sc, gb, w, sample, plane_index, f->avctx->bits_per_raw_sample, ac);
if (ret < 0)
return ret;
- if (sc->remap)
- for (x = 0; x < w; x++)
- sample[1][x] = sc->fltmap[remap_index][sample[1][x]];
- if (f->packed_at_lsb) {
- for (x = 0; x < w; x++) {
- ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x];
+
+ if (sc->remap) {
+ if (f->packed_at_lsb || f->avctx->bits_per_raw_sample == 16) {
+ for (x = 0; x < w; x++) {
+ ((uint16_t*)(src + stride*y))[x*pixel_stride] = sc->fltmap[remap_index][sample[1][x] & 0xFFFF];
+ }
+ } else {
+ for (x = 0; x < w; x++) {
+ int v = sc->fltmap[remap_index][sample[1][x] & 0xFFFF];
+ ((uint16_t*)(src + stride*y))[x*pixel_stride] = v << (16 - f->avctx->bits_per_raw_sample) | v >> (2 * f->avctx->bits_per_raw_sample - 16);
+ }
}
} else {
- for (x = 0; x < w; x++) {
- ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x] << (16 - f->avctx->bits_per_raw_sample) | ((uint16_t **)sample)[1][x] >> (2 * f->avctx->bits_per_raw_sample - 16);
+ if (f->packed_at_lsb || f->avctx->bits_per_raw_sample == 16) {
+ for (x = 0; x < w; x++) {
+ ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x];
+ }
+ } else {
+ for (x = 0; x < w; x++) {
+ ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x] << (16 - f->avctx->bits_per_raw_sample) | ((uint16_t **)sample)[1][x] >> (2 * f->avctx->bits_per_raw_sample - 16);
+ }
}
}
}
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 11f5048ee6..eac4aba49b 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -839,6 +839,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_GRAYF16:
case AV_PIX_FMT_YAF16:
if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) {
s->bits_per_raw_sample = 16;
@@ -1539,6 +1540,7 @@ const FFCodec ff_ffv1_encoder = {
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_GRAYF16,
AV_PIX_FMT_GBRPF16),
.color_ranges = AVCOL_RANGE_MPEG,
.p.priv_class = &ffv1_class,
More information about the ffmpeg-cvslog
mailing list