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 ESMTP id E9B55460AE for ; Sun, 4 Jun 2023 15:09:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 58DE768C3C5; Sun, 4 Jun 2023 18:09:23 +0300 (EEST) Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5C06168AC15 for ; Sun, 4 Jun 2023 18:09:17 +0300 (EEST) Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-1a2ad8f4075so2399772fac.2 for ; Sun, 04 Jun 2023 08:09:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685891355; x=1688483355; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=JVFqMNX2gokRoRLOk4KSAjFnF6R4ZfxwfAYUwqitpvw=; b=IM+IybhvK/dJ4pkqyldXPNEk2da8cApb8d6XJj6Yojo9kHA6ztHlkJM2kXmb9IC/Dt VhuajBo+LuEw7WNfhLKtzzD7OZ2Dd8EszLx2zEGPWERjHWIqeLSrJ1IFMEF13cAwFvWP E7n4EC82mzdKe6EUzVCRiJpQuh0NFd476W2JP4vIZZqWnLZe0HmuzXaELSxJWXGizM5J ShdgJAdlLQTjJ815RCW55xiun10bd7cxp+quEtE0nxm5Ga+ftISgnorYiF5MwfKofUFZ ouACCffqrrwZxGayIVWVLdR3AiTE61vVKYhuILXMheXo/a0VZjXQ6nMXr+Ku27GPEKUE 1VlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685891355; x=1688483355; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JVFqMNX2gokRoRLOk4KSAjFnF6R4ZfxwfAYUwqitpvw=; b=ZXnpxTB4RzAYqsm9LkSmtojuvgJM026WE2kay3xgCD7EvOlW+0yZ2hMtAyksHWxHbH RYEVv2zZr24KIHiuWmmS/KWE2cuMaJD1EW1jsK/QEVv6k+5jvqtmqE4NVnTQ2C6PWB+z shcvEo3P7DOiO/GFJyo/cC8H2JonDm6Muk1Zos7YxU9hMeB1LPKkj72/BDpiFLkWfLmE Oq4WENR1IqFNowEE7xYqZPJV2JGhUIZ2r65Vgcf3V/MwQfbsM0hudzxrgl0HW3Dnhd8w ohJ9+176BRlZP+7le09J+l4QAUQePtVzfO95aBBfe3aVXCIY5KZQZVRGoWqw1fkO0thr E1LA== X-Gm-Message-State: AC+VfDzBVZ4lPCWWmgYqMqEdb5Eg0G6S5EIpWvuCmUPJuz4Pmn3iwlNL TPs6e4I9rmX86mwhWkZQHs8Luou7JYY= X-Google-Smtp-Source: ACHHUZ6sZ3RHY0UV7CIk07hAUhp2jQcLMNtj2ISTrQkxB9DR7yhJFRvNuHgTs+xKJ/CRs1qIJnqHqg== X-Received: by 2002:a05:6870:822a:b0:19d:cf95:ca9 with SMTP id n42-20020a056870822a00b0019dcf950ca9mr7476474oae.54.1685891355171; Sun, 04 Jun 2023 08:09:15 -0700 (PDT) Received: from [192.168.0.12] (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id d42-20020a056870d2aa00b0019ed19a8659sm2709689oae.8.2023.06.04.08.09.14 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 04 Jun 2023 08:09:14 -0700 (PDT) Message-ID: <150c9b09-ed6d-9e76-21be-4ae208f1d5d8@gmail.com> Date: Sun, 4 Jun 2023 12:09:21 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: From: James Almer In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH] avcodec: add RTV1 decoder 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: > From cdd867aa1c88fa8b89dfe473ae0e2caf69c74313 Mon Sep 17 00:00:00 2001 > From: Paul B Mahol > Date: Sat, 3 Jun 2023 12:29:25 +0200 > Subject: [PATCH] avcodec: add RTV1 decoder > > Signed-off-by: Paul B Mahol > --- > libavcodec/Makefile | 1 + > libavcodec/allcodecs.c | 1 + > libavcodec/codec_desc.c | 7 ++ > libavcodec/codec_id.h | 1 + > libavcodec/rtv1.c | 141 ++++++++++++++++++++++++++++++++++++++++ > libavformat/riff.c | 1 + > 6 files changed, 152 insertions(+) > create mode 100644 libavcodec/rtv1.c Don't forget to bump minor version. [...] > diff --git a/libavcodec/rtv1.c b/libavcodec/rtv1.c > new file mode 100644 > index 0000000000..953f915c83 > --- /dev/null > +++ b/libavcodec/rtv1.c > @@ -0,0 +1,141 @@ > +/* > + * RTV1 decoder > + * Copyright (c) 2023 Paul B Mahol > + * > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * FFmpeg is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA > + */ > + > +#include > +#include > + > +#include "avcodec.h" > +#include "bytestream.h" > +#include "codec_internal.h" > +#include "decode.h" > +#include "texturedsp.h" > +#include "thread.h" > + > +static int decode_rtv1(GetByteContext *gb, uint8_t *dst, int linesize, ptrdiff_t linesize > + int width, int height, int flag, > + int (*dxt1_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)) > +{ > + uint8_t block[8] = { 0 }; > + int run = 0; > + > + for (int y = 0; y < height; y += 4) { > + for (int x = 0; x < width * 4; x += 16) { > + int mode = 0; > + > + if (run && --run > 0) { > + dxt1_block(dst + x, linesize, block); > + } else { > + int a, b; > + > + if (bytestream2_get_bytes_left(gb) < 4) > + break; > + > + a = bytestream2_get_le16u(gb); > + b = bytestream2_get_le16u(gb); > + if (a == b && flag) { 4 bytes for a boolean value? Geez. > + AV_WL32(block + 4, 0); > + } else if (a == 1 && b == 0xffff) { > + mode = 1; > + } else if (b && a == 0) { > + run = b; > + } else { > + AV_WL16(block, a); > + AV_WL16(block + 2, b); > + AV_WL32(block + 4, bytestream2_get_le32(gb)); > + } > + if (run && !mode) { > + dxt1_block(dst + x, linesize, block); > + } else if (!mode) { > + AV_WL16(block, a); > + AV_WL16(block + 2, b); > + dxt1_block(dst + x, linesize, block); > + } else { > + if (bytestream2_get_bytes_left(gb) < 12 * 4) > + break; > + > + for (int by = 0; by < 4; by++) { > + for (int bx = 0; bx < 4; bx++) > + AV_WL32(dst + x + bx * 4 + by * linesize, bytestream2_get_le24u(gb)); > + } > + } > + } > + } > + > + dst += linesize * 4; > + } > + > + return 0; > +} > + > +static int decode_frame(AVCodecContext *avctx, AVFrame *p, > + int *got_frame, AVPacket *avpkt) > +{ > + int ret, width, height, flags; > + TextureDSPContext dsp; > + GetByteContext gb; > + ptrdiff_t linesize; > + uint8_t *dst; > + > + if (avpkt->size < 22) > + return AVERROR_INVALIDDATA; > + > + ff_texturedsp_init(&dsp); This should be in an init() function, not called for every frame. > + > + bytestream2_init(&gb, avpkt->data, avpkt->size); > + > + if (bytestream2_get_le32(&gb) != MKTAG('D','X','T','1')) Is this really a RivaTuner codec and not just raw texture if the first four bytes are the name of the texture type? > + return AVERROR_INVALIDDATA; > + flags = bytestream2_get_le32(&gb); > + > + width = bytestream2_get_le32(&gb); > + height = bytestream2_get_le32(&gb); > + ret = ff_set_dimensions(avctx, width, height); > + if (ret < 0) > + return ret; > + > + avctx->coded_width = FFALIGN(avctx->width, 4); > + avctx->coded_height = FFALIGN(avctx->height, 4); This should also be in avcodec_align_dimensions2(), otherwise it will not be taken into account by ff_thread_get_buffer(). > + avctx->pix_fmt = AV_PIX_FMT_BGR0; Move this to the init function too while at it. > + > + if ((ret = ff_thread_get_buffer(avctx, p, 0)) < 0) > + return ret; > + > + dst = p->data[0] + p->linesize[0] * (avctx->coded_height - 1); > + linesize = -p->linesize[0]; > + > + decode_rtv1(&gb, dst, linesize, width, height, flags, dsp.dxt1_block); > + > + p->pict_type = AV_PICTURE_TYPE_I; > + p->flags |= AV_FRAME_FLAG_KEY; > + > + *got_frame = 1; > + > + return avpkt->size; > +} > + > +const FFCodec ff_rtv1_decoder = { > + .p.name = "rtv1", > + CODEC_LONG_NAME("RTV1 (RivaTuner Video)"), > + .p.type = AVMEDIA_TYPE_VIDEO, > + .p.id = AV_CODEC_ID_RTV1, > + FF_CODEC_DECODE_CB(decode_frame), > + .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, > +}; > diff --git a/libavformat/riff.c b/libavformat/riff.c > index 7319406b39..4279071159 100644 > --- a/libavformat/riff.c > +++ b/libavformat/riff.c > @@ -501,6 +501,7 @@ const AVCodecTag ff_codec_bmp_tags[] = { > { AV_CODEC_ID_NOTCHLC, MKTAG('n', 'l', 'c', '1') }, > { AV_CODEC_ID_VQC, MKTAG('V', 'Q', 'C', '1') }, > { AV_CODEC_ID_VQC, MKTAG('V', 'Q', 'C', '2') }, > + { AV_CODEC_ID_RTV1, MKTAG('R', 'T', 'V', '1') }, > { AV_CODEC_ID_NONE, 0 } > }; > > -- > 2.39.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".