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 6FBF2481C4 for ; Sat, 10 Feb 2024 22:59:25 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BB06F68CC0A; Sun, 11 Feb 2024 00:59:20 +0200 (EET) Received: from mail-il1-f172.google.com (mail-il1-f172.google.com [209.85.166.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D3FC168CC0A for ; Sun, 11 Feb 2024 00:59:13 +0200 (EET) Received: by mail-il1-f172.google.com with SMTP id e9e14a558f8ab-363b2cc93a8so8640035ab.3 for ; Sat, 10 Feb 2024 14:59:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707605951; x=1708210751; 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=p1vWykqwbo2LTeibXK9y3I6SUUGt+5YByOIgxRR5EXU=; b=IaFFnTOYZNG9zM0wO5QQUytmCnxwlp38CWC0U7KMf/6tdXMQXxWRyM6bikYr6dd3bN IGkUbMwxxSLyHUUY02PD++IEzV+bLYU30kDb7NExcDTAUJddHBxFM4LYeZ75k3Ip/a45 +6bOWJxV83VcvRk8jEJwz9TP/ty/veJviZHe1bO/4BOifzwinxf8jyjwiRE0tZwCPdKG e4CyQagZ3s8dsnnUjx660r0AdhKY+vi12nSlfpSmKjNOmBxos+TZ4JoGt6+N5MrA1L+T MtKDO42QMGr+d/2f2dv2jVWTjI+C94XJpwKTQfAounzDiElfjO+d7tIrVMSla4/fpPog qtwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707605951; x=1708210751; 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=p1vWykqwbo2LTeibXK9y3I6SUUGt+5YByOIgxRR5EXU=; b=Nczat+BjDF0U+mipkELtY3/EEV2iTtkF58dZfMB3TjtfGOi1WGGxHQnqBXQz/ISPp8 K24dYqq+4lS3tmudIPsJH5HM+VF2LzWuZXpGc+Lm36MTGckAIyPhVMRnXYDic8eyvvAC jKvMSgyfeBUzfCeTNLUWIog3FouUtVSNSqenT4d25F6RaRCS+zlRDbgsNvhk2naHmA+n seaLqCM2ZZa6sWB+Dd4D2CIvdTmryrMzY57PrzGe5oX7YKlQNNRaQ1zPi1n6TnmEmQQp D4lsjN3YahrjCqV2Kqn9rsOC9UbDPpuGvz8LEf0QrDfVywa+FoaNNTpXGVsvq1fNFLPB 8qfg== X-Gm-Message-State: AOJu0YxGkFBFSbjX/5X4H9pnzrGcaOgImyKiIio5sA4XSoQhrq9DSbKF MKyHjH0nOCsn0GRtvVoXjLtJIEFS3iqRbovN+MvrCKjXdjAEkra4qyE9w9CX X-Google-Smtp-Source: AGHT+IHbjNloHqnRxlEn0kQ9hFaczxmnR6dJh0lCyYT4c2P3C2TvLqPkGKNhPtKnaXhZXGsRJKP4Yw== X-Received: by 2002:a92:c0c1:0:b0:363:b5eb:cc84 with SMTP id t1-20020a92c0c1000000b00363b5ebcc84mr3904879ilf.24.1707605951521; Sat, 10 Feb 2024 14:59:11 -0800 (PST) Received: from localhost (192-184-169-201.fiber.dynamic.sonic.net. [192.184.169.201]) by smtp.gmail.com with UTF8SMTPSA id y12-20020a170902ed4c00b001d71df54cdasm3448358plb.274.2024.02.10.14.59.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 10 Feb 2024 14:59:11 -0800 (PST) From: Connor Worley To: ffmpeg-devel@ffmpeg.org Date: Sat, 10 Feb 2024 14:58:47 -0800 Message-ID: <20240210225847.53228-3-connorbworley@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240210225847.53228-1-connorbworley@gmail.com> References: <20240210225847.53228-1-connorbworley@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 cd78de3e0d..82c493f1de 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; @@ -889,8 +876,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, texdsp_ctx.tex_funct = ctx->texdsp.dxt4_block; texdsp_ctx.tex_ratio = 16; texdsp_ctx.raw_ratio = 16; - ctx->tex_rat = 4; - ctx->tex_step = 16; msgcomp = "DXTR5"; msgtext = "DXT5"; break; @@ -902,16 +887,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; @@ -923,16 +900,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; @@ -957,7 +926,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"; @@ -965,12 +933,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; } @@ -986,7 +952,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; } @@ -1004,14 +969,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; @@ -1031,12 +1002,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) -- 2.43.0 _______________________________________________ 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".