From patchwork Fri Mar 24 22:10:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 40812 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4c12:b0:dd:c6d8:789a with SMTP id fm18csp797136pzb; Fri, 24 Mar 2023 15:11:00 -0700 (PDT) X-Google-Smtp-Source: AKy350Zf2Ib7Ac0GSRNBseFiS1k8jMas50uErrpc9V7dCbE6rqmp4UGi9UWFKf5qVJXnZkzR1wcH X-Received: by 2002:a05:6402:1389:b0:501:d3a0:30d9 with SMTP id b9-20020a056402138900b00501d3a030d9mr4264916edv.7.1679695860734; Fri, 24 Mar 2023 15:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679695860; cv=none; d=google.com; s=arc-20160816; b=dW/T6df4Igg1xDiqdFyMXCG2eiZ4NzD01YMrqQd5954isfhjHE2DyFwDQipZrrYxzM nER5O3WQBWmEKdpGjTO0LPExgvC3w1zIL3JDB/nlUy/+9puP7Km98dE8u5vRogZL2+It fsqLwbEY8h6Lf9rnFtygqpp3MwSBbBIU/DPtpXFGWSVx5iJZFX6GSApfSyLeauC7oMdo jo3M97FSTgdt356sKpYiYiaqBtaWt0Gud+gCahIIHjNNIFfc/h9Bvr22T01hNOZNfgrU SY2GbMtPJRhYBEW+3whV9+naydrH2N2HM4nvWAYty238NZGKuLqDUS4bknjm+7oSLUgi xNUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=W4rwO3U57huoy0zUteETLPkappaYRC0oAuQKV65X3fw=; b=SWqXnLNrRZepApFMnNZVin0CVIC66g4amXOwq40ilmmDVfx3wYE/GUeae8gZmTcH6C +KiLftGrkIq9wCcddUmlkX+FIF4gAmxxcF8kLgzbEp+F2Ul4bBE+Y/MU92gK6iQHYh01 XjECSq3QwIw/MT2w7roOKcb9XwWja6ujE1sH5CxP/2jh3RIeGuBn+j1qY97QP9TM3+BC z7HJh2zBzuNLa5xocBjMkIUtEbPg5DI0JS/MbfgVF5ON6xDnWptsNb3C787254o7uthG u34IBxy+BYrnbauR6fehvhvP+QOd4fXwpnatrIjLan1AU/wE64rcK4OpmD2Mj2ybEjuW hz7A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id o6-20020aa7dd46000000b00501c4daac52si14557271edw.504.2023.03.24.15.10.37; Fri, 24 Mar 2023 15:11:00 -0700 (PDT) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E4A8D68C8A6; Sat, 25 Mar 2023 00:10:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 6474768C8CF for ; Sat, 25 Mar 2023 00:10:27 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 7EBC940004 for ; Fri, 24 Mar 2023 22:10:26 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 24 Mar 2023 23:10:24 +0100 Message-Id: <20230324221025.19447-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/snow_dwt: Support correct rounding of dwt decomposition of non even sizes 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: raHAsJ7UPUwn Signed-off-by: Michael Niedermayer --- libavcodec/snow_dwt.c | 61 ++++++++++++++++++++++++------------------- libavcodec/snow_dwt.h | 3 +++ 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/libavcodec/snow_dwt.c b/libavcodec/snow_dwt.c index 965f409002..b27b07f58a 100644 --- a/libavcodec/snow_dwt.c +++ b/libavcodec/snow_dwt.c @@ -322,15 +322,17 @@ void ff_spatial_dwt(DWTELEM *buffer, DWTELEM *temp, int width, int height, int level; for (level = 0; level < decomposition_count; level++) { - switch (type) { + int w = DWT_RSHIFT(width , level); + int h = DWT_RSHIFT(height, level); + switch (type & 3) { case DWT_97: spatial_decompose97i(buffer, temp, - width >> level, height >> level, + w, h, stride << level); break; case DWT_53: spatial_decompose53i(buffer, temp, - width >> level, height >> level, + w, h, stride << level); break; } @@ -642,13 +644,14 @@ void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width, { int level; for (level = decomposition_count - 1; level >= 0; level--) { - switch (type) { + int h = DWT_RSHIFT(height, level); + switch (type & 3) { case DWT_97: - spatial_compose97i_buffered_init(cs + level, sb, height >> level, + spatial_compose97i_buffered_init(cs + level, sb, h, stride_line << level); break; case DWT_53: - spatial_compose53i_buffered_init(cs + level, sb, height >> level, + spatial_compose53i_buffered_init(cs + level, sb, h, stride_line << level); break; } @@ -660,28 +663,29 @@ void ff_spatial_idwt_buffered_slice(SnowDWTContext *dsp, DWTCompose *cs, int width, int height, int stride_line, int type, int decomposition_count, int y) { - const int support = type == 1 ? 3 : 5; + const int support = (type & 3) == 1 ? 3 : 5; int level; - if (type == 2) + if ((type & 3) == 2) return; - for (level = decomposition_count - 1; level >= 0; level--) - while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) { - switch (type) { + for (level = decomposition_count - 1; level >= 0; level--) { + int w = DWT_RSHIFT(width , level); + int h = DWT_RSHIFT(height, level); + while (cs[level].y <= FFMIN((y >> level) + support, h)) { + switch (type & 3) { case DWT_97: spatial_compose97i_dy_buffered(dsp, cs + level, slice_buf, temp, - width >> level, - height >> level, + w, h, stride_line << level); break; case DWT_53: spatial_compose53i_dy_buffered(cs + level, slice_buf, temp, - width >> level, - height >> level, + w, h, stride_line << level); break; } } + } } static void spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width, @@ -690,13 +694,14 @@ static void spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width, { int level; for (level = decomposition_count - 1; level >= 0; level--) { - switch (type) { + int h = DWT_RSHIFT(height, level); + switch (type & 3) { case DWT_97: - spatial_compose97i_init(cs + level, buffer, height >> level, + spatial_compose97i_init(cs + level, buffer, h, stride << level); break; case DWT_53: - spatial_compose53i_init(cs + level, buffer, height >> level, + spatial_compose53i_init(cs + level, buffer, h, stride << level); break; } @@ -708,24 +713,25 @@ static void spatial_idwt_slice(DWTCompose *cs, IDWTELEM *buffer, int stride, int type, int decomposition_count, int y) { - const int support = type == 1 ? 3 : 5; + const int support = (type & 3) == 1 ? 3 : 5; int level; - if (type == 2) + if ((type & 3) == 2) return; - for (level = decomposition_count - 1; level >= 0; level--) - while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) { - switch (type) { + for (level = decomposition_count - 1; level >= 0; level--) { + int w = DWT_RSHIFT(width , level); + int h = DWT_RSHIFT(height, level); + while (cs[level].y <= FFMIN((y >> level) + support, h)) { + switch (type & 3) { case DWT_97: - spatial_compose97i_dy(cs + level, buffer, temp, width >> level, - height >> level, stride << level); + spatial_compose97i_dy(cs + level, buffer, temp, w, h, stride << level); break; case DWT_53: - spatial_compose53i_dy(cs + level, buffer, temp, width >> level, - height >> level, stride << level); + spatial_compose53i_dy(cs + level, buffer, temp, w, h, stride << level); break; } } + } } void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height, @@ -788,6 +794,7 @@ static inline int w_c(struct MpegEncContext *v, const uint8_t *pix1, const uint8 } ff_spatial_dwt(tmp, tmp2, w, h, 32, type, dec_count); + type &= 3; s = 0; av_assert1(w == h); diff --git a/libavcodec/snow_dwt.h b/libavcodec/snow_dwt.h index 15b8a3007b..48acfd46c5 100644 --- a/libavcodec/snow_dwt.h +++ b/libavcodec/snow_dwt.h @@ -67,6 +67,9 @@ typedef struct SnowDWTContext { #define DWT_97 0 #define DWT_53 1 +#define DWT_NEW_ROUNDING_FLAG 4 + +#define DWT_RSHIFT(a, b) (((type) & DWT_NEW_ROUNDING_FLAG) ? -(-(a) >> (b)) : (a) >> (b)) #define liftS lift #define W_AM 3 From patchwork Fri Mar 24 22:10:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 40813 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4c12:b0:dd:c6d8:789a with SMTP id fm18csp797209pzb; Fri, 24 Mar 2023 15:11:09 -0700 (PDT) X-Google-Smtp-Source: AKy350a6RskA4nI6LlJuD4jK+F8kbkJW3qEdxW+nVHluT4Qco5+6rw6zCmHRTFp2YQprMr9oHs4X X-Received: by 2002:a17:906:9453:b0:932:b7ce:2aaa with SMTP id z19-20020a170906945300b00932b7ce2aaamr5111213ejx.28.1679695869255; Fri, 24 Mar 2023 15:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679695869; cv=none; d=google.com; s=arc-20160816; b=Rq/9Je+Bf/H/iD37Yr8FCjJVXg9iE7Au16tll0j9txcqCYSeQ10EikacetDqus0C+/ h5gszfnLFkt1BNrj4hj3L8+J7OmOVVo7gpVYhSZLCqQBpt9QTmp0LtDjpZ5zdBkI17Mc JBFybDmsdx3pMkiw3BBDcYJJ2bwjWdyDsuNUcSKGJ5w23n5wRAE160JtbfjOHqfLtcUj B72EBvt4et2bRC+4Zaxcvh/b6Ymy5Rh+NIv2fQlcWaOZLpp3CRunyxEWHMcYsgnggQyU 7TCdJ8HdtxBUJSH03tgv1KSwUSVF5Njpdm2TFT+Xon0a+kqNMsMVxjBUJGIplf6Yhtqr Luzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=4FcvKeYQV9FMPpXBA3mZK3Dow2NjBqh32Rpx9JuGqSU=; b=AXy7by9eKNC///bcIAekTWghBQXmQnFnqoJxGVbHfxI7RbY2+OBgqRrEg7Pz8P6384 RJxt6GPLLSRACDj8DxHDzH+3aNvR82U7knS7KJ3LuJojWocRAgpnzVAwYGDvtaEav8ea 0RyU9FAJ1TIbXs8sOQHMagePkkry9FGTHVZKZH5jcb72s+OxiGA8zmu8QLBAgg8agwru P9mvtICJmd6qPB3jmgsCLKkGKZa18YEvX9W1of8eF+IxugGMC5N6Plyu2TVeZ0u87Iw1 L741bgOFvhTsuutsY24pTY/rfbECkAx9Dl0vKK/fzV9QbqOAjsFupdRv7c7oiJf3Z5xX CPVA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gl14-20020a170906e0ce00b009324539297csi15500384ejb.208.2023.03.24.15.10.47; Fri, 24 Mar 2023 15:11:09 -0700 (PDT) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F30DB68C8E0; Sat, 25 Mar 2023 00:10:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7F61368C249 for ; Sat, 25 Mar 2023 00:10:28 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id A763B240002 for ; Fri, 24 Mar 2023 22:10:27 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 24 Mar 2023 23:10:25 +0100 Message-Id: <20230324221025.19447-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230324221025.19447-1-michael@niedermayer.cc> References: <20230324221025.19447-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/snowdec: support DWT with new size rounding 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: TMScIOcegF1h Signed-off-by: Michael Niedermayer --- libavcodec/snowdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c index bed29d3390..b7a5864f4c 100644 --- a/libavcodec/snowdec.c +++ b/libavcodec/snowdec.c @@ -385,7 +385,7 @@ static int decode_header(SnowContext *s){ } s->spatial_decomposition_type+= (unsigned)get_symbol(&s->c, s->header_state, 1); - if(s->spatial_decomposition_type > 1U){ + if((s->spatial_decomposition_type & (~4)) > 1U){ av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported\n", s->spatial_decomposition_type); return AVERROR_INVALIDDATA; }