// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2019 Mentor Graphics Inc. */ #include <linux/types.h> #include <linux/init.h> #include <linux/errno.h> #include <linux/err.h> #include <linux/sizes.h> #include "ipu-prv.h" #define QUANT_MAP(q) … /* identity matrix */ static const struct ipu_ic_csc_params identity = …; /* * RGB full-range to RGB limited-range * * R_lim = 0.8588 * R_full + 16 * G_lim = 0.8588 * G_full + 16 * B_lim = 0.8588 * B_full + 16 */ static const struct ipu_ic_csc_params rgbf2rgbl = …; /* * RGB limited-range to RGB full-range * * R_full = 1.1644 * (R_lim - 16) * G_full = 1.1644 * (G_lim - 16) * B_full = 1.1644 * (B_lim - 16) */ static const struct ipu_ic_csc_params rgbl2rgbf = …; /* * YUV full-range to YUV limited-range * * Y_lim = 0.8588 * Y_full + 16 * Cb_lim = 0.8784 * (Cb_full - 128) + 128 * Cr_lim = 0.8784 * (Cr_full - 128) + 128 */ static const struct ipu_ic_csc_params yuvf2yuvl = …; /* * YUV limited-range to YUV full-range * * Y_full = 1.1644 * (Y_lim - 16) * Cb_full = 1.1384 * (Cb_lim - 128) + 128 * Cr_full = 1.1384 * (Cr_lim - 128) + 128 */ static const struct ipu_ic_csc_params yuvl2yuvf = …; static const struct ipu_ic_csc_params *rgb2rgb[] = …; static const struct ipu_ic_csc_params *yuv2yuv[] = …; /* * BT.601 RGB full-range to YUV full-range * * Y = .2990 * R + .5870 * G + .1140 * B * U = -.1687 * R - .3313 * G + .5000 * B + 128 * V = .5000 * R - .4187 * G - .0813 * B + 128 */ static const struct ipu_ic_csc_params rgbf2yuvf_601 = …; /* BT.601 RGB full-range to YUV limited-range */ static const struct ipu_ic_csc_params rgbf2yuvl_601 = …; /* BT.601 RGB limited-range to YUV full-range */ static const struct ipu_ic_csc_params rgbl2yuvf_601 = …; /* BT.601 RGB limited-range to YUV limited-range */ static const struct ipu_ic_csc_params rgbl2yuvl_601 = …; /* * BT.601 YUV full-range to RGB full-range * * R = 1. * Y + 0 * (Cb - 128) + 1.4020 * (Cr - 128) * G = 1. * Y - .3441 * (Cb - 128) - .7141 * (Cr - 128) * B = 1. * Y + 1.7720 * (Cb - 128) + 0 * (Cr - 128) * * equivalently (factoring out the offsets): * * R = 1. * Y + 0 * Cb + 1.4020 * Cr - 179.456 * G = 1. * Y - .3441 * Cb - .7141 * Cr + 135.450 * B = 1. * Y + 1.7720 * Cb + 0 * Cr - 226.816 */ static const struct ipu_ic_csc_params yuvf2rgbf_601 = …; /* BT.601 YUV full-range to RGB limited-range */ static const struct ipu_ic_csc_params yuvf2rgbl_601 = …; /* BT.601 YUV limited-range to RGB full-range */ static const struct ipu_ic_csc_params yuvl2rgbf_601 = …; /* BT.601 YUV limited-range to RGB limited-range */ static const struct ipu_ic_csc_params yuvl2rgbl_601 = …; static const struct ipu_ic_csc_params *rgb2yuv_601[] = …; static const struct ipu_ic_csc_params *yuv2rgb_601[] = …; /* * REC.709 encoding from RGB full range to YUV full range: * * Y = .2126 * R + .7152 * G + .0722 * B * U = -.1146 * R - .3854 * G + .5000 * B + 128 * V = .5000 * R - .4542 * G - .0458 * B + 128 */ static const struct ipu_ic_csc_params rgbf2yuvf_709 = …; /* Rec.709 RGB full-range to YUV limited-range */ static const struct ipu_ic_csc_params rgbf2yuvl_709 = …; /* Rec.709 RGB limited-range to YUV full-range */ static const struct ipu_ic_csc_params rgbl2yuvf_709 = …; /* Rec.709 RGB limited-range to YUV limited-range */ static const struct ipu_ic_csc_params rgbl2yuvl_709 = …; /* * Inverse REC.709 encoding from YUV full range to RGB full range: * * R = 1. * Y + 0 * (Cb - 128) + 1.5748 * (Cr - 128) * G = 1. * Y - .1873 * (Cb - 128) - .4681 * (Cr - 128) * B = 1. * Y + 1.8556 * (Cb - 128) + 0 * (Cr - 128) * * equivalently (factoring out the offsets): * * R = 1. * Y + 0 * Cb + 1.5748 * Cr - 201.574 * G = 1. * Y - .1873 * Cb - .4681 * Cr + 83.891 * B = 1. * Y + 1.8556 * Cb + 0 * Cr - 237.517 */ static const struct ipu_ic_csc_params yuvf2rgbf_709 = …; /* Rec.709 YUV full-range to RGB limited-range */ static const struct ipu_ic_csc_params yuvf2rgbl_709 = …; /* Rec.709 YUV limited-range to RGB full-range */ static const struct ipu_ic_csc_params yuvl2rgbf_709 = …; /* Rec.709 YUV limited-range to RGB limited-range */ static const struct ipu_ic_csc_params yuvl2rgbl_709 = …; static const struct ipu_ic_csc_params *rgb2yuv_709[] = …; static const struct ipu_ic_csc_params *yuv2rgb_709[] = …; static int calc_csc_coeffs(struct ipu_ic_csc *csc) { … } int __ipu_ic_calc_csc(struct ipu_ic_csc *csc) { … } EXPORT_SYMBOL_GPL(…); int ipu_ic_calc_csc(struct ipu_ic_csc *csc, enum v4l2_ycbcr_encoding in_enc, enum v4l2_quantization in_quant, enum ipu_color_space in_cs, enum v4l2_ycbcr_encoding out_enc, enum v4l2_quantization out_quant, enum ipu_color_space out_cs) { … } EXPORT_SYMBOL_GPL(…);