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 #ifndef __VEPU5XX_COMMON_H__ 18 #define __VEPU5XX_COMMON_H__ 19 20 #include "rk_venc_cmd.h" 21 #include "mpp_device.h" 22 23 /* 24 * Invert color threshold is for the absolute difference between background 25 * and foregroud color. 26 * If background color and foregroud color are close enough then trigger the 27 * invert color process. 28 */ 29 #define ENC_DEFAULT_OSD_INV_THR 15 30 #define SET_OSD_INV_THR(index, reg, region)\ 31 if(region[index].inverse) \ 32 reg.osd_ithd_r##index = ENC_DEFAULT_OSD_INV_THR; 33 34 typedef enum Vepu5xxOsdPltType_e { 35 VEPU5xx_OSD_PLT_TYPE_USERDEF = 0, 36 VEPU5xx_OSD_PLT_TYPE_DEFAULT = 1, 37 } Vepu5xxOsdPltType; 38 39 typedef enum VepuFmt_e { 40 VEPU5xx_FMT_BGRA8888, // 0 41 VEPU5xx_FMT_BGR888, // 1 42 VEPU5xx_FMT_BGR565, // 2 43 VEPU5xx_FMT_ARGB1555, // 3 44 VEPU5xx_FMT_YUV422SP, // 4 45 VEPU5xx_FMT_YUV422P, // 5 46 VEPU5xx_FMT_YUV420SP, // 6 47 VEPU5xx_FMT_YUV420P, // 7 48 VEPU5xx_FMT_YUYV422, // 8 49 VEPU5xx_FMT_UYVY422, // 9 50 VEPU5xx_FMT_YUV400, // 10 51 VEPU5xx_FMT_AYUV2BPP, // 11 52 VEPU5xx_FMT_YUV444SP, // 12 53 VEPU5xx_FMT_YUV444P, // 13 54 VEPU5xx_FMT_ARGB4444, // 14 55 VEPU5xx_FMT_AYUV1BPP, // 15 56 VEPU5xx_FMT_BUTT, // 16 57 } VepuFmt; 58 59 typedef struct VepuFmtCfg_t { 60 VepuFmt format; 61 RK_U32 alpha_swap; 62 RK_U32 rbuv_swap; 63 RK_U32 src_range; 64 RK_U32 src_endian; 65 const RK_S32 *weight; 66 const RK_S32 *offset; 67 } VepuFmtCfg; 68 69 typedef struct Vepu5xxOsdCfg_t { 70 void *reg_base; 71 MppDev dev; 72 MppDevRegOffCfgs *reg_cfg; 73 MppEncOSDPltCfg *plt_cfg; 74 MppEncOSDData *osd_data; 75 MppEncOSDData2 *osd_data2; 76 } Vepu5xxOsdCfg; 77 78 typedef struct VepuRgb2YuvCoeffs_t { 79 RK_S16 r_coeff; 80 RK_S16 g_coeff; 81 RK_S16 b_coeff; 82 RK_S16 offset; 83 } VepuRgb2YuvCoeffs; 84 85 /* formula: y(r, g, b) = (r_coeff x r + g_coeff x g + b_coeff x b + 128) >> 8 + offset */ 86 typedef struct VepuRgb2YuvCfg_t { 87 /* YUV colorspace type */ 88 MppFrameColorSpace color; 89 /* MPEG vs JPEG YUV range */ 90 MppFrameColorRange dst_range; 91 /* coeffs of rgb 2 yuv */ 92 VepuRgb2YuvCoeffs _2y; 93 VepuRgb2YuvCoeffs _2u; 94 VepuRgb2YuvCoeffs _2v; 95 } VepuRgb2YuvCfg; 96 97 /** 98 * @brief Get rgb2yuv cfg by color range and color space. If not found, return default cfg. 99 * default cfg's yuv range - limit. 100 * default cfg's color space - BT.601. 101 */ 102 const VepuRgb2YuvCfg* get_rgb2yuv_cfg(MppFrameColorRange range, MppFrameColorSpace color); 103 104 MPP_RET copy2osd2(MppEncOSDData2* dst, MppEncOSDData *src1, MppEncOSDData2 *src2); 105 106 MPP_RET vepu5xx_set_fmt(VepuFmtCfg *cfg, MppFrameFormat format); 107 108 extern const RK_U32 vepu580_540_h264_flat_scl_tab[576]; 109 110 extern const RK_U32 klut_weight[24]; 111 extern const RK_U32 lamd_satd_qp[52]; 112 extern const RK_U32 lamd_moda_qp[52]; 113 extern const RK_U32 lamd_modb_qp[52]; 114 extern const RK_U32 lamd_satd_qp_510[52]; 115 116 #endif /* __VEPU5XX_COMMON_H__ */