History

media: rkisp1: Add support for CAC

The CAC block implements chromatic aberration correction. Expose it to userspace using the extensible parameters format. This was tested on the i.MX8MP platform, but based on available documentation it is also present in the RK3399 variant (V10). Thus presumably also in later versions, so no feature flag is introduced.

Barnabás Pőcze committed 6 months ago

Commit 27caa941 parent c4c01c43 files · +187 −3Browse files

Showing the changes to include/uapi (1 of 3 files). Show all

Unified · Split

include/uapi/linux/rkisp1-config.h+106−1
@@ -967,6 +967,92 @@ struct rkisp1_cif_isp_wdr_config { · 966 unmodified lines
967 __u8 use_iref;967 __u8 use_iref;
968};968};
969 969
970/*
971 * enum rkisp1_cif_isp_cac_h_clip_mode - horizontal clipping mode
972 *
973 * @RKISP1_CIF_ISP_CAC_H_CLIP_MODE_4PX: +/- 4 pixels
974 * @RKISP1_CIF_ISP_CAC_H_CLIP_MODE_4_5PX: +/- 4/5 pixels depending on bayer position
975 */
976enum rkisp1_cif_isp_cac_h_clip_mode {
977 RKISP1_CIF_ISP_CAC_H_CLIP_MODE_4PX = 0,
978 RKISP1_CIF_ISP_CAC_H_CLIP_MODE_4_5PX = 1,
979};
980
981/**
982 * enum rkisp1_cif_isp_cac_v_clip_mode - vertical clipping mode
983 *
984 * @RKISP1_CIF_ISP_CAC_V_CLIP_MODE_2PX: +/- 2 pixels
985 * @RKISP1_CIF_ISP_CAC_V_CLIP_MODE_3PX: +/- 3 pixels
986 * @RKISP1_CIF_ISP_CAC_V_CLIP_MODE_3_4PX: +/- 3/4 pixels depending on bayer position
987 */
988enum rkisp1_cif_isp_cac_v_clip_mode {
989 RKISP1_CIF_ISP_CAC_V_CLIP_MODE_2PX = 0,
990 RKISP1_CIF_ISP_CAC_V_CLIP_MODE_3PX = 1,
991 RKISP1_CIF_ISP_CAC_V_CLIP_MODE_3_4PX = 2,
992};
993
994/**
995 * struct rkisp1_cif_isp_cac_config - chromatic aberration correction configuration
996 *
997 * The correction is carried out by shifting the red and blue pixels relative
998 * to the green ones, depending on the distance from the optical center:
999 *
1000 * @h_count_start: horizontal coordinate of the optical center (13-bit unsigned integer; [1,8191])
1001 * @v_count_start: vertical coordinate of the optical center (13-bit unsigned integer; [1,8191])
1002 *
1003 * For each pixel, the x/y distances from the optical center are calculated and
1004 * then transformed into the [0,255] range based on the following formula:
1005 *
1006 * (((d << 4) >> ns) * nf) >> 5
1007 *
1008 * where `d` is the distance, `ns` and `nf` are the normalization parameters:
1009 *
1010 * @x_nf: horizontal normalization scale parameter (5-bit unsigned integer; [0,31])
1011 * @x_ns: horizontal normalization shift parameter (4-bit unsigned integer; [0,15])
1012 *
1013 * @y_nf: vertical normalization scale parameter (5-bit unsigned integer; [0,31])
1014 * @y_ns: vertical normalization shift parameter (4-bit unsigned integer; [0,15])
1015 *
1016 * These parameters should be chosen based on the image resolution, the position
1017 * of the optical center, and the shape of pixels, so that no normalized distance
1018 * is larger than 255. If the pixels have square shape, the two sets of parameters
1019 * should be equal.
1020 *
1021 * The actual amount of correction is calculated with a third degree polynomial:
1022 *
1023 * c[0] * r + c[1] * r^2 + c[2] * r^3
1024 *
1025 * where `c` is the set of coefficients for the given color, and `r` is distance:
1026 *
1027 * @red: red coefficients (5.4 two's complement; [-16,15.9375])
1028 * @blue: blue coefficients (5.4 two's complement; [-16,15.9375])
1029 *
1030 * Finally, the amount is clipped as requested:
1031 *
1032 * @h_clip_mode: maximum horizontal shift (from enum rkisp1_cif_isp_cac_h_clip_mode)
1033 * @v_clip_mode: maximum vertical shift (from enum rkisp1_cif_isp_cac_v_clip_mode)
1034 *
1035 * A positive result will shift away from the optical center, while a negative
1036 * one will shift towards the optical center. In the latter case, the pixel
1037 * values at the edges are duplicated.
1038 */
1039struct rkisp1_cif_isp_cac_config {
1040 __u8 h_clip_mode;
1041 __u8 v_clip_mode;
1042
1043 __u16 h_count_start;
1044 __u16 v_count_start;
1045
1046 __u16 red[3];
1047 __u16 blue[3];
1048
1049 __u8 x_nf;
1050 __u8 x_ns;
1051
1052 __u8 y_nf;
1053 __u8 y_ns;
1054};
1055
970/*---------- PART2: Measurement Statistics ------------*/1056/*---------- PART2: Measurement Statistics ------------*/
971 1057
972/**1058/**
@@ -1138,6 +1224,7 @@ struct rkisp1_stat_buffer { · 165 unmodified lines
1138 * @RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND: Companding expand curve1224 * @RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND: Companding expand curve
1139 * @RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS: Companding compress curve1225 * @RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS: Companding compress curve
1140 * @RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR: Wide dynamic range1226 * @RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR: Wide dynamic range
1227 * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CAC: Chromatic aberration correction
1141 */1228 */
1142enum rkisp1_ext_params_block_type {1229enum rkisp1_ext_params_block_type {
1143 RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,1230 RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,
@@ -1161,6 +1248,7 @@ enum rkisp1_ext_params_block_type { · 17 unmodified lines
1161 RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND,1248 RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND,
1162 RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS,1249 RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS,
1163 RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR,1250 RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR,
1251 RKISP1_EXT_PARAMS_BLOCK_TYPE_CAC,
1164};1252};
1165 1253
1166/* For backward compatibility */1254/* For backward compatibility */
@@ -1507,6 +1595,22 @@ struct rkisp1_ext_params_wdr_config { · 340 unmodified lines
1507 struct rkisp1_cif_isp_wdr_config config;1595 struct rkisp1_cif_isp_wdr_config config;
1508} __attribute__((aligned(8)));1596} __attribute__((aligned(8)));
1509 1597
1598/**
1599 * struct rkisp1_ext_params_cac_config - RkISP1 extensible params CAC config
1600 *
1601 * RkISP1 extensible parameters CAC block.
1602 * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CAC`.
1603 *
1604 * @header: The RkISP1 extensible parameters header, see
1605 * :c:type:`rkisp1_ext_params_block_header`
1606 * @config: CAC configuration, see
1607 * :c:type:`rkisp1_cif_isp_cac_config`
1608 */
1609struct rkisp1_ext_params_cac_config {
1610 struct rkisp1_ext_params_block_header header;
1611 struct rkisp1_cif_isp_cac_config config;
1612} __attribute__((aligned(8)));
1613
1510/*1614/*
1511 * The rkisp1_ext_params_compand_curve_config structure is counted twice as it1615 * The rkisp1_ext_params_compand_curve_config structure is counted twice as it
1512 * is used for both the COMPAND_EXPAND and COMPAND_COMPRESS block types.1616 * is used for both the COMPAND_EXPAND and COMPAND_COMPRESS block types.
@@ -1532,7 +1636,8 @@ struct rkisp1_ext_params_wdr_config { · 19 unmodified lines
1532 sizeof(struct rkisp1_ext_params_compand_bls_config) +\1636 sizeof(struct rkisp1_ext_params_compand_bls_config) +\
1533 sizeof(struct rkisp1_ext_params_compand_curve_config) +\1637 sizeof(struct rkisp1_ext_params_compand_curve_config) +\
1534 sizeof(struct rkisp1_ext_params_compand_curve_config) +\1638 sizeof(struct rkisp1_ext_params_compand_curve_config) +\
1535 sizeof(struct rkisp1_ext_params_wdr_config))1639 sizeof(struct rkisp1_ext_params_wdr_config) +\
1640 sizeof(struct rkisp1_ext_params_cac_config))
1536 1641
1537/**1642/**
1538 * enum rkisp1_ext_param_buffer_version - RkISP1 extensible parameters version1643 * enum rkisp1_ext_param_buffer_version - RkISP1 extensible parameters version