1 /*
2 * Copyright 2022 Rockchip Electronics Co. LTD
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define MODULE_TAG "vepu5xx_common.c"
18
19 #include "mpp_log.h"
20 #include "mpp_common.h"
21 #include "vepu5xx_common.h"
22
23 const VepuRgb2YuvCfg vepu_rgb2limit_yuv_cfg_set[] = {
24 /* MPP_BT601_FULL_RGB_TO_LIMIT_YUV */
25 {
26 .color = MPP_FRAME_SPC_RGB, .dst_range = MPP_FRAME_RANGE_UNSPECIFIED,
27 ._2y = {.r_coeff = 66, .g_coeff = 129, .b_coeff = 25, .offset = 16},
28 ._2u = {.r_coeff = -38, .g_coeff = -74, .b_coeff = 112, .offset = 128},
29 ._2v = {.r_coeff = 112, .g_coeff = -94, .b_coeff = -18, .offset = 128},
30 },
31 /* MPP_BT709_FULL_RGB_TO_LIMIT_YUV */
32 {
33 .color = MPP_FRAME_SPC_BT709, .dst_range = MPP_FRAME_RANGE_UNSPECIFIED,
34 ._2y = {.r_coeff = 47, .g_coeff = 157, .b_coeff = 16, .offset = 16},
35 ._2u = {.r_coeff = -26, .g_coeff = -87, .b_coeff = 112, .offset = 128},
36 ._2v = {.r_coeff = 112, .g_coeff = -102, .b_coeff = -10, .offset = 128},
37 },
38 };
39
40
41 const VepuRgb2YuvCfg vepu_rgb2full_yuv_cfg_set[] = {
42 /* MPP_BT601_FULL_RGB_TO_FULL_YUV */
43 {
44 .color = MPP_FRAME_SPC_RGB, .dst_range = MPP_FRAME_RANGE_JPEG,
45 ._2y = {.r_coeff = 77, .g_coeff = 150, .b_coeff = 29, .offset = 0},
46 ._2u = {.r_coeff = -43, .g_coeff = -85, .b_coeff = 128, .offset = 128},
47 ._2v = {.r_coeff = 128, .g_coeff = -107, .b_coeff = -21, .offset = 128},
48 },
49 /* MPP_BT709_FULL_RGB_TO_FULL_YUV */
50 {
51 .color = MPP_FRAME_SPC_BT709, .dst_range = MPP_FRAME_RANGE_JPEG,
52 ._2y = {.r_coeff = 54, .g_coeff = 183, .b_coeff = 18, .offset = 0},
53 ._2u = {.r_coeff = -29, .g_coeff = -99, .b_coeff = 128, .offset = 128},
54 ._2v = {.r_coeff = 128, .g_coeff = -116, .b_coeff = -12, .offset = 128},
55 },
56 };
57
get_rgb2yuv_cfg(MppFrameColorRange range,MppFrameColorSpace color)58 const VepuRgb2YuvCfg *get_rgb2yuv_cfg(MppFrameColorRange range, MppFrameColorSpace color)
59 {
60 const VepuRgb2YuvCfg *cfg;
61 RK_U32 size;
62 RK_U32 i;
63
64 /* only jpeg full range, others limit range */
65 if (range == MPP_FRAME_RANGE_JPEG) {
66 /* set default cfg BT.601 */
67 cfg = &vepu_rgb2full_yuv_cfg_set[0];
68 size = MPP_ARRAY_ELEMS(vepu_rgb2full_yuv_cfg_set);
69 } else {
70 /* set default cfg BT.601 */
71 cfg = &vepu_rgb2limit_yuv_cfg_set[0];
72 size = MPP_ARRAY_ELEMS(vepu_rgb2limit_yuv_cfg_set);
73 }
74
75 for (i = 0; i < size; i++)
76 if (cfg[i].color == color)
77 return &cfg[i];
78
79 return cfg;
80 }