From patchwork Tue May 3 06:37:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 35553 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp257375pzb; Mon, 2 May 2022 23:38:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkQUl5V3yxhYyB8X3hbhmkKcOirEgvIF+T/dZDuewwyHE+xk3Wr7fZ1PGD9VaWZrcMyJ9L X-Received: by 2002:a17:907:3fa6:b0:6f3:a758:73b3 with SMTP id hr38-20020a1709073fa600b006f3a75873b3mr14529516ejc.108.1651559926297; Mon, 02 May 2022 23:38:46 -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 g14-20020a056402424e00b00427b1691f9csi7070702edb.186.2022.05.02.23.38.45; Mon, 02 May 2022 23:38:46 -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=@outlook.com header.s=selector1 header.b=tv49icx+; arc=fail (body hash mismatch); 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9A83E68B38A; Tue, 3 May 2022 09:38:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075087.outbound.protection.outlook.com [40.92.75.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2044768B379 for ; Tue, 3 May 2022 09:38:36 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JXKkOBHOdioYa82/yLPlktCR27HVHlUbOQbKvb3tnQpDZxhyO+D67dS4N6bKeMlvkrd2qCwwSFoaa8B3YkNQisoj6pE3vxRi1sSJKZJAdgdGHyqz9KTuNwh8LzsQIXLUqb+R6lHke6k2i5NSBptnmLPO+nKhLWFS15YCwfz6CGA8nNVMHJR6rpz1zEJQD/FHxoxjU7HD7sqd9H9TM5Y0610K7X8FoedMJj3RH6wUXdTpzuxQd/nGedzmwN6T52mi5+Bu3PsND+vItIZ4fsFO8dyZ68IJQX09nOJg7z4diW6vyqAN/2ZD/S9E0Q0/x9uzmr8LEl4N/0sYTJK/U6JgqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=F3XcY3UHYQXebAiqseI3XPBvawpma9LaDIYAt4qLO2M=; b=LQwNYeK1NTHGt0Z1ilwtzzKZmXPp8mDPJtEDmqwvge5hiqUic7mc3ELT1GGB3FgokBXhklkMU8EdK8ou41Ora4SIVOZ6VYbBg+YvpTRkYmz6AVS5DEpaQ6ZT/O2cjYgre9LRthIKFGtMqeubK+Zy4lFsaKQeM6d1tSK2PaMdAZY+NOiJOc0wmOicnzmO2rEil+9tmVQt9jkCQ1AiJaIZyERW0JaTzSDggtHa5E30WOtGAWkTF8Bv7b31STYEkzeB1WoRXnGsSbuM5QcD+PoPZQnJNmyl4oTw4o+KHgdzfTEWg8YstZ7bzvbuuzsDyhBbSYrN+i4UFl2CV9mLumqk0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F3XcY3UHYQXebAiqseI3XPBvawpma9LaDIYAt4qLO2M=; b=tv49icx+b4SSHbpHFCnRrZ7dZ8AXXx6yuDvG/4SIMqvjD0HBhTcuTz5oHqbG9q8AYDpCqnAxP+3e09tEMrBCdmGFZWW4nvbU3yC5Ow+URBI48SLcu3beAn3q1My8HlzaZkYwa0mxjVvFE3LpYbsX1R0qv4bAMW06nMEI0S/rLIABkl6DpA4L2a2Tr0MTfo7Vd2xj2wY2P8iAuWuWPvrAIYf2hcl8o0wqMXd44gXxtMMI3DOy0wNiHGzeS3wOC7skLEwNEJ81OL6uUrOkflex7fgOvxD6QBMiX1cKGWwAlbtF4UV8E9VRAnLM78KgTuyu1IqTXd7jJkTT7j/1gmg5NQ== Received: from AS8PR01MB7944.eurprd01.prod.exchangelabs.com (2603:10a6:20b:373::5) by VI1PR0102MB3230.eurprd01.prod.exchangelabs.com (2603:10a6:803:8::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 06:38:34 +0000 Received: from AS8PR01MB7944.eurprd01.prod.exchangelabs.com ([fe80::1854:2c30:7ba1:c431]) by AS8PR01MB7944.eurprd01.prod.exchangelabs.com ([fe80::1854:2c30:7ba1:c431%6]) with mapi id 15.20.5206.024; Tue, 3 May 2022 06:38:34 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 May 2022 08:37:44 +0200 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [3gKlD+wwK11AsqD8gGAY5lOfMpImp+z2] X-ClientProxiedBy: ZR0P278CA0014.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::24) To AS8PR01MB7944.eurprd01.prod.exchangelabs.com (2603:10a6:20b:373::5) X-Microsoft-Original-Message-ID: <20220503063751.2261222-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 74fd3d2a-17d7-4e99-0d08-08da2ccf8bc8 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiTQEkMEhbgfP1CXQyS+IofoXLPsl+0rmRprglPJoP39vu4VkUkyzMhXRVhF7jr+jHzHmftcSCbsltdOLpSoHOhhfekO7QxcOLycVv1WmS42NdKHsmd4PD9DEE4jyfQ45XJwThz4C3qej5ppl19GExb6N/VYwoZjY7ma6UFnSkqbP2qpbJ1JJSsu+pB+OweChOkQSEGE9lzffK75uu81eiZLObb1I5rRGvahCfprAYxqpATvilGkX0dsaU6QQgcLcibK8Kk7LqGg8FdYVUl+AWqq1fZaVWuDgUkqsaN8YObWFW5ERmOn0mmm3Pv/I0QPo/mA0J9DmrniPYjcEuSkv+4M7r5Ie0rybqu+/yfnovCKqlieiCjz07dt4cN6/nnmNplavAjlIgp8DbDBKDPNYXkw7yRH6LGdxxdyGKxfxotXD7OLO6U4+ZoVaFWZAxyLr3E5re+BcPJeb/bw1MsPMvFT5UQ2AyC8SybWRjyXiWRsdrIplH4kiJpWjkI6VP8g+vOjVwvXoYrN2WmgEX4YCL8R2gfzzKTRXBjVQUvyRVc+/4QQb5JAGIWLcopTtWewz5b3RoKjvdf70wCJMNNFDwuzaryjG2Bk+NqxeaWQycaHaizrHx89iyuqCWtjRyiKrCKNxj1tZX/yTTQO9oPh8gf/SqebqEJ/6GEuM6stgdff3uXSMEQfapmodlJ/6ahvQXlMk93OemgVkmKqGe/WLePuiFfwi89lqjZsB8ltkJh10sPmqVzuUM9iqAWI52moKls= X-MS-TrafficTypeDiagnostic: VI1PR0102MB3230:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9XGQ+W6GS80Tr6cFq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com X-MS-Exchange-CrossTenant-Network-Message-Id: 74fd3d2a-17d7-4e99-0d08-08da2ccf8bc8 X-MS-Exchange-CrossTenant-AuthSource: AS8PR01MB7944.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 06:38:34.6341 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0102MB3230 Subject: [FFmpeg-devel] [PATCH 03/10] avfilter/vf_blend: Move ff_blend_init into a header 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 1o0C8M0j6I+P This removes a dependency of checkasm on lavfi/vf_blend.o and also allows to inline ff_blend_init() irrespectively of interposing. Signed-off-by: Andreas Rheinhardt --- libavfilter/blend.h | 1 - libavfilter/vf_blend.c | 176 +------------------------------ libavfilter/vf_blend_init.h | 201 ++++++++++++++++++++++++++++++++++++ tests/checkasm/vf_blend.c | 2 +- 4 files changed, 203 insertions(+), 177 deletions(-) create mode 100644 libavfilter/vf_blend_init.h diff --git a/libavfilter/blend.h b/libavfilter/blend.h index ff417650cf..b046e062bc 100644 --- a/libavfilter/blend.h +++ b/libavfilter/blend.h @@ -81,7 +81,6 @@ typedef struct FilterParams { struct FilterParams *param, double *values, int starty); } FilterParams; -void ff_blend_init(FilterParams *param, int depth); void ff_blend_init_x86(FilterParams *param, int depth); #endif /* AVFILTER_BLEND_H */ diff --git a/libavfilter/vf_blend.c b/libavfilter/vf_blend.c index c882086c51..dfe2b8b174 100644 --- a/libavfilter/vf_blend.c +++ b/libavfilter/vf_blend.c @@ -20,48 +20,19 @@ #include "config_components.h" -#include "libavutil/imgutils.h" -#include "libavutil/intfloat.h" #include "libavutil/eval.h" #include "libavutil/opt.h" #include "libavutil/pixfmt.h" #include "avfilter.h" -#include "formats.h" #include "framesync.h" #include "internal.h" +#include "vf_blend_init.h" #include "video.h" #include "blend.h" #define TOP 0 #define BOTTOM 1 -#define DEPTH 8 -#include "blend_modes.c" - -#undef DEPTH -#define DEPTH 9 -#include "blend_modes.c" - -#undef DEPTH -#define DEPTH 10 -#include "blend_modes.c" - -#undef DEPTH -#define DEPTH 12 -#include "blend_modes.c" - -#undef DEPTH -#define DEPTH 14 -#include "blend_modes.c" - -#undef DEPTH -#define DEPTH 16 -#include "blend_modes.c" - -#undef DEPTH -#define DEPTH 32 -#include "blend_modes.c" - typedef struct BlendContext { const AVClass *class; FFFrameSync fs; @@ -155,58 +126,6 @@ static const AVOption blend_options[] = { FRAMESYNC_DEFINE_CLASS(blend, BlendContext, fs); -#define COPY(src, depth) \ -static void blend_copy ## src##_##depth(const uint8_t *top, ptrdiff_t top_linesize, \ - const uint8_t *bottom, ptrdiff_t bottom_linesize,\ - uint8_t *dst, ptrdiff_t dst_linesize, \ - ptrdiff_t width, ptrdiff_t height, \ - FilterParams *param, double *values, int starty) \ -{ \ - av_image_copy_plane(dst, dst_linesize, src, src ## _linesize, \ - width * depth / 8, height); \ -} - -COPY(top, 8) -COPY(bottom, 8) - -COPY(top, 16) -COPY(bottom, 16) - -COPY(top, 32) -COPY(bottom, 32) - -#undef COPY - -#define BLEND_NORMAL(name, type) \ -static void blend_normal_##name(const uint8_t *_top, ptrdiff_t top_linesize, \ - const uint8_t *_bottom, ptrdiff_t bottom_linesize,\ - uint8_t *_dst, ptrdiff_t dst_linesize, \ - ptrdiff_t width, ptrdiff_t height, \ - FilterParams *param, double *values, int starty) \ -{ \ - const type *top = (type*)_top; \ - const type *bottom = (type*)_bottom; \ - type *dst = (type*)_dst; \ - const float opacity = param->opacity; \ - \ - dst_linesize /= sizeof(type); \ - top_linesize /= sizeof(type); \ - bottom_linesize /= sizeof(type); \ - \ - for (int i = 0; i < height; i++) { \ - for (int j = 0; j < width; j++) { \ - dst[j] = top[j] * opacity + bottom[j] * (1.f - opacity); \ - } \ - dst += dst_linesize; \ - top += top_linesize; \ - bottom += bottom_linesize; \ - } \ -} - -BLEND_NORMAL(8bit, uint8_t) -BLEND_NORMAL(16bit, uint16_t) -BLEND_NORMAL(32bit, float) - #define DEFINE_BLEND_EXPR(type, name, div) \ static void blend_expr_## name(const uint8_t *_top, ptrdiff_t top_linesize, \ const uint8_t *_bottom, ptrdiff_t bottom_linesize, \ @@ -365,99 +284,6 @@ static av_cold void uninit(AVFilterContext *ctx) av_expr_free(s->params[i].e); } -#define DEFINE_INIT_BLEND_FUNC(depth, nbits) \ -static av_cold void init_blend_func_##depth##_##nbits##bit(FilterParams *param) \ -{ \ - switch (param->mode) { \ - case BLEND_ADDITION: param->blend = blend_addition_##depth##bit; break; \ - case BLEND_GRAINMERGE: param->blend = blend_grainmerge_##depth##bit; break; \ - case BLEND_AND: param->blend = blend_and_##depth##bit; break; \ - case BLEND_AVERAGE: param->blend = blend_average_##depth##bit; break; \ - case BLEND_BURN: param->blend = blend_burn_##depth##bit; break; \ - case BLEND_DARKEN: param->blend = blend_darken_##depth##bit; break; \ - case BLEND_DIFFERENCE: param->blend = blend_difference_##depth##bit; break; \ - case BLEND_GRAINEXTRACT: param->blend = blend_grainextract_##depth##bit; break; \ - case BLEND_DIVIDE: param->blend = blend_divide_##depth##bit; break; \ - case BLEND_DODGE: param->blend = blend_dodge_##depth##bit; break; \ - case BLEND_EXCLUSION: param->blend = blend_exclusion_##depth##bit; break; \ - case BLEND_EXTREMITY: param->blend = blend_extremity_##depth##bit; break; \ - case BLEND_FREEZE: param->blend = blend_freeze_##depth##bit; break; \ - case BLEND_GLOW: param->blend = blend_glow_##depth##bit; break; \ - case BLEND_HARDLIGHT: param->blend = blend_hardlight_##depth##bit; break; \ - case BLEND_HARDMIX: param->blend = blend_hardmix_##depth##bit; break; \ - case BLEND_HEAT: param->blend = blend_heat_##depth##bit; break; \ - case BLEND_LIGHTEN: param->blend = blend_lighten_##depth##bit; break; \ - case BLEND_LINEARLIGHT: param->blend = blend_linearlight_##depth##bit; break; \ - case BLEND_MULTIPLY: param->blend = blend_multiply_##depth##bit; break; \ - case BLEND_MULTIPLY128: param->blend = blend_multiply128_##depth##bit; break; \ - case BLEND_NEGATION: param->blend = blend_negation_##depth##bit; break; \ - case BLEND_NORMAL: param->blend = blend_normal_##nbits##bit; break; \ - case BLEND_OR: param->blend = blend_or_##depth##bit; break; \ - case BLEND_OVERLAY: param->blend = blend_overlay_##depth##bit; break; \ - case BLEND_PHOENIX: param->blend = blend_phoenix_##depth##bit; break; \ - case BLEND_PINLIGHT: param->blend = blend_pinlight_##depth##bit; break; \ - case BLEND_REFLECT: param->blend = blend_reflect_##depth##bit; break; \ - case BLEND_SCREEN: param->blend = blend_screen_##depth##bit; break; \ - case BLEND_SOFTLIGHT: param->blend = blend_softlight_##depth##bit; break; \ - case BLEND_SUBTRACT: param->blend = blend_subtract_##depth##bit; break; \ - case BLEND_VIVIDLIGHT: param->blend = blend_vividlight_##depth##bit; break; \ - case BLEND_XOR: param->blend = blend_xor_##depth##bit; break; \ - case BLEND_SOFTDIFFERENCE:param->blend=blend_softdifference_##depth##bit;break; \ - case BLEND_GEOMETRIC: param->blend = blend_geometric_##depth##bit; break; \ - case BLEND_HARMONIC: param->blend = blend_harmonic_##depth##bit; break; \ - case BLEND_BLEACH: param->blend = blend_bleach_##depth##bit; break; \ - case BLEND_STAIN: param->blend = blend_stain_##depth##bit; break; \ - case BLEND_INTERPOLATE: param->blend = blend_interpolate_##depth##bit; break; \ - case BLEND_HARDOVERLAY: param->blend = blend_hardoverlay_##depth##bit; break; \ - } \ -} -DEFINE_INIT_BLEND_FUNC(8, 8) -DEFINE_INIT_BLEND_FUNC(9, 16) -DEFINE_INIT_BLEND_FUNC(10, 16) -DEFINE_INIT_BLEND_FUNC(12, 16) -DEFINE_INIT_BLEND_FUNC(14, 16) -DEFINE_INIT_BLEND_FUNC(16, 16) -DEFINE_INIT_BLEND_FUNC(32, 32) - -void ff_blend_init(FilterParams *param, int depth) -{ - switch (depth) { - case 8: - init_blend_func_8_8bit(param); - break; - case 9: - init_blend_func_9_16bit(param); - break; - case 10: - init_blend_func_10_16bit(param); - break; - case 12: - init_blend_func_12_16bit(param); - break; - case 14: - init_blend_func_14_16bit(param); - break; - case 16: - init_blend_func_16_16bit(param); - break; - case 32: - init_blend_func_32_32bit(param); - break; - } - - if (param->opacity == 0 && param->mode != BLEND_NORMAL) { - param->blend = depth > 8 ? depth > 16 ? blend_copytop_32 : blend_copytop_16 : blend_copytop_8; - } else if (param->mode == BLEND_NORMAL) { - if (param->opacity == 1) - param->blend = depth > 8 ? depth > 16 ? blend_copytop_32 : blend_copytop_16 : blend_copytop_8; - else if (param->opacity == 0) - param->blend = depth > 8 ? depth > 16 ? blend_copybottom_32 : blend_copybottom_16 : blend_copybottom_8; - } - - if (ARCH_X86) - ff_blend_init_x86(param, depth); -} - static int config_params(AVFilterContext *ctx) { BlendContext *s = ctx->priv; diff --git a/libavfilter/vf_blend_init.h b/libavfilter/vf_blend_init.h new file mode 100644 index 0000000000..5fb2599490 --- /dev/null +++ b/libavfilter/vf_blend_init.h @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2013 Paul B Mahol + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFILTER_BLEND_INIT_H +#define AVFILTER_BLEND_INIT_H + +#include "config.h" +#include "libavutil/attributes.h" +#include "libavutil/imgutils.h" +#include "blend.h" + +#define DEPTH 8 +#include "blend_modes.c" + +#undef DEPTH +#define DEPTH 9 +#include "blend_modes.c" + +#undef DEPTH +#define DEPTH 10 +#include "blend_modes.c" + +#undef DEPTH +#define DEPTH 12 +#include "blend_modes.c" + +#undef DEPTH +#define DEPTH 14 +#include "blend_modes.c" + +#undef DEPTH +#define DEPTH 16 +#include "blend_modes.c" + +#undef DEPTH +#define DEPTH 32 +#include "blend_modes.c" + +#define COPY(src, depth) \ +static void blend_copy ## src##_##depth(const uint8_t *top, ptrdiff_t top_linesize, \ + const uint8_t *bottom, ptrdiff_t bottom_linesize,\ + uint8_t *dst, ptrdiff_t dst_linesize, \ + ptrdiff_t width, ptrdiff_t height, \ + FilterParams *param, double *values, int starty) \ +{ \ + av_image_copy_plane(dst, dst_linesize, src, src ## _linesize, \ + width * depth / 8, height); \ +} + +COPY(top, 8) +COPY(bottom, 8) + +COPY(top, 16) +COPY(bottom, 16) + +COPY(top, 32) +COPY(bottom, 32) + +#undef COPY + +#define BLEND_NORMAL(name, type) \ +static void blend_normal_##name(const uint8_t *_top, ptrdiff_t top_linesize, \ + const uint8_t *_bottom, ptrdiff_t bottom_linesize,\ + uint8_t *_dst, ptrdiff_t dst_linesize, \ + ptrdiff_t width, ptrdiff_t height, \ + FilterParams *param, double *values, int starty) \ +{ \ + const type *top = (type*)_top; \ + const type *bottom = (type*)_bottom; \ + type *dst = (type*)_dst; \ + const float opacity = param->opacity; \ + \ + dst_linesize /= sizeof(type); \ + top_linesize /= sizeof(type); \ + bottom_linesize /= sizeof(type); \ + \ + for (int i = 0; i < height; i++) { \ + for (int j = 0; j < width; j++) { \ + dst[j] = top[j] * opacity + bottom[j] * (1.f - opacity); \ + } \ + dst += dst_linesize; \ + top += top_linesize; \ + bottom += bottom_linesize; \ + } \ +} + +BLEND_NORMAL(8bit, uint8_t) +BLEND_NORMAL(16bit, uint16_t) +BLEND_NORMAL(32bit, float) + +#define DEFINE_INIT_BLEND_FUNC(depth, nbits) \ +static av_cold void init_blend_func_##depth##_##nbits##bit(FilterParams *param) \ +{ \ + switch (param->mode) { \ + case BLEND_ADDITION: param->blend = blend_addition_##depth##bit; break; \ + case BLEND_GRAINMERGE: param->blend = blend_grainmerge_##depth##bit; break; \ + case BLEND_AND: param->blend = blend_and_##depth##bit; break; \ + case BLEND_AVERAGE: param->blend = blend_average_##depth##bit; break; \ + case BLEND_BURN: param->blend = blend_burn_##depth##bit; break; \ + case BLEND_DARKEN: param->blend = blend_darken_##depth##bit; break; \ + case BLEND_DIFFERENCE: param->blend = blend_difference_##depth##bit; break; \ + case BLEND_GRAINEXTRACT: param->blend = blend_grainextract_##depth##bit; break; \ + case BLEND_DIVIDE: param->blend = blend_divide_##depth##bit; break; \ + case BLEND_DODGE: param->blend = blend_dodge_##depth##bit; break; \ + case BLEND_EXCLUSION: param->blend = blend_exclusion_##depth##bit; break; \ + case BLEND_EXTREMITY: param->blend = blend_extremity_##depth##bit; break; \ + case BLEND_FREEZE: param->blend = blend_freeze_##depth##bit; break; \ + case BLEND_GLOW: param->blend = blend_glow_##depth##bit; break; \ + case BLEND_HARDLIGHT: param->blend = blend_hardlight_##depth##bit; break; \ + case BLEND_HARDMIX: param->blend = blend_hardmix_##depth##bit; break; \ + case BLEND_HEAT: param->blend = blend_heat_##depth##bit; break; \ + case BLEND_LIGHTEN: param->blend = blend_lighten_##depth##bit; break; \ + case BLEND_LINEARLIGHT: param->blend = blend_linearlight_##depth##bit; break; \ + case BLEND_MULTIPLY: param->blend = blend_multiply_##depth##bit; break; \ + case BLEND_MULTIPLY128: param->blend = blend_multiply128_##depth##bit; break; \ + case BLEND_NEGATION: param->blend = blend_negation_##depth##bit; break; \ + case BLEND_NORMAL: param->blend = blend_normal_##nbits##bit; break; \ + case BLEND_OR: param->blend = blend_or_##depth##bit; break; \ + case BLEND_OVERLAY: param->blend = blend_overlay_##depth##bit; break; \ + case BLEND_PHOENIX: param->blend = blend_phoenix_##depth##bit; break; \ + case BLEND_PINLIGHT: param->blend = blend_pinlight_##depth##bit; break; \ + case BLEND_REFLECT: param->blend = blend_reflect_##depth##bit; break; \ + case BLEND_SCREEN: param->blend = blend_screen_##depth##bit; break; \ + case BLEND_SOFTLIGHT: param->blend = blend_softlight_##depth##bit; break; \ + case BLEND_SUBTRACT: param->blend = blend_subtract_##depth##bit; break; \ + case BLEND_VIVIDLIGHT: param->blend = blend_vividlight_##depth##bit; break; \ + case BLEND_XOR: param->blend = blend_xor_##depth##bit; break; \ + case BLEND_SOFTDIFFERENCE:param->blend=blend_softdifference_##depth##bit;break; \ + case BLEND_GEOMETRIC: param->blend = blend_geometric_##depth##bit; break; \ + case BLEND_HARMONIC: param->blend = blend_harmonic_##depth##bit; break; \ + case BLEND_BLEACH: param->blend = blend_bleach_##depth##bit; break; \ + case BLEND_STAIN: param->blend = blend_stain_##depth##bit; break; \ + case BLEND_INTERPOLATE: param->blend = blend_interpolate_##depth##bit; break; \ + case BLEND_HARDOVERLAY: param->blend = blend_hardoverlay_##depth##bit; break; \ + } \ +} +DEFINE_INIT_BLEND_FUNC(8, 8) +DEFINE_INIT_BLEND_FUNC(9, 16) +DEFINE_INIT_BLEND_FUNC(10, 16) +DEFINE_INIT_BLEND_FUNC(12, 16) +DEFINE_INIT_BLEND_FUNC(14, 16) +DEFINE_INIT_BLEND_FUNC(16, 16) +DEFINE_INIT_BLEND_FUNC(32, 32) + +static av_unused void ff_blend_init(FilterParams *param, int depth) +{ + switch (depth) { + case 8: + init_blend_func_8_8bit(param); + break; + case 9: + init_blend_func_9_16bit(param); + break; + case 10: + init_blend_func_10_16bit(param); + break; + case 12: + init_blend_func_12_16bit(param); + break; + case 14: + init_blend_func_14_16bit(param); + break; + case 16: + init_blend_func_16_16bit(param); + break; + case 32: + init_blend_func_32_32bit(param); + break; + } + + if (param->opacity == 0 && param->mode != BLEND_NORMAL) { + param->blend = depth > 8 ? depth > 16 ? blend_copytop_32 : blend_copytop_16 : blend_copytop_8; + } else if (param->mode == BLEND_NORMAL) { + if (param->opacity == 1) + param->blend = depth > 8 ? depth > 16 ? blend_copytop_32 : blend_copytop_16 : blend_copytop_8; + else if (param->opacity == 0) + param->blend = depth > 8 ? depth > 16 ? blend_copybottom_32 : blend_copybottom_16 : blend_copybottom_8; + } + + if (ARCH_X86) + ff_blend_init_x86(param, depth); +} + +#endif /* AVFILTER_BLEND_INIT_H */ diff --git a/tests/checkasm/vf_blend.c b/tests/checkasm/vf_blend.c index bdd21d4986..484ed0b1d8 100644 --- a/tests/checkasm/vf_blend.c +++ b/tests/checkasm/vf_blend.c @@ -20,7 +20,7 @@ #include #include "checkasm.h" -#include "libavfilter/blend.h" +#include "libavfilter/vf_blend_init.h" #include "libavutil/common.h" #include "libavutil/internal.h" #include "libavutil/intreadwrite.h"