From patchwork Tue Jan 22 07:15:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruiling Song X-Patchwork-Id: 11822 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 EE1D644CDA1 for ; Tue, 22 Jan 2019 09:18:35 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 20C3768AAE3; Tue, 22 Jan 2019 09:18:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D26868A89B for ; Tue, 22 Jan 2019 09:18:17 +0200 (EET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jan 2019 23:18:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,505,1539673200"; d="scan'208";a="293351647" Received: from ruiling-skl2.sh.intel.com ([10.239.158.154]) by orsmga005.jf.intel.com with ESMTP; 21 Jan 2019 23:18:30 -0800 From: Ruiling Song To: ffmpeg-devel@ffmpeg.org Date: Tue, 22 Jan 2019 15:15:36 +0800 Message-Id: <1548141337-32109-4-git-send-email-ruiling.song@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548141337-32109-1-git-send-email-ruiling.song@intel.com> References: <1548141337-32109-1-git-send-email-ruiling.song@intel.com> Subject: [FFmpeg-devel] [PATCH 4/5] lavfi/tonemap_opencl: reuse color matrix calculation from colorspace.c 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: Ruiling Song MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Ruiling Song --- libavfilter/opencl/colorspace_common.cl | 25 ------------- libavfilter/vf_tonemap_opencl.c | 64 +++++++++++++++------------------ 2 files changed, 29 insertions(+), 60 deletions(-) diff --git a/libavfilter/opencl/colorspace_common.cl b/libavfilter/opencl/colorspace_common.cl index 94a4dd0..1d68a54 100644 --- a/libavfilter/opencl/colorspace_common.cl +++ b/libavfilter/opencl/colorspace_common.cl @@ -39,31 +39,6 @@ constant const float ST2084_C1 = 0.8359375f; constant const float ST2084_C2 = 18.8515625f; constant const float ST2084_C3 = 18.6875f; -__constant float yuv2rgb_bt2020[] = { - 1.0f, 0.0f, 1.4746f, - 1.0f, -0.16455f, -0.57135f, - 1.0f, 1.8814f, 0.0f -}; - -__constant float yuv2rgb_bt709[] = { - 1.0f, 0.0f, 1.5748f, - 1.0f, -0.18732f, -0.46812f, - 1.0f, 1.8556f, 0.0f -}; - -__constant float rgb2yuv_bt709[] = { - 0.2126f, 0.7152f, 0.0722f, - -0.11457f, -0.38543f, 0.5f, - 0.5f, -0.45415f, -0.04585f -}; - -__constant float rgb2yuv_bt2020[] ={ - 0.2627f, 0.678f, 0.0593f, - -0.1396f, -0.36037f, 0.5f, - 0.5f, -0.4598f, -0.0402f, -}; - - float get_luma_dst(float3 c) { return luma_dst.x * c.x + luma_dst.y * c.y + luma_dst.z * c.z; } diff --git a/libavfilter/vf_tonemap_opencl.c b/libavfilter/vf_tonemap_opencl.c index ae3f98d..315ead4 100644 --- a/libavfilter/vf_tonemap_opencl.c +++ b/libavfilter/vf_tonemap_opencl.c @@ -18,7 +18,6 @@ #include #include "libavutil/avassert.h" -#include "libavutil/bprint.h" #include "libavutil/common.h" #include "libavutil/imgutils.h" #include "libavutil/mem.h" @@ -35,7 +34,6 @@ // TODO: // - separate peak-detection from tone-mapping kernel to solve // one-frame-delay issue. -// - import colorspace matrix generation from vf_colorspace.c // - more format support #define DETECTION_FRAMES 63 @@ -73,16 +71,6 @@ typedef struct TonemapOpenCLContext { cl_mem util_mem; } TonemapOpenCLContext; -static const char *yuv_coff[AVCOL_SPC_NB] = { - [AVCOL_SPC_BT709] = "rgb2yuv_bt709", - [AVCOL_SPC_BT2020_NCL] = "rgb2yuv_bt2020", -}; - -static const char *rgb_coff[AVCOL_SPC_NB] = { - [AVCOL_SPC_BT709] = "yuv2rgb_bt709", - [AVCOL_SPC_BT2020_NCL] = "yuv2rgb_bt2020", -}; - static const char *linearize_funcs[AVCOL_TRC_NB] = { [AVCOL_TRC_SMPTE2084] = "eotf_st2084", [AVCOL_TRC_ARIB_STD_B67] = "inverse_oetf_hlg", @@ -93,11 +81,6 @@ static const char *delinearize_funcs[AVCOL_TRC_NB] = { [AVCOL_TRC_BT2020_10] = "inverse_eotf_bt1886", }; -static const struct LumaCoefficients luma_coefficients[AVCOL_SPC_NB] = { - [AVCOL_SPC_BT709] = { 0.2126, 0.7152, 0.0722 }, - [AVCOL_SPC_BT2020_NCL] = { 0.2627, 0.6780, 0.0593 }, -}; - static const struct PrimaryCoefficients primaries_table[AVCOL_PRI_NB] = { [AVCOL_PRI_BT709] = { 0.640, 0.330, 0.300, 0.600, 0.150, 0.060 }, [AVCOL_PRI_BT2020] = { 0.708, 0.292, 0.170, 0.797, 0.131, 0.046 }, @@ -137,8 +120,8 @@ static int tonemap_opencl_init(AVFilterContext *avctx) { TonemapOpenCLContext *ctx = avctx->priv; int rgb2rgb_passthrough = 1; - double rgb2rgb[3][3]; - struct LumaCoefficients luma_src, luma_dst; + double rgb2rgb[3][3], rgb2yuv[3][3], yuv2rgb[3][3]; + const struct LumaCoefficients *luma_src, *luma_dst; cl_int cle; int err; AVBPrint header; @@ -215,27 +198,37 @@ static int tonemap_opencl_init(AVFilterContext *avctx) if (rgb2rgb_passthrough) av_bprintf(&header, "#define RGB2RGB_PASSTHROUGH\n"); - else { - av_bprintf(&header, "__constant float rgb2rgb[9] = {\n"); - av_bprintf(&header, " %.4ff, %.4ff, %.4ff,\n", - rgb2rgb[0][0], rgb2rgb[0][1], rgb2rgb[0][2]); - av_bprintf(&header, " %.4ff, %.4ff, %.4ff,\n", - rgb2rgb[1][0], rgb2rgb[1][1], rgb2rgb[1][2]); - av_bprintf(&header, " %.4ff, %.4ff, %.4ff};\n", - rgb2rgb[2][0], rgb2rgb[2][1], rgb2rgb[2][2]); + else + ff_opencl_print_const_matrix_3x3(&header, "rgb2rgb", rgb2rgb); + + + luma_src = ff_get_luma_coefficients(ctx->colorspace_in); + if (!luma_src) { + err = AVERROR(EINVAL); + av_log(avctx, AV_LOG_ERROR, "unsupported input colorspace %d (%s)\n", + ctx->colorspace_in, av_color_space_name(ctx->colorspace_in)); + goto fail; } - av_bprintf(&header, "#define rgb_matrix %s\n", - rgb_coff[ctx->colorspace_in]); - av_bprintf(&header, "#define yuv_matrix %s\n", - yuv_coff[ctx->colorspace_out]); + luma_dst = ff_get_luma_coefficients(ctx->colorspace_out); + if (!luma_dst) { + err = AVERROR(EINVAL); + av_log(avctx, AV_LOG_ERROR, "unsupported output colorspace %d (%s)\n", + ctx->colorspace_out, av_color_space_name(ctx->colorspace_out)); + goto fail; + } + + ff_fill_rgb2yuv_table(luma_dst, rgb2yuv); + ff_opencl_print_const_matrix_3x3(&header, "yuv_matrix", rgb2yuv); + + ff_fill_rgb2yuv_table(luma_src, rgb2yuv); + ff_matrix_invert_3x3(rgb2yuv, yuv2rgb); + ff_opencl_print_const_matrix_3x3(&header, "rgb_matrix", yuv2rgb); - luma_src = luma_coefficients[ctx->colorspace_in]; - luma_dst = luma_coefficients[ctx->colorspace_out]; av_bprintf(&header, "constant float3 luma_src = {%.4ff, %.4ff, %.4ff};\n", - luma_src.cr, luma_src.cg, luma_src.cb); + luma_src->cr, luma_src->cg, luma_src->cb); av_bprintf(&header, "constant float3 luma_dst = {%.4ff, %.4ff, %.4ff};\n", - luma_dst.cr, luma_dst.cg, luma_dst.cb); + luma_dst->cr, luma_dst->cg, luma_dst->cb); av_bprintf(&header, "#define linearize %s\n", linearize_funcs[ctx->trc_in]); av_bprintf(&header, "#define delinearize %s\n", @@ -276,6 +269,7 @@ static int tonemap_opencl_init(AVFilterContext *avctx) return 0; fail: + av_bprint_finalize(&header, NULL); if (ctx->util_mem) clReleaseMemObject(ctx->util_mem); if (ctx->command_queue)