From patchwork Mon Mar 20 09:48:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Brzostek X-Patchwork-Id: 3026 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp1309812vsy; Mon, 20 Mar 2017 02:51:28 -0700 (PDT) X-Received: by 10.223.172.101 with SMTP id v92mr27171595wrc.49.1490003488445; Mon, 20 Mar 2017 02:51:28 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w75si22226539wrb.207.2017.03.20.02.51.27; Mon, 20 Mar 2017 02:51:28 -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; dkim=neutral (body hash did not verify) header.i=@msystem.waw.pl; 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 EDE3F6883A1; Mon, 20 Mar 2017 11:51:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from s36a.hekko.net.pl (s36a.hekko.net.pl [188.116.19.94]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2DD9768830E for ; Mon, 20 Mar 2017 11:51:00 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=msystem.waw.pl; s=x; h=Content-Type:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=+PsW08HO5A6OofrWQpKcN3n67oTppvkW8a3fBN9/yhc=; b=I1U4nPa1JdpyzTN85Bld9YmCh obdcGxXFigdnEke5XfktPbI4EipEAhUFicuDickI5lCKrRFmfBej1Dt7lCaYtWsXpgFrtwGjQPfEk upUZO7Fwg+RKEpHeoyVPeR6Xh01giEKy2bI/P/L1+Ix+etdXUlkLab46W9e4pQ/1R5fzabp5FqseA GaKj5a2kcf7otQAniJe2W0hX0WzOJh1r8rHh7UDGx6kjrPJg+Vrx07uvXKMK50xmotFCl2pzlwbO1 3utEu/p5uCXKt5Iw0/6InapEmm4Gchu4YTgPTWQgSK5Rw+i+MHi08A+W2pS9gSFeagIyliEuRq30G jUjcKyY0A==; Received: from adpe28.neoplus.adsl.tpnet.pl ([79.185.112.28] helo=[192.168.1.3]) by s36.hekko.net.pl with esmtpsa (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.87) (envelope-from ) id 1cpty9-00057W-BQ for ffmpeg-devel@ffmpeg.org; Mon, 20 Mar 2017 10:51:17 +0100 To: FFmpeg development discussions and patches References: <5de4b4a8-767b-5ddb-1b5b-78cb913e32d0@msystem.waw.pl> From: Mateusz Brzostek Message-ID: <41eba3ee-b58d-dbf6-c7f9-5a37bb5564a6@msystem.waw.pl> Date: Mon, 20 Mar 2017 10:48:40 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: X-HEKKO: 79.185.112.28:mateusz@msystem.waw.pl Subject: Re: [FFmpeg-devel] [PATCH] libswscale/swscale_unscaled: fix DITHER_COPY macro X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" W dniu 2017-03-20 o 10:00, Carl Eugen Hoyos pisze: > 2017-03-15 22:52 GMT+01:00 Mateusz Brzostek : >> Hello! >> >> There are 3 problems with DITHER_COPY macro in libswscale/swscale_unscaled.c: >> 1) there is overflow in dithering from 12-bit to 10-bit (output value > 1023); >> 2) for limit range the lower limit is not respected, for example from 10-bit to 8-bit value 64 is converted to 15; >> 3) for many iteration of downscale/upscale of the same image the 200th iteration is significantly darker. >> >> The first bug is due to wrong dithers table (now it is OK only for 8-bit destination), fix is: >> - const uint8_t *dither= dithers[src_depth-9][i&7];\ >> + const uint8_t *dither= dithers[src_depth-dst_depth-1][i&7];\ > I believe this implies that you could split your patch. > > Carl Eugen I've attached dither_tiny.patch -- it solve the biggest problem when dst_depth > 8 and white goes to black. If you don't want to loose time for DITHER_COPY problem, please apply only this dither_tiny.patch -- for one iteration it is acceptable quality. movie after 200 iterations 12bit -> 10bit -> 8bit ->12bit with dither_tiny.patch msystem.waw.pl/x265/w200.mkv and the same but with dither_sub.patch msystem.waw.pl/x265/n200.mkv libswscale/swscale_unscaled.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c index ba3d688..bd4e4f2 100644 --- a/libswscale/swscale_unscaled.c +++ b/libswscale/swscale_unscaled.c @@ -1488,7 +1488,7 @@ static int packedCopyWrapper(SwsContext *c, const uint8_t *src[], uint16_t scale= dither_scale[dst_depth-1][src_depth-1];\ int shift= src_depth-dst_depth + dither_scale[src_depth-2][dst_depth-1];\ for (i = 0; i < height; i++) {\ - const uint8_t *dither= dithers[src_depth-9][i&7];\ + const uint8_t *dither= dithers[src_depth-dst_depth-1][i&7];\ for (j = 0; j < length-7; j+=8){\ dst[j+0] = dbswap((bswap(src[j+0]) + dither[0])*scale>>shift);\ dst[j+1] = dbswap((bswap(src[j+1]) + dither[1])*scale>>shift);\