From patchwork Sun Jan 28 21:13:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Connor Worley X-Patchwork-Id: 45871 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp1196139pzb; Sun, 28 Jan 2024 13:14:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLyZzSxDMUYMzFowEBWWXpNBIsr2PSehb+X4W1GWHrkFxLIAVFo8PH+Unmn0eg6KlWjx3N X-Received: by 2002:a05:6402:2709:b0:55c:8b81:87f2 with SMTP id y9-20020a056402270900b0055c8b8187f2mr3512741edd.31.1706476446812; Sun, 28 Jan 2024 13:14:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706476446; cv=none; d=google.com; s=arc-20160816; b=UDJi/bXCPz4BYNI1maPd9d2U5Xf45ICterW9botwRsxJ+BhzTh4C40T80ZjDV5stsg ILTSG5MaEYUaruzt3HmIbRXd0mAen0hRhbX0kJM/usXpRPHXKnqhKJ/8jYXMR3QkI9pL 1I0s8HaLRG5Vhb/cfYipAgcb4fUkbF2gCcR/6XtULgRr7n1HOc8zBBr4cbsvbFchRlIL 8YCj589/EmuCv6R8ed7kJuufMDMs2rANAeL829ScnJqfm6wb1Y6/wrVadBOaJkEw4la3 4Zhf7GcuVuYBXiE3U61ezxa7CMvHBHMPS3ah2PZXwv46DyNMqt9XG899sF5OElXIAgqk LqeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=i0hM6WJI+fkbxaKKS7b32umTaykPqQ3SorXect9Qa/w=; fh=4o9WedBEbOrq7GvNs0s+TOKeyzmDZRM3O7oe6ZP6vYM=; b=nnJn6jP5AvlVdGmEWNhI7zM9opBkqiLDGxOvYWhhb0jRrCNm2lPDHfDlfROda83Llw tpKFL6fvXsNl7mg2hhr06ZOKJER1kMZSq26pdEMy77W79MHrBSBQhHCADoKDu0SOC2RA Sd8AjxddVEp4jGY9OMtUQZxdHsPlKlcVEzqy3gRKx4S6sttqSeE1Bu+cZ28KskJ37pOL eHUvvovGEU1uN3xgV7rOYet98vGbOVEYJTnLHVBvzJQPzB4yMk6Rw1Wfy97axVNi8gag UDqCTFv7NSR0Om3cHMSzp0JY432egFpQQ8VKBF90g9eM0AFNK3QUmIPCj7s9KihVdt6s 5w/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=ZHbR1uES; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dg13-20020a0564021d0d00b0055c2fd2bcadsi2815150edb.181.2024.01.28.13.14.06; Sun, 28 Jan 2024 13:14:06 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=ZHbR1uES; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 113AE68D188; Sun, 28 Jan 2024 23:14:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8C50868CD8E for ; Sun, 28 Jan 2024 23:13:56 +0200 (EET) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1d7881b1843so19336335ad.3 for ; Sun, 28 Jan 2024 13:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706476434; x=1707081234; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Otr4qS2WLEtLaBHUi1kLl0wD/9DrWiKuMNhjootbytg=; b=ZHbR1uES6Z0ILzOAn+J0UOoeZ2Revj8xXto9KNlKpmrqS8I6RV07QRAEVfM36iUWJx FWD4GEwO7iQynSj/xJ8dvYgLHc+3WCPAZriWP/juMdOtWfrH+UTI1KTTF0VvhQrjhyfg IQaYWFDSo3ZrmskRrvNgABHoNtprvV4KdWxgy9S5Ze4iiBccOHJzKELtcWybyaZtK+Ph MEFRSq8j6n/vrfWYhzGGd+ofHNREqfAA0tdPrD3JpycI+pxYvAXu6qbmyEAlSXfbhZYI xQWUA7+dPuL6NslRMgaWgx+dE/xkNR+rfV1+WPVea59WzhZaihPwRIjl6nDZsLQqsUPG yFgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706476434; x=1707081234; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Otr4qS2WLEtLaBHUi1kLl0wD/9DrWiKuMNhjootbytg=; b=pqhnxkw2bss7YIKNNiZbx2+0xhRfPtseFtjBPCResiS9GuQEXjFtp7HfNxVOYlj2U6 9gXdSFitXlUDtCg82S4yFKS498pp1pTFOpyAa0pLst/rTO89f1OLe82A8VxtIih+1HIh yJMkTngBJN/aF6OTF8firdSlr48TxntlqgkgNO0U0O+/pXWlSRipvX5xyDPC/ALPxzyE x0bL6WDX8RHv2DrZqLPjN/ozbGw2SFIY+ejd+DQTbse/rU7JLoGdmy8RP6yJawpHVy6h VDhlqJo15DgnirOyCNGF6yTWPcQjNqteKdpqyQoH7OnNb7Xus3W5m04VHWtz6Q4V0lcS orQQ== X-Gm-Message-State: AOJu0YzzCG1ANeZYRjbeH/FeXlwOE94DSTbudEUpWUsP1wmsv1RClA9g murYq6eC6retfuF1ja7CEfRPfu7yJ7pKYFpnVhWxu5h1L+IDjvIZ6rz/8/4EFC8= X-Received: by 2002:a17:902:d501:b0:1d8:e079:ce16 with SMTP id b1-20020a170902d50100b001d8e079ce16mr1110715plg.1.1706476433664; Sun, 28 Jan 2024 13:13:53 -0800 (PST) Received: from localhost ([2601:647:4600:84e0:cd8b:a23d:3457:1538]) by smtp.gmail.com with UTF8SMTPSA id ns1-20020a17090b250100b0028e821155efsm6892076pjb.46.2024.01.28.13.13.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 28 Jan 2024 13:13:53 -0800 (PST) From: Connor Worley To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Jan 2024 13:13:33 -0800 Message-Id: <20240128211335.58631-1-connorbworley@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavc/dxv: move tag definitions to common header 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 Cc: Connor Worley Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: RVWHdmEEP9Bc Signed-off-by: Connor Worley --- libavcodec/dxv.c | 9 +++++---- libavcodec/dxv.h | 34 ++++++++++++++++++++++++++++++++++ libavcodec/dxvenc.c | 7 ++----- 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 libavcodec/dxv.h diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index 5923811b29..a2ae070984 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -28,6 +28,7 @@ #include "avcodec.h" #include "bytestream.h" #include "codec_internal.h" +#include "dxv.h" #include "lzf.h" #include "texturedsp.h" #include "thread.h" @@ -1064,7 +1065,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, tag = bytestream2_get_le32(gbc); switch (tag) { - case MKBETAG('D', 'X', 'T', '1'): + case DXV_FMT_DXT1: decompress_tex = dxv_decompress_dxt1; ctx->tex_funct = ctx->texdsp.dxt1_block; ctx->tex_rat = 8; @@ -1072,7 +1073,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, msgcomp = "DXTR1"; msgtext = "DXT1"; break; - case MKBETAG('D', 'X', 'T', '5'): + case DXV_FMT_DXT5: decompress_tex = dxv_decompress_dxt5; ctx->tex_funct = ctx->texdsp.dxt5_block; ctx->tex_rat = 4; @@ -1080,7 +1081,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, msgcomp = "DXTR5"; msgtext = "DXT5"; break; - case MKBETAG('Y', 'C', 'G', '6'): + case DXV_FMT_YCG6: decompress_tex = dxv_decompress_ycg6; ctx->tex_funct_planar[0] = yo_block; ctx->tex_funct_planar[1] = cocg_block; @@ -1097,7 +1098,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, avctx->pix_fmt = AV_PIX_FMT_YUV420P; avctx->colorspace = AVCOL_SPC_YCOCG; break; - case MKBETAG('Y', 'G', '1', '0'): + case DXV_FMT_YG10: decompress_tex = dxv_decompress_yg10; ctx->tex_funct_planar[0] = yao_block; ctx->tex_funct_planar[1] = cocg_block; diff --git a/libavcodec/dxv.h b/libavcodec/dxv.h new file mode 100644 index 0000000000..71cfddec85 --- /dev/null +++ b/libavcodec/dxv.h @@ -0,0 +1,34 @@ +/* + * Resolume DXV common + * Copyright (C) 2024 Connor Worley + * + * 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 + */ + +#ifndef AVCODEC_DXV_H +#define AVCODEC_DXV_H + +#include "libavutil/macros.h" + +typedef enum DXVTextureFormat { + DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'), + DXV_FMT_DXT5 = MKBETAG('D', 'X', 'T', '5'), + DXV_FMT_YCG6 = MKBETAG('Y', 'C', 'G', '6'), + DXV_FMT_YG10 = MKBETAG('Y', 'G', '1', '0'), +} DXVTextureFormat; + +#endif /* AVCODEC_DXV_H */ diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c index b274175689..6a67dd75d4 100644 --- a/libavcodec/dxvenc.c +++ b/libavcodec/dxvenc.c @@ -27,6 +27,7 @@ #include "bytestream.h" #include "codec_internal.h" +#include "dxv.h" #include "encode.h" #include "texturedsp.h" @@ -40,10 +41,6 @@ #define LOOKBACK_HT_ELEMS 0x40000 #define LOOKBACK_WORDS 0x20202 -enum DXVTextureFormat { - DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'), -}; - typedef struct HTEntry { uint32_t key; uint32_t pos; @@ -120,7 +117,7 @@ typedef struct DXVEncContext { TextureDSPThreadContext enc; - enum DXVTextureFormat tex_fmt; + DXVTextureFormat tex_fmt; int (*compress_tex)(AVCodecContext *avctx); const AVCRC *crc_ctx; From patchwork Sun Jan 28 21:13:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Connor Worley X-Patchwork-Id: 45872 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp1196194pzb; Sun, 28 Jan 2024 13:14:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IElH7BtqCNdAW2CzVwrdhbqIZ5r0U9TJtO0fmkqSYiBWdY2KoL5Qx6opRulxk/FyXMZyI5Z X-Received: by 2002:a17:906:71db:b0:a30:33bd:b588 with SMTP id i27-20020a17090671db00b00a3033bdb588mr3495888ejk.25.1706476456752; Sun, 28 Jan 2024 13:14:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706476456; cv=none; d=google.com; s=arc-20160816; b=e9Jk1y8rNVwWFM5v9iYT5JcyKNHRhtCs0nyUDv0rQEurSj5VucyOzbps7DU3j9/7xP ybt9d4tS2KIt4VCMMN5CLUpHymB0gtAQn+7iQCYPkGlDJXN+qBrSn6VkJUjSiLp+MjT/ hUDDgaCvvfMW6KOPkZgMm6geITuF84Zir/6I+/m4QtwjBIjai61V/RP7ImU9iT5Owjp4 VyATVpmNgD1t78b7N4elo46FBwJj1XDQXcJSM67bNdsL3iYFy+9Xr/0ag6ZhO0HyT83Y dqA7JhG097dQjKK8kg4sQe2RmTyFLFRgd5qyJhIVSGr2Qj06Um+T8++02dSdzGvdEyG7 yqQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=92Jd9oIA6OuijLwk1XZ/ggl2qEoNcMMOcOqFGMFHYSk=; fh=4o9WedBEbOrq7GvNs0s+TOKeyzmDZRM3O7oe6ZP6vYM=; b=f5vtf+Sn41/Db8ZjYA0KMXpM8SIEmlUyUBDgktGN9+hiOrvuGCcwLOhSTY+xeRhXm1 YerTEucMDdl1ke0X3CrZO2IlJN5vzZZMvNSrrphexMZ6RizSd6hP5PIKDiKR7/mUFjo+ /SeyW8RP2pbkuZNMau1iQ2qgAmZCcFEMPKXov6W4aXkGWyw7PU2DC70+2Az904txFMoX 3LxRdO3mSolmdpwY67jln5VPNAtC9lUllpos/Lj2IaQ59hxFB4LXZIqqhu8zo8N7YRHA 0KIIB3DnjFwuqFXSg66TCo5tetrCToS2Vup1ykswjwAuymUeYMN3VEJ4H8o8LKicE3vW MurA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="I9rIK/WM"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e11-20020a170906374b00b00a2ace215a7esi2785003ejc.731.2024.01.28.13.14.16; Sun, 28 Jan 2024 13:14:16 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="I9rIK/WM"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5DF9768D194; Sun, 28 Jan 2024 23:14:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5510768D18E for ; Sun, 28 Jan 2024 23:14:05 +0200 (EET) Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-290ec261a61so981662a91.0 for ; Sun, 28 Jan 2024 13:14:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706476442; x=1707081242; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vX2s3z6lfqPDisQwpKQZF6FKPfZEFSjBdEMgj846u3Y=; b=I9rIK/WMMY0FidXAA5TRpZ/2jfTW0YL6IpefwbkyPsC8JhABStWEkc4u4GdulyMNlS 20+TN3RwbQJVaPt/zZ4o37+fhQexPEuaSGeyIlGrAwMOiqVOfy9D0J8CvO5f7nOjFTS+ +GAVCXdHL7tkB+GFKQ1EqtnIwzraKWli0nB9kitizTe/cp+91nKeNKkfYtOlV9AYB5C9 alRrqrv60ekG+8YTm1tH1LkihHwsf9TwLW/GbPnD9F6AmI4lQpMBzScn6bqRp7LKfd67 qGhkDDqhWTJaWlF7TEJZRKatN5+bShkVy8zCqEL8Wi3Pjw8dXOZClazGS1qfH0engcWg +Nrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706476442; x=1707081242; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vX2s3z6lfqPDisQwpKQZF6FKPfZEFSjBdEMgj846u3Y=; b=tk1CMir1+IJmsjpkJDNcYj1YkGmeiOE/qSzqlTYJd7RlYJ10rfsPoglH45dWg/gCXl H4sx/Q6mVXxsOVg03HL8iYWtD6+Pd/agndtGBAaSG66V31AFAO1mmfqY6PO/j688ii8F Cqtulg5GFJS56i/mYnb/73AigfuRqu8eKh2FhGyOuHHBSQgpbNru9XYFGSTlELFTTdfg 4GjAnLpCucnYslsYpkjfckfmU+gI/TGaoMDRFFIgfVkxg3v/Yh2R6/O8HjeLWWv7CKLs Uri+kZXgDNZmeh9Kzr6O5iMDsskhRdujBsxj05FO8t9Pd7B1OO0eN9Fd7JTe+APhdFh2 FQ1g== X-Gm-Message-State: AOJu0YxPzi+R3r22xb3eT2wBDyUaJI5p+2b7+GU6GWayhomq1SRD0Ca/ 4E5gIoYjSshLeMExZ9OrbW/N9xh49ZXhHt9smX4/AGNM6XJeJPxh/2XePEyRXak= X-Received: by 2002:a17:90a:fb51:b0:28f:eeda:e9ad with SMTP id iq17-20020a17090afb5100b0028feedae9admr2021161pjb.28.1706476442166; Sun, 28 Jan 2024 13:14:02 -0800 (PST) Received: from localhost ([2601:647:4600:84e0:cd8b:a23d:3457:1538]) by smtp.gmail.com with UTF8SMTPSA id p3-20020a17090a348300b0028aea6c24bcsm7497374pjb.53.2024.01.28.13.14.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 28 Jan 2024 13:14:01 -0800 (PST) From: Connor Worley To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Jan 2024 13:13:34 -0800 Message-Id: <20240128211335.58631-2-connorbworley@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240128211335.58631-1-connorbworley@gmail.com> References: <20240128211335.58631-1-connorbworley@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] lavc/dvx: use texdsp funcs for texture block decompression 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 Cc: Connor Worley Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HDpe5dA0jFGl Signed-off-by: Connor Worley --- libavcodec/dxv.c | 289 ++++++++++++----------------------------------- 1 file changed, 75 insertions(+), 214 deletions(-) diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index a2ae070984..cae5d8a92f 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -38,15 +38,12 @@ typedef struct DXVContext { GetByteContext gbc; uint8_t *tex_data; // Compressed texture - uint8_t *ctex_data; // Compressed texture + uint8_t *ctex_data; // Compressed chroma texture int tex_rat; // Compression ratio int tex_step; // Distance between blocks int ctex_step; // Distance between blocks int64_t tex_size; // Texture size - int64_t ctex_size; // Texture size - - /* Optimal number of slices for parallel decoding */ - int slice_count; + int64_t ctex_size; // Chroma texture size uint8_t *op_data[4]; // Opcodes int64_t op_size[4]; // Opcodes size @@ -56,198 +53,8 @@ typedef struct DXVContext { int ctexture_block_w; int ctexture_block_h; - - /* Pointer to the selected decompression function */ - int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block); - int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0, - uint8_t *plane1, ptrdiff_t stride1, - const uint8_t *block); } DXVContext; -static void decompress_indices(uint8_t *dst, const uint8_t *src) -{ - int block, i; - - for (block = 0; block < 2; block++) { - int tmp = AV_RL24(src); - - /* Unpack 8x3 bit from last 3 byte block */ - for (i = 0; i < 8; i++) - dst[i] = (tmp >> (i * 3)) & 0x7; - - src += 3; - dst += 8; - } -} - -static int extract_component(int yo0, int yo1, int code) -{ - int yo; - - if (yo0 == yo1) { - yo = yo0; - } else if (code == 0) { - yo = yo0; - } else if (code == 1) { - yo = yo1; - } else { - if (yo0 > yo1) { - yo = (uint8_t) (((8 - code) * yo0 + - (code - 1) * yo1) / 7); - } else { - if (code == 6) { - yo = 0; - } else if (code == 7) { - yo = 255; - } else { - yo = (uint8_t) (((6 - code) * yo0 + - (code - 1) * yo1) / 5); - } - } - } - - return yo; -} - -static int cocg_block(uint8_t *plane0, ptrdiff_t stride0, - uint8_t *plane1, ptrdiff_t stride1, - const uint8_t *block) -{ - uint8_t co_indices[16]; - uint8_t cg_indices[16]; - uint8_t co0 = *(block); - uint8_t co1 = *(block + 1); - uint8_t cg0 = *(block + 8); - uint8_t cg1 = *(block + 9); - int x, y; - - decompress_indices(co_indices, block + 2); - decompress_indices(cg_indices, block + 10); - - for (y = 0; y < 4; y++) { - for (x = 0; x < 4; x++) { - int co_code = co_indices[x + y * 4]; - int cg_code = cg_indices[x + y * 4]; - - plane0[x] = extract_component(cg0, cg1, cg_code); - plane1[x] = extract_component(co0, co1, co_code); - } - plane0 += stride0; - plane1 += stride1; - } - - return 16; -} - -static void yao_subblock(uint8_t *dst, uint8_t *yo_indices, - ptrdiff_t stride, const uint8_t *block) -{ - uint8_t yo0 = *(block); - uint8_t yo1 = *(block + 1); - int x, y; - - decompress_indices(yo_indices, block + 2); - - for (y = 0; y < 4; y++) { - for (x = 0; x < 4; x++) { - int yo_code = yo_indices[x + y * 4]; - - dst[x] = extract_component(yo0, yo1, yo_code); - } - dst += stride; - } -} - -static int yo_block(uint8_t *dst, ptrdiff_t stride, - uint8_t *unused0, ptrdiff_t unused1, - const uint8_t *block) -{ - uint8_t yo_indices[16]; - - yao_subblock(dst, yo_indices, stride, block); - yao_subblock(dst + 4, yo_indices, stride, block + 8); - yao_subblock(dst + 8, yo_indices, stride, block + 16); - yao_subblock(dst + 12, yo_indices, stride, block + 24); - - return 32; -} - -static int yao_block(uint8_t *plane0, ptrdiff_t stride0, - uint8_t *plane3, ptrdiff_t stride1, - const uint8_t *block) -{ - uint8_t yo_indices[16]; - uint8_t a_indices[16]; - - yao_subblock(plane0, yo_indices, stride0, block); - yao_subblock(plane3, a_indices, stride1, block + 8); - yao_subblock(plane0 + 4, yo_indices, stride0, block + 16); - yao_subblock(plane3 + 4, a_indices, stride1, block + 24); - yao_subblock(plane0 + 8, yo_indices, stride0, block + 32); - yao_subblock(plane3 + 8, a_indices, stride1, block + 40); - yao_subblock(plane0 + 12, yo_indices, stride0, block + 48); - yao_subblock(plane3 + 12, a_indices, stride1, block + 56); - - return 64; -} - -static int decompress_texture_thread(AVCodecContext *avctx, void *arg, - int slice, int thread_nb) -{ - const DXVContext *ctx = avctx->priv_data; - AVFrame *frame = arg; - const uint8_t *d = ctx->tex_data; - int w_block = avctx->coded_width / ctx->texture_block_w; - int h_block = avctx->coded_height / ctx->texture_block_h; - int x, y; - int start_slice, end_slice; - - start_slice = h_block * slice / ctx->slice_count; - end_slice = h_block * (slice + 1) / ctx->slice_count; - - if (ctx->tex_funct) { - for (y = start_slice; y < end_slice; y++) { - uint8_t *p = frame->data[0] + y * frame->linesize[0] * ctx->texture_block_h; - int off = y * w_block; - for (x = 0; x < w_block; x++) { - ctx->tex_funct(p + x * 4 * ctx->texture_block_w, frame->linesize[0], - d + (off + x) * ctx->tex_step); - } - } - } else { - const uint8_t *c = ctx->ctex_data; - - for (y = start_slice; y < end_slice; y++) { - uint8_t *p0 = frame->data[0] + y * frame->linesize[0] * ctx->texture_block_h; - uint8_t *p3 = ctx->tex_step != 64 ? NULL : frame->data[3] + y * frame->linesize[3] * ctx->texture_block_h; - int off = y * w_block; - for (x = 0; x < w_block; x++) { - ctx->tex_funct_planar[0](p0 + x * ctx->texture_block_w, frame->linesize[0], - p3 != NULL ? p3 + x * ctx->texture_block_w : NULL, frame->linesize[3], - d + (off + x) * ctx->tex_step); - } - } - - w_block = (avctx->coded_width / 2) / ctx->ctexture_block_w; - h_block = (avctx->coded_height / 2) / ctx->ctexture_block_h; - start_slice = h_block * slice / ctx->slice_count; - end_slice = h_block * (slice + 1) / ctx->slice_count; - - for (y = start_slice; y < end_slice; y++) { - uint8_t *p0 = frame->data[1] + y * frame->linesize[1] * ctx->ctexture_block_h; - uint8_t *p1 = frame->data[2] + y * frame->linesize[2] * ctx->ctexture_block_h; - int off = y * w_block; - for (x = 0; x < w_block; x++) { - ctx->tex_funct_planar[1](p0 + x * ctx->ctexture_block_w, frame->linesize[1], - p1 + x * ctx->ctexture_block_w, frame->linesize[2], - c + (off + x) * ctx->ctex_step); - } - } - } - - return 0; -} - /* This scheme addresses already decoded elements depending on 2-bit status: * 0 -> copy new element * 1 -> copy one element from position -x @@ -1044,6 +851,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, { DXVContext *ctx = avctx->priv_data; GetByteContext *gbc = &ctx->gbc; + AVCodecContext cavctx = *avctx; + TextureDSPThreadContext texdsp_ctx, ctexdsp_ctx; int (*decompress_tex)(AVCodecContext *avctx); const char *msgcomp, *msgtext; uint32_t tag; @@ -1053,21 +862,22 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, bytestream2_init(gbc, avpkt->data, avpkt->size); + cavctx.coded_height = avctx->coded_height / 2; + cavctx.coded_width = avctx->coded_width / 2; + ctx->texture_block_h = 4; ctx->texture_block_w = 4; avctx->pix_fmt = AV_PIX_FMT_RGBA; avctx->colorspace = AVCOL_SPC_RGB; - ctx->tex_funct = NULL; - ctx->tex_funct_planar[0] = NULL; - ctx->tex_funct_planar[1] = NULL; - tag = bytestream2_get_le32(gbc); switch (tag) { case DXV_FMT_DXT1: decompress_tex = dxv_decompress_dxt1; - ctx->tex_funct = ctx->texdsp.dxt1_block; + texdsp_ctx.tex_funct = ctx->texdsp.dxt1_block; + texdsp_ctx.tex_ratio = 8; + texdsp_ctx.raw_ratio = 16; ctx->tex_rat = 8; ctx->tex_step = 8; msgcomp = "DXTR1"; @@ -1075,7 +885,9 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, break; case DXV_FMT_DXT5: decompress_tex = dxv_decompress_dxt5; - ctx->tex_funct = ctx->texdsp.dxt5_block; + texdsp_ctx.tex_funct = ctx->texdsp.dxt5_block; + texdsp_ctx.tex_ratio = 16; + texdsp_ctx.raw_ratio = 16; ctx->tex_rat = 4; ctx->tex_step = 16; msgcomp = "DXTR5"; @@ -1083,8 +895,12 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, break; case DXV_FMT_YCG6: decompress_tex = dxv_decompress_ycg6; - ctx->tex_funct_planar[0] = yo_block; - ctx->tex_funct_planar[1] = cocg_block; + texdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block; + texdsp_ctx.tex_ratio = 8; + texdsp_ctx.raw_ratio = 4; + ctexdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block; + ctexdsp_ctx.tex_ratio = 16; + ctexdsp_ctx.raw_ratio = 4; ctx->tex_rat = 8; ctx->tex_step = 32; ctx->ctex_step = 16; @@ -1100,8 +916,12 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, break; case DXV_FMT_YG10: decompress_tex = dxv_decompress_yg10; - ctx->tex_funct_planar[0] = yao_block; - ctx->tex_funct_planar[1] = cocg_block; + texdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block; + texdsp_ctx.tex_ratio = 16; + texdsp_ctx.raw_ratio = 4; + ctexdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block; + ctexdsp_ctx.tex_ratio = 16; + ctexdsp_ctx.raw_ratio = 4; ctx->tex_rat = 4; ctx->tex_step = 64; ctx->ctex_step = 16; @@ -1130,14 +950,20 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, } if (old_type & 0x40) { + tag = DXV_FMT_DXT5; msgtext = "DXT5"; - ctx->tex_funct = ctx->texdsp.dxt5_block; + texdsp_ctx.tex_funct = ctx->texdsp.dxt5_block; + texdsp_ctx.tex_ratio = 16; + texdsp_ctx.raw_ratio = 16; ctx->tex_step = 16; } else if (old_type & 0x20 || version_major == 1) { + tag = DXV_FMT_DXT1; msgtext = "DXT1"; - ctx->tex_funct = ctx->texdsp.dxt1_block; + texdsp_ctx.tex_funct = ctx->texdsp.dxt1_block; + texdsp_ctx.tex_ratio = 8; + texdsp_ctx.raw_ratio = 16; ctx->tex_step = 8; } else { av_log(avctx, AV_LOG_ERROR, "Unsupported header (0x%08"PRIX32")\n.", tag); @@ -1147,10 +973,10 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, break; } - ctx->slice_count = av_clip(avctx->thread_count, 1, - avctx->coded_height / FFMAX(ctx->texture_block_h, - ctx->ctexture_block_h)); - + texdsp_ctx.slice_count = av_clip(avctx->thread_count, 1, + avctx->coded_height / TEXTURE_BLOCK_H); + ctexdsp_ctx.slice_count = av_clip(avctx->thread_count, 1, + cavctx.coded_height / TEXTURE_BLOCK_H); /* New header is 12 bytes long. */ if (!old_type) { version_major = bytestream2_get_byte(gbc) - 1; @@ -1215,9 +1041,44 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, if (ret < 0) return ret; - /* Now decompress the texture with the standard functions. */ - avctx->execute2(avctx, decompress_texture_thread, - frame, NULL, ctx->slice_count); + switch (tag) { + case DXV_FMT_YG10: + /* BC5 texture with alpha in the second half of each block */ + texdsp_ctx.tex_data.in = ctx->tex_data + texdsp_ctx.tex_ratio / 2; + texdsp_ctx.frame_data.out = frame->data[3]; + texdsp_ctx.stride = frame->linesize[3]; + ret = ff_texturedsp_exec_decompress_threads(avctx, &texdsp_ctx); + if (ret < 0) + return ret; + /* fallthrough */ + case DXV_FMT_YCG6: + /* BC5 texture with Co in the first half of each block and Cg in the second */ + ctexdsp_ctx.tex_data.in = ctx->ctex_data; + ctexdsp_ctx.frame_data.out = frame->data[2]; + ctexdsp_ctx.stride = frame->linesize[2]; + ret = ff_texturedsp_exec_decompress_threads(&cavctx, &ctexdsp_ctx); + if (ret < 0) + return ret; + ctexdsp_ctx.tex_data.in = ctx->ctex_data + ctexdsp_ctx.tex_ratio / 2; + ctexdsp_ctx.frame_data.out = frame->data[1]; + ctexdsp_ctx.stride = frame->linesize[1]; + ret = ff_texturedsp_exec_decompress_threads(&cavctx, &ctexdsp_ctx); + if (ret < 0) + return ret; + /* fallthrough */ + case DXV_FMT_DXT1: + case DXV_FMT_DXT5: + /* For DXT1 and DXT5, self explanatory + * For YCG6, BC4 texture for Y + * For YG10, BC5 texture with Y in the first half of each block */ + texdsp_ctx.tex_data.in = ctx->tex_data; + texdsp_ctx.frame_data.out = frame->data[0]; + texdsp_ctx.stride = frame->linesize[0]; + ret = ff_texturedsp_exec_decompress_threads(avctx, &texdsp_ctx); + if (ret < 0) + return ret; + break; + } /* Frame is ready to be output. */ frame->pict_type = AV_PICTURE_TYPE_I; From patchwork Sun Jan 28 21:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Connor Worley X-Patchwork-Id: 45873 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp1196243pzb; Sun, 28 Jan 2024 13:14:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHUAd/VO7mwino+iq+FHikFR8N+adegX3hCRkZ4ErtK8qMoKGZ5XuMIAdMYuzMA4TMJKgv2 X-Received: by 2002:a17:906:a013:b0:a34:d7db:1ae3 with SMTP id p19-20020a170906a01300b00a34d7db1ae3mr3554426ejy.1.1706476464840; Sun, 28 Jan 2024 13:14:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706476464; cv=none; d=google.com; s=arc-20160816; b=F0cV+CKNK+zdaPBtOXzJNs/Jdy9wICPxRS5SzusTiOLFYLs8HzQOfn+iehVwDwnSkx 4/EGLfe0+8hU7ZMRfakFrCS2lMpGb0jaAlPnpA/qY46c03O5zB2Y6xQx5C6hZG/foLFT 6vv7bVlu3wlIzHPJzxZ9uWcKFQjwnrHD0ZkO1mr8fUWp3ZXo5qdOigiAwG4b/EqNNrOz gpVEgKhFaEcex3ODLAdw/uFQvCn/W5Wzm/fO8aVXxghKF0y9mQ06hIvU2hoWFy3p4x6j Ibr8UOylmKHj8vbIVfurZVLBvfWWpuY0C2met+ADQB9pyyKZDzjGM7Y8wAK7UkesPjL1 MQ1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=LwzvG+LF8ppMDAUfVam32/h0hwq2RvNDZLg4yH5VebY=; fh=4o9WedBEbOrq7GvNs0s+TOKeyzmDZRM3O7oe6ZP6vYM=; b=b+3DGwkFIPyZ5E0quwNmrTScrMpEPq/Fv+mGu3yRsaVoY9E/LvRPcYFB6eqLMJYjLk fG29sOXiEvl1OuyoUPpBYtYCRNrV5WErM3pJgBY9wLYAsDW53+ZQeKj26zRc1W6QAoES 4Ntz15og9ak+SJ9j9LybPUvcR4CQYvYFGmjeIQBOiLRgmUXRb6T8oIgU3qe57huRt5e1 WikEXfQTBcU7ZLFmqLjxBseZ0HQCt1CutqDrF5BShRnZz8azVoLwMtgFHq4Hh9vNY9OJ TxN8JFPFZk0TLocPu297badnVNLIwNREK1cjxpdPhEsHb1GL2W5Z+tZ5iez77m2sGTOP pUeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=CUt6VmAr; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b22-20020a1709062b5600b00a318b87e8b9si3004784ejg.577.2024.01.28.13.14.24; Sun, 28 Jan 2024 13:14:24 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=CUt6VmAr; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8095868D19A; Sun, 28 Jan 2024 23:14:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6000468D192 for ; Sun, 28 Jan 2024 23:14:10 +0200 (EET) Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-29065efa06fso1850407a91.1 for ; Sun, 28 Jan 2024 13:14:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706476448; x=1707081248; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z0jjvGHejTKv0TDfziM8o+3xGM8byfrM+/B21SqQXK8=; b=CUt6VmArZoXa7PIkIscCnuH0SGoE8YaRvrayYEKtwzHO6qqU7Cw1yiewEcl+lNzEBE N6sCixaTyzyBKMrO0cyrewQ3GfeJccTab38UTpBvqrLCxx7zThRMD936jfzaom6SWzkx 02EtOUeSut7teoe6ayoU4PiaZkeQIg9BWP/ZZ/QmS5QULR8/hl4f4LnaxemtE/kkeehJ LVqFMvEHpW3PG5KbtgiUjgubyO6aZL5ehz8pzAfeob/8fcp7GjI8835bNgGSfMxMWMzl LOdA9AXH1mOFL5xBxiEIPaQXsLRh0jhB7W4phZbs8JVf4NIzRjOFdewI9zQ52ipvcifj WMDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706476448; x=1707081248; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z0jjvGHejTKv0TDfziM8o+3xGM8byfrM+/B21SqQXK8=; b=v0GySdlJu2W33leXF/GfXcsUAfgi06+G0zy9WVjgPi1aqhVYUqRu+2Ah9S2bkoIvRy QAKrgz16BgnKwXKJ86zRYn8WRrfKY+CWecZkJSu611aVGHkKVKlg2+TTWh6YVkJbjb6V 0nCcpbZdFQi0QdU8qYs9l+O89zvnfHVOmqkTpEfm80gT4mXGznQQf4QXF6tbWn9L7gxj k8HzW/7TDFMK8N38IyxGCiLoqu9C0J9P7raENvdNIWTRV43dfph69BYLR0+3FqhbrQJk ZYBTstD5xis0LqCmW4fLcFCt/sDbbaZ7Rh4ATDz0j9Vo5QlY1XayH8O2tvRb5kfEQ32C uBTQ== X-Gm-Message-State: AOJu0YxQsPQ5w07uBs7EaJTIuFbLUrxjkQf/Jdeg16EVTom50d+D5SBq N9iTNDPtr88ajUcsbevCmtJX+Kb078rm9LOt3g7k4USN6ZrHCeZtaxJNOkLqTkY= X-Received: by 2002:a17:90b:1253:b0:290:c2cd:6aac with SMTP id gx19-20020a17090b125300b00290c2cd6aacmr2289516pjb.6.1706476448157; Sun, 28 Jan 2024 13:14:08 -0800 (PST) Received: from localhost ([2601:647:4600:84e0:cd8b:a23d:3457:1538]) by smtp.gmail.com with UTF8SMTPSA id pl14-20020a17090b268e00b002906a444b2esm4773398pjb.7.2024.01.28.13.14.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 28 Jan 2024 13:14:07 -0800 (PST) From: Connor Worley To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Jan 2024 13:13:35 -0800 Message-Id: <20240128211335.58631-3-connorbworley@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240128211335.58631-1-connorbworley@gmail.com> References: <20240128211335.58631-1-connorbworley@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavc/dxv: remove ctx fields that can be derived from texdsp ctxs 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 Cc: Connor Worley Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: TVngmRO4pZoo Signed-off-by: Connor Worley --- libavcodec/dxv.c | 53 ++++++++---------------------------------------- 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index cae5d8a92f..b29adf8ad9 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -39,20 +39,12 @@ typedef struct DXVContext { uint8_t *tex_data; // Compressed texture uint8_t *ctex_data; // Compressed chroma texture - int tex_rat; // Compression ratio - int tex_step; // Distance between blocks - int ctex_step; // Distance between blocks + int64_t tex_size; // Texture size int64_t ctex_size; // Chroma texture size uint8_t *op_data[4]; // Opcodes int64_t op_size[4]; // Opcodes size - - int texture_block_w; - int texture_block_h; - - int ctexture_block_w; - int ctexture_block_h; } DXVContext; /* This scheme addresses already decoded elements depending on 2-bit status: @@ -865,9 +857,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, cavctx.coded_height = avctx->coded_height / 2; cavctx.coded_width = avctx->coded_width / 2; - ctx->texture_block_h = 4; - ctx->texture_block_w = 4; - avctx->pix_fmt = AV_PIX_FMT_RGBA; avctx->colorspace = AVCOL_SPC_RGB; @@ -878,8 +867,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, texdsp_ctx.tex_funct = ctx->texdsp.dxt1_block; texdsp_ctx.tex_ratio = 8; texdsp_ctx.raw_ratio = 16; - ctx->tex_rat = 8; - ctx->tex_step = 8; msgcomp = "DXTR1"; msgtext = "DXT1"; break; @@ -888,8 +875,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, texdsp_ctx.tex_funct = ctx->texdsp.dxt5_block; texdsp_ctx.tex_ratio = 16; texdsp_ctx.raw_ratio = 16; - ctx->tex_rat = 4; - ctx->tex_step = 16; msgcomp = "DXTR5"; msgtext = "DXT5"; break; @@ -901,16 +886,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, ctexdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block; ctexdsp_ctx.tex_ratio = 16; ctexdsp_ctx.raw_ratio = 4; - ctx->tex_rat = 8; - ctx->tex_step = 32; - ctx->ctex_step = 16; msgcomp = "YOCOCG6"; msgtext = "YCG6"; - ctx->ctex_size = avctx->coded_width * avctx->coded_height / 4; - ctx->texture_block_h = 4; - ctx->texture_block_w = 16; - ctx->ctexture_block_h = 4; - ctx->ctexture_block_w = 4; avctx->pix_fmt = AV_PIX_FMT_YUV420P; avctx->colorspace = AVCOL_SPC_YCOCG; break; @@ -922,16 +899,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, ctexdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block; ctexdsp_ctx.tex_ratio = 16; ctexdsp_ctx.raw_ratio = 4; - ctx->tex_rat = 4; - ctx->tex_step = 64; - ctx->ctex_step = 16; msgcomp = "YAOCOCG10"; msgtext = "YG10"; - ctx->ctex_size = avctx->coded_width * avctx->coded_height / 4; - ctx->texture_block_h = 4; - ctx->texture_block_w = 16; - ctx->ctexture_block_h = 4; - ctx->ctexture_block_w = 4; avctx->pix_fmt = AV_PIX_FMT_YUVA420P; avctx->colorspace = AVCOL_SPC_YCOCG; break; @@ -956,7 +925,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, texdsp_ctx.tex_funct = ctx->texdsp.dxt5_block; texdsp_ctx.tex_ratio = 16; texdsp_ctx.raw_ratio = 16; - ctx->tex_step = 16; } else if (old_type & 0x20 || version_major == 1) { tag = DXV_FMT_DXT1; msgtext = "DXT1"; @@ -964,12 +932,10 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, texdsp_ctx.tex_funct = ctx->texdsp.dxt1_block; texdsp_ctx.tex_ratio = 8; texdsp_ctx.raw_ratio = 16; - ctx->tex_step = 8; } else { av_log(avctx, AV_LOG_ERROR, "Unsupported header (0x%08"PRIX32")\n.", tag); return AVERROR_INVALIDDATA; } - ctx->tex_rat = 1; break; } @@ -985,7 +951,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, /* Encoder copies texture data when compression is not advantageous. */ if (bytestream2_get_byte(gbc)) { msgcomp = "RAW"; - ctx->tex_rat = 1; decompress_tex = dxv_decompress_raw; } @@ -1003,14 +968,20 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, return AVERROR_INVALIDDATA; } - ctx->tex_size = avctx->coded_width * avctx->coded_height * 4 / ctx->tex_rat; + ctx->tex_size = avctx->coded_width / (texdsp_ctx.raw_ratio / (avctx->pix_fmt == AV_PIX_FMT_RGBA ? 4 : 1)) * + avctx->coded_height / TEXTURE_BLOCK_H * + texdsp_ctx.tex_ratio; ret = av_reallocp(&ctx->tex_data, ctx->tex_size + AV_INPUT_BUFFER_PADDING_SIZE); if (ret < 0) return ret; - if (ctx->ctex_size) { + if (avctx->pix_fmt != AV_PIX_FMT_RGBA) { int i; + ctx->ctex_size = cavctx.coded_width / ctexdsp_ctx.raw_ratio * + cavctx.coded_height / TEXTURE_BLOCK_H * + ctexdsp_ctx.tex_ratio; + ctx->op_size[0] = avctx->coded_width * avctx->coded_height / 16; ctx->op_size[1] = avctx->coded_width * avctx->coded_height / 32; ctx->op_size[2] = avctx->coded_width * avctx->coded_height / 32; @@ -1030,12 +1001,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, ret = decompress_tex(avctx); if (ret < 0) return ret; - { - int w_block = avctx->coded_width / ctx->texture_block_w; - int h_block = avctx->coded_height / ctx->texture_block_h; - if (w_block * h_block * ctx->tex_step > ctx->tex_size * 8LL) - return AVERROR_INVALIDDATA; - } ret = ff_thread_get_buffer(avctx, frame, 0); if (ret < 0)