From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id E091E4E3C0 for ; Tue, 11 Mar 2025 00:59:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D3BB368DDB8; Tue, 11 Mar 2025 02:59:14 +0200 (EET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 25E5268DAFA for ; Tue, 11 Mar 2025 02:59:08 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 7CAC144169 for ; Tue, 11 Mar 2025 00:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1741654747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=f0XD+ydEPOiBTki3W5MMq29/pksaRPttbobywgRQGbc=; b=XxebrwQPvwsVgMCw8h6aZ1yManAwJs39QW5NiIrKtsog+bTiEKectC/NxB8XetTlocGwE3 QaEiOxL0LppLm2N4hFSIGvOpVmHilr5lMwVnD3pgfVO0sYB/nAZkuRpFfhbb6PsqbzjUDn fw7pS43i1Uk+6zLllxrKM2boYfFq12Gcs5z9ZlLU2B3woOylQQGcMr8YzxRmM95RO1Gov8 tUPRiNsZXazV6q72yTXpdcqOuIMrCcLsMMzaea6Ku+EA2Dzul+wmkQv+VwYLfs+xvNvTn9 SpU3m5y7acS2vA8T7+6SWaYpBzJInwngJn7/t4ljQpHeEiGsIdZzOq+IzhIqqw== Date: Tue, 11 Mar 2025 01:59:06 +0100 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20250311005906.GV4991@pb2> References: <20250310004552.2980855-1-michael@niedermayer.cc> MIME-Version: 1.0 In-Reply-To: X-GND-State: clean X-GND-Score: -70 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduvddtkeehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdeftddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfpihgvuggvrhhmrgihvghruceomhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtqeenucggtffrrghtthgvrhhnpeeigeektdejudffjefhteegjedtgeettefggedthfejgfevhfetgeekjedtvdfhveenucfkphepgedurdeiiedrieejrdduudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepgedurdeiiedrieejrdduudefpdhhvghloheplhhotggrlhhhohhsthdpmhgrihhlfhhrohhmpehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgdpnhgspghrtghpthhtohepuddprhgtphhtthhopehffhhmphgvghdquggvvhgvlhesfhhfmhhpvghgrdhorhhg X-GND-Sasl: michael@niedermayer.cc Subject: Re: [FFmpeg-devel] [PATCH] ffv1: implement remap for encode/decode_plane() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: multipart/mixed; boundary="===============7780809567796718762==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============7780809567796718762== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="uV6o6mYWwsv4GnXs" Content-Disposition: inline --uV6o6mYWwsv4GnXs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 10, 2025 at 06:48:29PM +0100, Lynne wrote: > On 10/03/2025 01:45, Michael Niedermayer wrote: > > Sponsored-by: Sovereign Tech Fund > > Signed-off-by: Michael Niedermayer > > --- > > libavcodec/ffv1dec.c | 20 ++++++++----- > > libavcodec/ffv1enc.c | 67 ++++++++++++++++++++++++++++++++++++++------ > > 2 files changed, 71 insertions(+), 16 deletions(-) > >=20 > > diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c > > index 9738e4e9c9f..72c93fcf0cd 100644 > > --- a/libavcodec/ffv1dec.c > > +++ b/libavcodec/ffv1dec.c > > @@ -92,7 +92,7 @@ static int is_input_end(RangeCoder *c, GetBitContext = *gb, int ac) > > static int decode_plane(FFV1Context *f, FFV1SliceContext *sc, > > GetBitContext *gb, > > uint8_t *src, int w, int h, int stride, int p= lane_index, > > - int pixel_stride, int ac) > > + int remap_index, int pixel_stride, int ac) > > { > > int x, y; > > int16_t *sample[2]; > > @@ -116,12 +116,18 @@ static int decode_plane(FFV1Context *f, FFV1Slice= Context *sc, > > int ret =3D decode_line(f, sc, gb, w, sample, plane_index= , 8, ac); > > if (ret < 0) > > return ret; > > + if (sc->remap) > > + for (x =3D 0; x < w; x++) > > + sample[1][x] =3D sc->fltmap[remap_index][sample[1]= [x]]; > > for (x =3D 0; x < w; x++) > > src[x*pixel_stride + stride * y] =3D sample[1][x]; > > } else { > > int ret =3D 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 =3D 0; x < w; x++) > > + sample[1][x] =3D sc->fltmap[remap_index][sample[1]= [x]]; > > if (f->packed_at_lsb) { > > for (x =3D 0; x < w; x++) { > > ((uint16_t*)(src + stride*y))[x*pixel_stride] =3D= sample[1][x]; > > @@ -347,17 +353,17 @@ static int decode_slice(AVCodecContext *c, void *= arg) > > if (f->colorspace =3D=3D 0 && (f->chroma_planes || !f->transparen= cy)) { > > const int cx =3D x >> f->chroma_h_shift; > > const int cy =3D y >> f->chroma_v_shift; > > - decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0],= width, height, p->linesize[0], 0, 1, ac); > > + decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0],= width, height, p->linesize[0], 0, 0, 1, ac); > > if (f->chroma_planes) { > > - decode_plane(f, sc, &gb, p->data[1] + ps*cx+cy*p->linesize= [1], chroma_width, chroma_height, p->linesize[1], 1, 1, ac); > > - decode_plane(f, sc, &gb, p->data[2] + ps*cx+cy*p->linesize= [2], chroma_width, chroma_height, p->linesize[2], 1, 1, ac); > > + decode_plane(f, sc, &gb, p->data[1] + ps*cx+cy*p->linesize= [1], chroma_width, chroma_height, p->linesize[1], 1, 1, 1, ac); > > + decode_plane(f, sc, &gb, p->data[2] + ps*cx+cy*p->linesize= [2], chroma_width, chroma_height, p->linesize[2], 1, 2, 1, ac); > > } > > if (f->transparency) > > - decode_plane(f, sc, &gb, p->data[3] + ps*x + y*p->linesize= [3], width, height, p->linesize[3], (f->version >=3D 4 && !f->chroma_planes= ) ? 1 : 2, 1, ac); > > + decode_plane(f, sc, &gb, p->data[3] + ps*x + y*p->linesize= [3], width, height, p->linesize[3], (f->version >=3D 4 && !f->chroma_planes= ) ? 1 : 2, 2, 1, ac); > > } else if (f->colorspace =3D=3D 0) { > > - decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0]= , width, height, p->linesize[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, 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]= + 1, width, height, p->linesize[0], 1, 1, 2, ac); > > } else if (f->use32bit) { > > uint8_t *planes[4] =3D { p->data[0] + ps * x + y * p->linesiz= e[0], > > p->data[1] + ps * x + y * p->linesize[= 1], > > diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c > > index f3041219b71..4c55c01263b 100644 > > --- a/libavcodec/ffv1enc.c > > +++ b/libavcodec/ffv1enc.c > > @@ -272,7 +272,7 @@ static inline void put_vlc_symbol(PutBitContext *pb= , VlcState *const state, > > static int encode_plane(FFV1Context *f, FFV1SliceContext *sc, > > const uint8_t *src, int w, int h, > > - int stride, int plane_index, int pixel_stride= , int ac) > > + int stride, int plane_index, int remap_index, = int pixel_stride, int ac) > > { > > int x, y, i, ret; > > const int pass1 =3D !!(f->avctx->flags & AV_CODEC_FLAG_PASS1); > > @@ -288,9 +288,14 @@ static int encode_plane(FFV1Context *f, FFV1SliceC= ontext *sc, > > sample[0][-1]=3D sample[1][0 ]; > > sample[1][ w]=3D sample[1][w-1]; > > + > > if (f->bits_per_raw_sample <=3D 8) { > > for (x =3D 0; x < w; x++) > > sample[0][x] =3D src[x * pixel_stride + stride * y]; > > + if (sc->remap) > > + for (x =3D 0; x < w; x++) > > + sample[0][x] =3D sc->fltmap[remap_index][ sample[0= ][x] ]; > > + > > if((ret =3D encode_line(f, sc, f->avctx, w, sample, plane= _index, 8, ac, pass1)) < 0) > > return ret; > > } else { > > @@ -303,6 +308,10 @@ static int encode_plane(FFV1Context *f, FFV1SliceC= ontext *sc, > > sample[0][x] =3D ((uint16_t*)(src + stride*y))[x]= >> (16 - f->bits_per_raw_sample); > > } > > } > > + if (sc->remap) > > + for (x =3D 0; x < w; x++) > > + sample[0][x] =3D sc->fltmap[remap_index][ sample[0= ][x] ]; > > + > > if((ret =3D encode_line(f, sc, f->avctx, w, sample, plane= _index, f->bits_per_raw_sample, ac, pass1)) < 0) > > return ret; > > } > > @@ -310,6 +319,30 @@ static int encode_plane(FFV1Context *f, FFV1SliceC= ontext *sc, > > return 0; > > } > > +static void load_plane(FFV1Context *f, FFV1SliceContext *sc, > > + const uint8_t *src, int w, int h, > > + int stride, int remap_index, int pixel_stride) > > +{ > > + int x, y; > > + > > + memset(sc->fltmap[remap_index], 0, sizeof(sc->fltmap[remap_index])= ); > > + > > + for (y =3D 0; y < h; y++) { > > + if (f->bits_per_raw_sample <=3D 8) { > > + for (x =3D 0; x < w; x++) > > + sc->fltmap[remap_index][ src[x * pixel_stride + stride= * y] ] =3D 1; > > + } else { > > + if (f->packed_at_lsb) { > > + for (x =3D 0; x < w; x++) > > + sc->fltmap[remap_index][ ((uint16_t*)(src + stride= *y))[x] ] =3D 1; > > + } else { > > + for (x =3D 0; x < w; x++) > > + sc->fltmap[remap_index][ ((uint16_t*)(src + stride= *y))[x] >> (16 - f->bits_per_raw_sample) ] =3D 1; > > + } > > + } > > + } > > +} > > + > > static void write_quant_table(RangeCoder *c, int16_t *quant_table) > > { > > int last =3D 0; > > @@ -1178,8 +1211,24 @@ retry: > > } > > if (sc->remap) { > > - if (f->colorspace =3D=3D 0) { > > - av_assert0(0); > > + if (f->colorspace =3D=3D 0 && c->pix_fmt !=3D AV_PIX_FMT_YA8) { > > + const int cx =3D x >> f->chroma_h_shift; > > + const int cy =3D y >> f->chroma_v_shift; > > + > > + //TODO decide on the order for the encoded remaps and load= s. with golomb rice it > > + // easier to have all range coded ones together, otherwise= it may be nicer to handle each plane as a whole? > > + > > + load_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], wi= dth, height, p->linesize[0], 0, 1); > > + > > + if (f->chroma_planes) { > > + load_plane(f, sc, p->data[1] + ps*cx+cy*p->linesize[1]= , chroma_width, chroma_height, p->linesize[1], 1, 1); > > + load_plane(f, sc, p->data[2] + ps*cx+cy*p->linesize[2]= , chroma_width, chroma_height, p->linesize[2], 2, 1); > > + } > > + 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 =3D=3D 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 (f->use32bit) { > > load_rgb_frame32(f, sc, planes, width, height, p->linesiz= e); > > } else > > @@ -1206,17 +1255,17 @@ retry: > > const int cx =3D x >> f->chroma_h_shift; > > const int cy =3D y >> f->chroma_v_shift; > > - ret =3D encode_plane(f, sc, p->data[0] + ps*x + y*p->linesize[= 0], width, height, p->linesize[0], 0, 1, ac); > > + ret =3D encode_plane(f, sc, p->data[0] + ps*x + y*p->linesize[= 0], width, height, p->linesize[0], 0, 0, 1, ac); > > if (f->chroma_planes) { > > - ret |=3D encode_plane(f, sc, p->data[1] + ps*cx+cy*p->line= size[1], chroma_width, chroma_height, p->linesize[1], 1, 1, ac); > > - ret |=3D encode_plane(f, sc, p->data[2] + ps*cx+cy*p->line= size[2], chroma_width, chroma_height, p->linesize[2], 1, 1, ac); > > + ret |=3D encode_plane(f, sc, p->data[1] + ps*cx+cy*p->line= size[1], chroma_width, chroma_height, p->linesize[1], 1, 1, 1, ac); > > + ret |=3D encode_plane(f, sc, p->data[2] + ps*cx+cy*p->line= size[2], chroma_width, chroma_height, p->linesize[2], 1, 2, 1, ac); > > } > > if (f->transparency) > > - ret |=3D encode_plane(f, sc, p->data[3] + ps*x + y*p->line= size[3], width, height, p->linesize[3], 2, 1, ac); > > + ret |=3D encode_plane(f, sc, p->data[3] + ps*x + y*p->line= size[3], width, height, p->linesize[3], 2, 3, 1, ac); > > } else if (c->pix_fmt =3D=3D AV_PIX_FMT_YA8) { > > - ret =3D encode_plane(f, sc, p->data[0] + ps*x + y*p->line= size[0], width, height, p->linesize[0], 0, 2, ac); > > - ret |=3D encode_plane(f, sc, p->data[0] + 1 + ps*x + y*p->line= size[0], width, height, p->linesize[0], 1, 2, ac); > > + ret =3D encode_plane(f, sc, p->data[0] + ps*x + y*p->line= size[0], width, height, p->linesize[0], 0, 0, 2, ac); > > + ret |=3D encode_plane(f, sc, p->data[0] + 1 + ps*x + y*p->line= size[0], width, height, p->linesize[0], 1, 1, 2, ac); > > } else if (f->use32bit) { > > ret =3D encode_rgb_frame32(f, sc, planes, width, height, p->l= inesize, ac); > > } else { >=20 > Doesn't apply properly. > What does it even do? Does the current git master not already do this? master implements remap for encode_rgb_frame* This implements it for the other cases. Most of this is untested though, i have no YUV planar float16 material thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In a rich man's house there is no place to spit but his face. -- Diogenes of Sinope --uV6o6mYWwsv4GnXs Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEKAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZ8+K2gAKCRBhHseHBAsP qw8EAKCXI4O0Md+sq3/JW9W7360Z1JzVIgCdHU5WNlRKu2HplfykS3Wp59BQp0s= =kHvW -----END PGP SIGNATURE----- --uV6o6mYWwsv4GnXs-- --===============7780809567796718762== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============7780809567796718762==--