From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id 37E814CDD8
	for <ffmpegdev@gitmailbox.com>; Sat, 15 Mar 2025 00:00:46 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E8E7568E375;
	Sat, 15 Mar 2025 02:00:18 +0200 (EET)
Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net
 [217.70.183.196])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B884A68E341
 for <ffmpeg-devel@ffmpeg.org>; Sat, 15 Mar 2025 02:00:11 +0200 (EET)
Received: by mail.gandi.net (Postfix) with ESMTPSA id 1A18244384
 for <ffmpeg-devel@ffmpeg.org>; Sat, 15 Mar 2025 00:00:10 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc;
 s=gm1; t=1741996811;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:mime-version:mime-version:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=CVFZgYTfQ9HMQ/0eKiJpR3UCLagLlbnFqTrJtVryZBg=;
 b=kmpohGtCRZ8H4TZ7vBNAWF7yvKQe6nEMkumDff9LDy2ZyEr7Isa6nofK6I/Yfl8n0XAMug
 ewl4cFIAlxosfhzLQsp2Y5t93zZiJZEz9z8w1dIdKuPyGNverBR5Y1hp+pVC46xuTD6JA6
 e1zy5EVNI5T3WCc9sDmUow+I3q/05nIuXx5CE1Hb3E4kBA1NC+lVznMrkosDntStKNa6my
 UNMHXCBpZzibmkRolkKO/yqNTD66LVU637JWA/rKPW6uoAoLXWHxd6cybZzsezIVlf8lGt
 YX4/X3E67bDNSr4+kB/R7nL94SsI3/5lmXtrxsx3Tx/QRs43wnCeKesNdTgEhA==
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Date: Sat, 15 Mar 2025 01:00:05 +0100
Message-ID: <20250315000007.1601265-3-michael@niedermayer.cc>
X-Mailer: git-send-email 2.48.1
In-Reply-To: <20250315000007.1601265-1-michael@niedermayer.cc>
References: <20250315000007.1601265-1-michael@niedermayer.cc>
MIME-Version: 1.0
X-GND-State: clean
X-GND-Score: -70
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddufedvvdduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdeftddmnecujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefoihgthhgrvghlucfpihgvuggvrhhmrgihvghruceomhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtqeenucggtffrrghtthgvrhhnpedvgfefudeijeetieejkefgfffhtdeludeuffdvfeelieevjeetvedufeetfeejfeenucfkphepgedurdeiiedrieejrdduudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepgedurdeiiedrieejrdduudefpdhhvghloheplhhotggrlhhhohhsthdpmhgrihhlfhhrohhmpehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgdpnhgspghrtghpthhtohepuddprhgtphhtthhopehffhhmphgvghdquggvvhgvlhesfhhfmhhpvghgrdhorhhg
X-GND-Sasl: michael@niedermayer.cc
Subject: [FFmpeg-devel] [PATCH 3/5] avcodec/ffv1: Add GRAYF16 support
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250315000007.1601265-3-michael@niedermayer.cc/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 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 a49f1eb6cef..9745f9de694 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 e24c6b8d3a2..968c386f897 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -125,16 +125,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 9fb98c37584..3879d1b19a1 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -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_GRAYF16:
     case AV_PIX_FMT_YAF16:
         if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) {
             s->bits_per_raw_sample = 16;
@@ -1565,6 +1566,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,
-- 
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".