From patchwork Wed Sep 6 07:27:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mateusz X-Patchwork-Id: 5003 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp266955jao; Wed, 6 Sep 2017 00:29:01 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5lxCveaLB8x49JAsSJd4QMcsG+IVyZJ9/EeKeeK/MvQFrP0M7Ek9AuPgCEhA7KBrlBlHBV X-Received: by 10.223.169.51 with SMTP id u48mr936472wrc.270.1504682941849; Wed, 06 Sep 2017 00:29:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504682941; cv=none; d=google.com; s=arc-20160816; b=XnO7FHLivBI8uTB7G7NhT2YAVj/kixKrjoMC13Yl/DVfYxCCfAf/1u/5iFTSwKPwq+ 8qb8+kgHn/mQN2taO2wirhnLyhgA2pWtr/UpjrB5umjyQPbDZZwNi2njKoRhBPGn8J62 ic6BmidOx1k8PCfUIWZR0WfSZcFZfzrxyzIY11suT5EadAVXBLFEymOP4/YKiSRDgpNG Jiw8sUuc9dwXf+6PVAX6KOsNP5g74nGHE1u/NsEo56UdcwIs2Pge/cXxvnLMVfl2SKls kDNl+pcufXLUhkFaNku1nKKWVA/YjMlAumHFZdOwr/ZgB5bl3DUc7EHyhchn5OYxzz0/ 39HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:dkim-signature:delivered-to :arc-authentication-results; bh=UEpfnotBwFixKoO8YWAfoq/m8Ptr117fdl0UjC5sQJo=; b=dXQ34izyRyRcg40RYl1sjeY+5o7Vfi75fqJGSXxMjxgwuZGHy85xG8hMX9PTDWg606 W1N0kvg1KZXl0KxJxHoJvRuIxwprdFNBuSAuvfMGG8H1dpILhwPxErnYr6odcvNrKf2+ V3gmcvjXcAjMWmWLWJe628EP1XMbwyScykL42SpKy9J0lHLeSuecFz8LvZgeO0q9JCuP IeWN6tNPqZL04kq91xZb/GP2epVI8hdY1jQSBeCp3RREJ0EtwvLR/PSbEZNL7au7zmSL 4ZfxUV7N0B2zD3D5zrEXe+90cFkJM8KqHXCAZicYx0Q6kH8tweO4myQyG8m9AWf4/ukn qZVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@poczta.onet.pl header.s=2011 header.b=S60CRyBT; 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 c3si1810123wrb.544.2017.09.06.00.29.00; Wed, 06 Sep 2017 00:29:01 -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=@poczta.onet.pl header.s=2011 header.b=S60CRyBT; 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 BB5F068A49C; Wed, 6 Sep 2017 10:28:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpo112.poczta.onet.pl (smtpo112.poczta.onet.pl [213.180.149.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BFA7368A48E for ; Wed, 6 Sep 2017 10:28:50 +0300 (EEST) Received: from [192.168.1.2] (affs228.neoplus.adsl.tpnet.pl [95.49.148.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mateuszb@poczta.onet.pl) by smtp.poczta.onet.pl (Onet) with ESMTPSA id 3xnFZ96KzHzlk7Hr for ; Wed, 6 Sep 2017 09:28:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poczta.onet.pl; s=2011; t=1504682930; bh=1wIjgpZiqfFv9mFrKrANTyqmTCSFyo7vNeTKbmEKsrU=; h=Subject:To:References:From:Date:In-Reply-To:From; b=S60CRyBTm3L8HBsQ8DfbsL9R0nxUnZf/zotXV40xb8lqZ0+WVJeTfn6Es5GvGE+ex ZSGKkS0FrMlDkWLUINtHdM6QPe0alcahkZHh1UJJRxov2CNSOgPKR9zPmwzZuwJ4Ei +Jg5ES3xrhuWaseaHrNBtKFiwWxCVniHPJIm2G3U= To: ffmpeg-devel@ffmpeg.org References: <8fa31561-5155-6975-738c-7406150ba73e@poczta.onet.pl> <20170905134031.GF7094@nb4> <89fdce7a-a6b9-189d-6d87-778e325c600c@poczta.onet.pl> <20170905213748.GI7094@nb4> <20170906000729.GL7094@nb4> From: Mateusz Message-ID: Date: Wed, 6 Sep 2017 09:27:23 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20170906000729.GL7094@nb4> Content-Language: en-US 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-09-06 o 02:07, Michael Niedermayer pisze: > On Wed, Sep 06, 2017 at 01:25:45AM +0200, Mateusz wrote: >> W dniu 2017-09-05 o 23:37, Michael Niedermayer pisze: >>> On Tue, Sep 05, 2017 at 04:42:06PM +0200, Mateusz wrote: >>>> W dniu 2017-09-05 o 15:40, Michael Niedermayer pisze: >>>>> On Mon, Sep 04, 2017 at 09:33:34AM +0200, Mateusz wrote: >>>>>> If ffmpeg reduces bit-depth to 8-bit or more, it uses DITHER_COPY macro. >>>>>> The problem is DITHER_COPY macro make images darker (on all planes). >>>>>> >>>>>> In x265 project there is issue #365 which is caused by this DITHER_COPY bug. >>>>>> I think it is time to fix -- there are more and more high bit-depth sources. >>>>>> >>>>>> Please review. >>>>>> >>>>>>  libswscale/swscale_unscaled.c | 44 +++++++++++++------------------------------ >>>>>>  1 file changed, 13 insertions(+), 31 deletions(-) >>>>> >>>>> please provide a git compatible patch with with commit message as produced >>>>> by git format-patch or git send-email >>>>> >>>>> this mail is not accepted as is by git >>>>> Applying: libswscale/swscale_unscaled: fix DITHER_COPY macro >>>>> error: corrupt patch at line 6 >>>>> error: could not build fake ancestor >>>>> Patch failed at 0001 libswscale/swscale_unscaled: fix DITHER_COPY macro >>>>> >>>>> [...] >>>> >>>> I've attached the result of git format-patch command. >>>> >>>> Sorry for 1 private e-mail (I clicked wrong button). >>>> >>>> Mateusz >>> >>>> swscale_unscaled.c | 44 +++++++++++++------------------------------- >>>> 1 file changed, 13 insertions(+), 31 deletions(-) >>>> 9973b13b3f74319abe9c97302ee87b2b3468b3b6 0001-fix-DITHER_COPY-macro-to-avoid-make-images-darker.patch >>>> From 9b96d612fef46ccec7e148cd7f8e8666b4e7a4cd Mon Sep 17 00:00:00 2001 >>>> From: Mateusz >>>> Date: Tue, 5 Sep 2017 16:09:28 +0200 >>>> Subject: [PATCH] fix DITHER_COPY macro to avoid make images darker >>>> >>>> --- >>>> libswscale/swscale_unscaled.c | 44 +++++++++++++------------------------------ >>>> 1 file changed, 13 insertions(+), 31 deletions(-) >>>> >>>> diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c >>>> index ef36aec..3b7a5a9 100644 >>>> --- a/libswscale/swscale_unscaled.c >>>> +++ b/libswscale/swscale_unscaled.c >>>> @@ -110,24 +110,6 @@ DECLARE_ALIGNED(8, static const uint8_t, dithers)[8][8][8]={ >>>> { 112, 16,104, 8,118, 22,110, 14,}, >>>> }}; >>>> >>>> -static const uint16_t dither_scale[15][16]={ >>>> -{ 2, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,}, >>>> -{ 2, 3, 7, 7, 13, 13, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,}, >>>> -{ 3, 3, 4, 15, 15, 29, 57, 57, 57, 113, 113, 113, 113, 113, 113, 113,}, >>>> -{ 3, 4, 4, 5, 31, 31, 61, 121, 241, 241, 241, 241, 481, 481, 481, 481,}, >>>> -{ 3, 4, 5, 5, 6, 63, 63, 125, 249, 497, 993, 993, 993, 993, 993, 1985,}, >>>> -{ 3, 5, 6, 6, 6, 7, 127, 127, 253, 505, 1009, 2017, 4033, 4033, 4033, 4033,}, >>>> -{ 3, 5, 6, 7, 7, 7, 8, 255, 255, 509, 1017, 2033, 4065, 8129,16257,16257,}, >>>> -{ 3, 5, 6, 8, 8, 8, 8, 9, 511, 511, 1021, 2041, 4081, 8161,16321,32641,}, >>>> -{ 3, 5, 7, 8, 9, 9, 9, 9, 10, 1023, 1023, 2045, 4089, 8177,16353,32705,}, >>>> -{ 3, 5, 7, 8, 10, 10, 10, 10, 10, 11, 2047, 2047, 4093, 8185,16369,32737,}, >>>> -{ 3, 5, 7, 8, 10, 11, 11, 11, 11, 11, 12, 4095, 4095, 8189,16377,32753,}, >>>> -{ 3, 5, 7, 9, 10, 12, 12, 12, 12, 12, 12, 13, 8191, 8191,16381,32761,}, >>>> -{ 3, 5, 7, 9, 10, 12, 13, 13, 13, 13, 13, 13, 14,16383,16383,32765,}, >>>> -{ 3, 5, 7, 9, 10, 12, 14, 14, 14, 14, 14, 14, 14, 15,32767,32767,}, >>>> -{ 3, 5, 7, 9, 11, 12, 14, 15, 15, 15, 15, 15, 15, 15, 16,65535,}, >>>> -}; >>>> - >>>> >>>> static void fillPlane(uint8_t *plane, int stride, int width, int height, int y, >>>> uint8_t val) >>>> @@ -1502,22 +1484,22 @@ static int packedCopyWrapper(SwsContext *c, const uint8_t *src[], >>>> } >>>> >>>> #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\ >>>> - 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];\ >>>> + unsigned shift= src_depth-dst_depth, tmp;\ >>>> for (i = 0; i < height; i++) {\ >>>> - const uint8_t *dither= dithers[src_depth-9][i&7];\ >>>> + const uint8_t *dither= dithers[shift-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);\ >>>> - dst[j+2] = dbswap((bswap(src[j+2]) + dither[2])*scale>>shift);\ >>>> - dst[j+3] = dbswap((bswap(src[j+3]) + dither[3])*scale>>shift);\ >>>> - dst[j+4] = dbswap((bswap(src[j+4]) + dither[4])*scale>>shift);\ >>>> - dst[j+5] = dbswap((bswap(src[j+5]) + dither[5])*scale>>shift);\ >>>> - dst[j+6] = dbswap((bswap(src[j+6]) + dither[6])*scale>>shift);\ >>>> - dst[j+7] = dbswap((bswap(src[j+7]) + dither[7])*scale>>shift);\ >>>> + tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\ >>>> + tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\ >>>> + tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\ >>>> + tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\ >>>> + tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\ >>>> + tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\ >>>> + tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\ >>>> + tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\ >>> >>> This does not look correct >>> >>> flat black should be mapped to flat black (ok) >>> flat white should be mapped to flat white (ok) >>> black+1 should not be mapped to flat black but to a dithered pattern mixing black with the next brighter color (ok) >>> white-1 should not be mapped to flat white but to a dithered pattern mixing white with the next darker color (not ok) >>> >>> example if you take 9 bit to 7 bit >>> 511 + {0..3} = {511..514} >>> {511..514} >> 2 = {127,128} >>> {127,128} - ({127,128} >> 7) = 127 >>> >>> 510 + {0..3} = {510..513} >>> {510..513} >> 2 = {127,128} >>> {127,128} - ({127,128} >> 7) = 127 >>> >>> Thus multiple of the brigher colors all get mapped to the same output, >>> that way the brightest shades become indistingishable and this is not >>> correct. >>> >>> above is based on code review not testing so i might have missed >>> something >>> >>> [...] >> >> Yes, you are right. >> >> There is one more rule, that is important and (partially) in contradiction to white-1 to not flat white rule: > >> if you convert 7-bit source to 9-bit and next resulting 9-bit to 7-bit, it should be the same picture as original. > > this would be desirable > > >> if we convert 7 bit white (or max value at plane) == 127, we have 127 << 2 == 508 >> now 508 goes always to 127 > > This would only be the case if 508 was the white point and not 511 > otherwise > If you convert 7bit to 9bit, 127 is converted to 511, this would be a > requirement to maintain white. > if you use fewer bits it becomes more obvious > 2 bits to 4 bits > 3 -> 15 not 3 -> 12 > > whereever the white and black points are in the input and output > colorspace they must get converted correctly. > > > [...] line #1538 in file libswscale/swscale_unscaled.c int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 0); line #421 in file libswscale/swscale_internal.h int srcRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (source image). For movies (without special options) ffmpeg always upscale bit-depth by simple shift (127 to 508). Only for plane 0 and srcRange == 1 (full range) ffmpeg upscale 127 to 511. For me it is impossible to make DITHER_COPY macro that works OK for both cases, so I attached new version that check shiftonly state and works optimal according to the shiftonly state. Now in both cases it is original picture after upscale bit-depth -> downscale bit-depth sequence. Please review. Mateusz From fd9e271ea531d25bc5a708d0dfeb1be5415b90d0 Mon Sep 17 00:00:00 2001 From: Mateusz Date: Wed, 6 Sep 2017 09:05:02 +0200 Subject: [PATCH] fix DITHER_COPY macro according to shiftonly state --- libswscale/swscale_unscaled.c | 73 ++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c index ef36aec..e3e375a 100644 --- a/libswscale/swscale_unscaled.c +++ b/libswscale/swscale_unscaled.c @@ -110,24 +110,6 @@ DECLARE_ALIGNED(8, static const uint8_t, dithers)[8][8][8]={ { 112, 16,104, 8,118, 22,110, 14,}, }}; -static const uint16_t dither_scale[15][16]={ -{ 2, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,}, -{ 2, 3, 7, 7, 13, 13, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,}, -{ 3, 3, 4, 15, 15, 29, 57, 57, 57, 113, 113, 113, 113, 113, 113, 113,}, -{ 3, 4, 4, 5, 31, 31, 61, 121, 241, 241, 241, 241, 481, 481, 481, 481,}, -{ 3, 4, 5, 5, 6, 63, 63, 125, 249, 497, 993, 993, 993, 993, 993, 1985,}, -{ 3, 5, 6, 6, 6, 7, 127, 127, 253, 505, 1009, 2017, 4033, 4033, 4033, 4033,}, -{ 3, 5, 6, 7, 7, 7, 8, 255, 255, 509, 1017, 2033, 4065, 8129,16257,16257,}, -{ 3, 5, 6, 8, 8, 8, 8, 9, 511, 511, 1021, 2041, 4081, 8161,16321,32641,}, -{ 3, 5, 7, 8, 9, 9, 9, 9, 10, 1023, 1023, 2045, 4089, 8177,16353,32705,}, -{ 3, 5, 7, 8, 10, 10, 10, 10, 10, 11, 2047, 2047, 4093, 8185,16369,32737,}, -{ 3, 5, 7, 8, 10, 11, 11, 11, 11, 11, 12, 4095, 4095, 8189,16377,32753,}, -{ 3, 5, 7, 9, 10, 12, 12, 12, 12, 12, 12, 13, 8191, 8191,16381,32761,}, -{ 3, 5, 7, 9, 10, 12, 13, 13, 13, 13, 13, 13, 14,16383,16383,32765,}, -{ 3, 5, 7, 9, 10, 12, 14, 14, 14, 14, 14, 14, 14, 15,32767,32767,}, -{ 3, 5, 7, 9, 11, 12, 14, 15, 15, 15, 15, 15, 15, 15, 16,65535,}, -}; - static void fillPlane(uint8_t *plane, int stride, int width, int height, int y, uint8_t val) @@ -1502,24 +1484,45 @@ static int packedCopyWrapper(SwsContext *c, const uint8_t *src[], } #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\ - 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];\ - 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);\ - dst[j+2] = dbswap((bswap(src[j+2]) + dither[2])*scale>>shift);\ - dst[j+3] = dbswap((bswap(src[j+3]) + dither[3])*scale>>shift);\ - dst[j+4] = dbswap((bswap(src[j+4]) + dither[4])*scale>>shift);\ - dst[j+5] = dbswap((bswap(src[j+5]) + dither[5])*scale>>shift);\ - dst[j+6] = dbswap((bswap(src[j+6]) + dither[6])*scale>>shift);\ - dst[j+7] = dbswap((bswap(src[j+7]) + dither[7])*scale>>shift);\ + unsigned shift= src_depth-dst_depth, tmp;\ + if (shiftonly) {\ + for (i = 0; i < height; i++) {\ + const uint8_t *dither= dithers[shift-1][i&7];\ + for (j = 0; j < length-7; j+=8){\ + tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\ + tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\ + tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\ + tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\ + tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\ + tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\ + tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\ + tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\ + }\ + for (; j < length; j++){\ + tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\ + }\ + dst += dstStride;\ + src += srcStride;\ + }\ + } else {\ + for (i = 0; i < height; i++) {\ + const uint8_t *dither= dithers[shift-1][i&7];\ + for (j = 0; j < length-7; j+=8){\ + tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\ + tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\ + tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\ + tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\ + tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\ + tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\ + tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\ + tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\ + }\ + for (; j < length; j++){\ + tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\ + }\ + dst += dstStride;\ + src += srcStride;\ }\ - for (; j < length; j++)\ - dst[j] = dbswap((bswap(src[j]) + dither[j&7])*scale>>shift);\ - dst += dstStride;\ - src += srcStride;\ } static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],