From patchwork Sun May 26 00:07:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13298 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id EAE94449742 for ; Sun, 26 May 2019 03:16:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D11FD688391; Sun, 26 May 2019 03:16:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6A4AB680373 for ; Sun, 26 May 2019 03:16:28 +0300 (EEST) Received: by mail-pg1-f196.google.com with SMTP id n2so7038651pgp.11 for ; Sat, 25 May 2019 17:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=teMrHDddOdLpze6vYsKb8WGigytnMG6g3uiqPyrZ4mY=; b=Tv4NDp3Dmae8DhS/MHgErPMgH5srJoYCaUb10rdf7a0yQF+64afNKnjuji02lbuYh8 wCj/iq5FPA4FRrgnKib+aSIc+eQ6PZls+/6AzgfSJHRINk3zj/pZqNJwNlvJligMdRgq vkVgkkFQoeB2gqvhDAXnNujRIXD5yjATI9KkkSNaxfF3wWz9IGCuXU2BWC26TZvt1lU0 Vv+HfXv+VkgmHJmh480g/L9QKjK5PJzH1KFc0USb0/VGPgtG3l7fnxKG3CacRuQzS3JO 6Z0///oF5XhJU4RuOuVTESquT/6LBMMQIqOMEarmKPAflLtNs68xI7B0Aa+gztEG8fE1 V9lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=teMrHDddOdLpze6vYsKb8WGigytnMG6g3uiqPyrZ4mY=; b=FAgMBemfApJk6mex0RjNzh9jj1cY4YKRQaKR9ZC+8gIcBNywT0yAEJAaHhZX9amVAK tA0EbMMa9JWMEJBWvb3r2ovDvM5uXJ02U2vL9P1pxBp6ouWiqmthXvXpfVN7K2QEheTh +GFUjbgqzTT9r7OKCIhXlNSAH2VHMziyKl76kSCI4yQh79moz6XTbCfV1Edw1+XKEcrV VIPOSLAvVq/1jU/yH4GTkFk6WeOC5VbbeNZVDeQlnTWuuAN2f9jWXxV7wQuPXu5/Tbyh bVLcEmWWxjZ7ww0GPed9X8SDaNMYphu6dkX4ji8S4tFbKoH5G1fwN2RBYVDWJdEIt5CB 5LhQ== X-Gm-Message-State: APjAAAV8gpB6HrAARViNgsKcOEveeOm83sCjJGMrkiCo+QFUTM/xC2QV 9XgIABMlfNXAFU/yuK6rsbSUZqK7eWc= X-Google-Smtp-Source: APXvYqwrbDdPHmcKT0L7g081PdNVOIFolueOc9ZhKuyEV2+maHMe1hL8mdYp1Ey6oD1HzJTKpRKqTg== X-Received: by 2002:aa7:8157:: with SMTP id d23mr97256500pfn.92.1558829330796; Sat, 25 May 2019 17:08:50 -0700 (PDT) Received: from localhost.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id a9sm6323945pgw.72.2019.05.25.17.08.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 May 2019 17:08:50 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 May 2019 08:07:49 +0800 Message-Id: <20190526000750.79563-4-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190526000750.79563-1-lance.lmwang@gmail.com> References: <20190526000750.79563-1-lance.lmwang@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] libavfilter/vf_overlay.c: using the nbits and depth for 8bits and 10bit support Have fix the build issue for other platform by Michael Niedermayer comments: https://patchwork.ffmpeg.org/patch/13271/ 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 Cc: michael@niedermayer.cc, Limin Wang , ceffmpeg@gmail.com, barsnick@gmx.net, james.darnley@gmail.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang --- libavfilter/vf_overlay.c | 79 ++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 32 deletions(-) diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c index ee51a54659..2d06074f15 100644 --- a/libavfilter/vf_overlay.c +++ b/libavfilter/vf_overlay.c @@ -464,22 +464,26 @@ static av_always_inline void blend_plane_##depth##_##nbits##bits(AVFilterContext int dst_hp = AV_CEIL_RSHIFT(dst_h, vsub); \ int yp = y>>vsub; \ int xp = x>>hsub; \ - uint8_t *s, *sp, *d, *dp, *dap, *a, *da, *ap; \ + uint##depth##_t *s, *sp, *d, *dp, *dap, *a, *da, *ap; \ int jmax, j, k, kmax; \ int slice_start, slice_end; \ + const uint##depth##_t max = (1 << nbits) - 1; \ + const uint##depth##_t mid = (1 << (nbits -1)) ; \ + int bytes = depth / 8; \ \ + dst_step /= bytes; \ j = FFMAX(-yp, 0); \ jmax = FFMIN3(-yp + dst_hp, FFMIN(src_hp, dst_hp), yp + src_hp); \ \ slice_start = j + (jmax * jobnr) / nb_jobs; \ slice_end = j + (jmax * (jobnr+1)) / nb_jobs; \ \ - sp = src->data[i] + (slice_start) * src->linesize[i]; \ - dp = dst->data[dst_plane] \ + sp = (uint##depth##_t *)(src->data[i] + (slice_start) * src->linesize[i]); \ + dp = (uint##depth##_t *)(dst->data[dst_plane] \ + (yp + slice_start) * dst->linesize[dst_plane] \ - + dst_offset; \ - ap = src->data[3] + (slice_start << vsub) * src->linesize[3]; \ - dap = dst->data[3] + ((yp + slice_start) << vsub) * dst->linesize[3]; \ + + dst_offset); \ + ap = (uint##depth##_t *)(src->data[3] + (slice_start << vsub) * src->linesize[3]); \ + dap = (uint##depth##_t *)(dst->data[3] + ((yp + slice_start) << vsub) * dst->linesize[3]); \ \ for (j = slice_start; j < slice_end; j++) { \ k = FFMAX(-xp, 0); \ @@ -489,8 +493,8 @@ static av_always_inline void blend_plane_##depth##_##nbits##bits(AVFilterContext da = dap + ((xp+k) << hsub); \ kmax = FFMIN(-xp + dst_wp, src_wp); \ \ - if (((vsub && j+1 < src_hp) || !vsub) && octx->blend_row[i]) { \ - int c = octx->blend_row[i](d, da, s, a, kmax - k, src->linesize[3]); \ + if (nbits == 8 && ((vsub && j+1 < src_hp) || !vsub) && octx->blend_row[i]) { \ + int c = octx->blend_row[i]((uint8_t*)d, (uint8_t*)da, (uint8_t*)s, (uint8_t*)a, kmax - k, src->linesize[3]); \ \ s += c; \ d += dst_step * c; \ @@ -515,7 +519,7 @@ static av_always_inline void blend_plane_##depth##_##nbits##bits(AVFilterContext alpha = a[0]; \ /* if the main channel has an alpha channel, alpha has to be calculated */ \ /* to create an un-premultiplied (straight) alpha value */ \ - if (main_has_alpha && alpha != 0 && alpha != 255) { \ + if (main_has_alpha && alpha != 0 && alpha != max) { \ /* average alpha for color components, improve quality */ \ uint8_t alpha_d; \ if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) { \ @@ -532,22 +536,32 @@ static av_always_inline void blend_plane_##depth##_##nbits##bits(AVFilterContext alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d); \ } \ if (straight) { \ - *d = FAST_DIV255(*d * (255 - alpha) + *s * alpha); \ - } else { \ - if (i && yuv) \ - *d = av_clip(FAST_DIV255((*d - 128) * (255 - alpha)) + *s - 128, -128, 128) + 128; \ + if (nbits > 8) \ + *d = (*d * (max - alpha) + *s * alpha) / max; \ else \ - *d = FFMIN(FAST_DIV255(*d * (255 - alpha)) + *s, 255); \ + *d = FAST_DIV255(*d * (255 - alpha) + *s * alpha); \ + } else { \ + if (nbits > 8) { \ + if (i && yuv) \ + *d = av_clip((*d * (max - alpha) + *s * alpha) / max + *s - mid, -mid, mid) + mid; \ + else \ + *d = FFMIN((*d * (max - alpha) + *s * alpha) / max + *s, max); \ + } else { \ + if (i && yuv) \ + *d = av_clip(FAST_DIV255((*d - mid) * (max - alpha)) + *s - mid, -mid, mid) + mid; \ + else \ + *d = FFMIN(FAST_DIV255(*d * (max - alpha)) + *s, max); \ + } \ } \ s++; \ d += dst_step; \ da += 1 << hsub; \ a += 1 << hsub; \ } \ - dp += dst->linesize[dst_plane]; \ - sp += src->linesize[i]; \ - ap += (1 << vsub) * src->linesize[3]; \ - dap += (1 << vsub) * dst->linesize[3]; \ + dp += dst->linesize[dst_plane] / bytes; \ + sp += src->linesize[i] / bytes; \ + ap += (1 << vsub) * src->linesize[3] / bytes; \ + dap += (1 << vsub) * dst->linesize[3] / bytes; \ } \ } DEFINE_BLEND_PLANE(8, 8); @@ -559,18 +573,20 @@ static inline void alpha_composite_##depth##_##nbits##bits(const AVFrame *src, c int x, int y, \ int jobnr, int nb_jobs) \ { \ - uint8_t alpha; /* the amount of overlay to blend on to main */ \ - uint8_t *s, *sa, *d, *da; \ + uint##depth##_t alpha; /* the amount of overlay to blend on to main */ \ + uint##depth##_t *s, *sa, *d, *da; \ int i, imax, j, jmax; \ int slice_start, slice_end; \ + const uint##depth##_t max = (1 << nbits) - 1; \ + int bytes = depth / 8; \ \ imax = FFMIN(-y + dst_h, src_h); \ slice_start = (imax * jobnr) / nb_jobs; \ slice_end = ((imax * (jobnr+1)) / nb_jobs); \ \ i = FFMAX(-y, 0); \ - sa = src->data[3] + (i + slice_start) * src->linesize[3]; \ - da = dst->data[3] + (y + i + slice_start) * dst->linesize[3]; \ + sa = (uint##depth##_t *)(src->data[3] + (i + slice_start) * src->linesize[3]); \ + da = (uint##depth##_t *)(dst->data[3] + (y + i + slice_start) * dst->linesize[3]); \ \ for (i = i + slice_start; i < slice_end; i++) { \ j = FFMAX(-x, 0); \ @@ -579,25 +595,24 @@ static inline void alpha_composite_##depth##_##nbits##bits(const AVFrame *src, c \ for (jmax = FFMIN(-x + dst_w, src_w); j < jmax; j++) { \ alpha = *s; \ - if (alpha != 0 && alpha != 255) { \ + if (alpha != 0 && alpha != max) { \ uint8_t alpha_d = *d; \ alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d); \ } \ - switch (alpha) { \ - case 0: \ - break; \ - case 255: \ + if (alpha == max) \ *d = *s; \ - break; \ - default: \ + else if (alpha > 0) { \ /* apply alpha compositing: main_alpha += (1-main_alpha) * overlay_alpha */ \ - *d += FAST_DIV255((255 - *d) * *s); \ + if (nbits > 8) \ + *d += (max - *d) * *s / max; \ + else \ + *d += FAST_DIV255((max - *d) * *s); \ } \ d += 1; \ s += 1; \ } \ - da += dst->linesize[3]; \ - sa += src->linesize[3]; \ + da += dst->linesize[3] / bytes; \ + sa += src->linesize[3] / bytes; \ } \ } DEFINE_ALPHA_COMPOSITE(8, 8);