1 /* 2 * Copyright (c) 2019 Rockchip Corporation 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 18 #ifndef _RK_AIQ_COMM_H_ 19 #define _RK_AIQ_COMM_H_ 20 21 #include <stdbool.h> 22 #include <stdint.h> 23 24 #ifdef __cplusplus 25 #define RKAIQ_BEGIN_DECLARE extern "C" { 26 #define RKAIQ_END_DECLARE } 27 #else 28 #define RKAIQ_BEGIN_DECLARE 29 #define RKAIQ_END_DECLARE 30 #endif 31 32 RKAIQ_BEGIN_DECLARE 33 34 typedef int RESULT; 35 36 typedef enum RKAiqResult_e { 37 RK_AIQ_RET_SUCCESS = 0, // this has to be 0, if clauses rely on it 38 RK_AIQ_RET_FAILURE = 1, // process failure 39 RK_AIQ_RET_INVALID_PARM = 2, // invalid parameter 40 RK_AIQ_RET_WRONG_CONFIG = 3, // feature not supported 41 RK_AIQ_RET_BUSY = 4, // there's already something going on... 42 RK_AIQ_RET_CANCELED = 5, // operation canceled 43 RK_AIQ_RET_OUTOFMEM = 6, // out of memory 44 RK_AIQ_RET_OUTOFRANGE = 7, // parameter/value out of range 45 RK_AIQ_RET_NULL_POINTER = 8, // the/one/all parameter(s) is a(are) NULL pointer(s) 46 RK_AIQ_RET_DIVISION_BY_ZERO = 9, // a divisor equals ZERO 47 RK_AIQ_RET_NO_INPUTIMAGE = 10 // no input image 48 } RKAiqResult_t; 49 50 typedef enum RKAiqState_e { 51 RK_AIQ_STATE_INVALID = 0, /**< initialization value */ 52 RK_AIQ_STATE_INITIALIZED = 1, /**< instance is created, but not initialized */ 53 RK_AIQ_STATE_STOPPED = 2, /**< instance is confiured (ready to start) or stopped */ 54 RK_AIQ_STATE_RUNNING = 3, /**< instance is running (processes frames) */ 55 RK_AIQ_STATE_LOCKED = 4, /**< instance is locked (for taking snapshots) */ 56 RK_AIQ_STATE_MAX /**< max */ 57 } RKAiqState_t; 58 59 typedef enum RKAiqOPMode_e { 60 RK_AIQ_OP_MODE_INVALID = 0, /**< initialization value */ 61 RK_AIQ_OP_MODE_AUTO = 1, /**< instance is created, but not initialized */ 62 RK_AIQ_OP_MODE_MANUAL = 2, /**< instance is confiured (ready to start) or stopped */ 63 RK_AIQ_OP_MODE_MAX /**< max */ 64 } RKAiqOPMode_t; 65 66 #define ABS(a) (((a) > 0) ? (a) : (-(a))) 67 #ifndef MIN 68 #define MIN(a,b) ((a) > (b) ? (b) : (a)) 69 #endif 70 #ifndef MAX 71 #define MAX(a,b) ((a) < (b) ? (b) : (a)) 72 #endif 73 #define ROUND_D(x) (long)(((double)x)+(((x) > 0) ? 0.5 : (-0.5))) 74 #define ROUND_F(x) (int)(((float)x)+(((x) > 0) ? 0.5 : (-0.5))) 75 #define FLOOR(a) (int)( ((double)(a) < (int)(a)) ? (int)((a)-1) : (int)(a) ) 76 #define FLOOR_INT64(a) (long)( ((double)(a) < (long)(a)) ? (long)((a)-1) : (long)(a) ) 77 #define INTERP1(x0, x1, ratio) ((ratio) * ((x1) - (x0)) + x0) 78 #define CLIPBIT(a,b) ((a)>((1<<(b))-1)?((1<<(b))-1):(a)) 79 #define SWAP(_T_,A,B) { _T_ tmp = (A); (A) = (B); (B) = tmp; } 80 #define MIN2(a, b) ((a) > (b) ? (b) : (a)) 81 #define CLIP(a, min_v, max_v) (((a) < (min_v)) ? (min_v) : (((a) > (max_v)) ? (max_v) : (a))) 82 #define ROUND_INT(x, shf_bit) (int)((((x) > 0) ? 1 : -1) * ((ABS(x) + (1<<((shf_bit)-1)))>>(shf_bit))) 83 #define LOG2(x) (log((double)x) / log((double)2)) 84 85 86 #define RETURN_RESULT_IF_DIFFERENT( cur_res, exp_res ) if ( exp_res != cur_res ) { return ( cur_res ); } 87 #define DCT_ASSERT(exp) ((void)0) 88 89 #ifndef __FLT_EPSILON__ 90 #define __FLT_EPSILON__ 0.000000119209289550781250000000 91 #endif /* __FLT_EPSILON__ */ 92 93 #ifndef FLT_EPSILON 94 #define FLT_EPSILON __FLT_EPSILON__ 95 #endif /* FLT_EPSILON */ 96 97 98 #define DIVMIN 0.00001 99 100 typedef unsigned int uint32_t; 101 typedef int sint32_t; 102 typedef char sint8_t; 103 typedef unsigned long long uint64t; 104 105 106 /******************************************************************************/ 107 /** 108 * @brief A structure to represent a 5x5 matrix. 109 * 110 * The 25 values are laid out as follows (zero based index): 111 * 112 * | 00 01 02 03 04 | \n 113 * | 05 06 07 08 09 | \n 114 * | 10 11 12 13 14 | \n 115 * | 15 16 17 18 19 | \n 116 * | 20 21 22 23 24 | \n 117 * 118 * @note The 25 values are represented as unsigned char numbers. 119 * 120 *****************************************************************************/ 121 typedef struct Cam5x5UCharMatrix_s { 122 uint8_t uCoeff[5 * 5]; /**< array of 5x5 unsigned char values */ 123 } Cam5x5UCharMatrix_t; 124 125 typedef struct Cam15x15UCharMatrix_s { 126 uint8_t uCoeff[15 * 15]; /**< array of 15x15 unsigned char values */ 127 } Cam15x15UCharMatrix_t; 128 129 130 typedef struct Cam1x3IntMatrix_s 131 { 132 // M4_ARRAY_DESC("Coeff", "s32", M4_SIZE(1,3), M4_RANGE(-65535,65535), "0", M4_DIGIT(0), M4_DYNAMIC(0)) 133 int Coeff[3]; 134 } Cam1x3IntMatrix_t; 135 136 typedef struct Cam1x4IntMatrix_s 137 { 138 int Coeff[4]; 139 } Cam1x4IntMatrix_t; 140 141 typedef struct Cam1x6IntMatrix_s 142 { 143 int Coeff[6]; 144 } Cam1x6IntMatrix_t; 145 146 typedef struct Cam1x8IntMatrix_s 147 { 148 int Coeff[8]; 149 } Cam1x8IntMatrix_t; 150 151 typedef struct Cam1x9IntMatrix_s 152 { 153 int Coeff[9]; 154 } Cam1x9IntMatrix_t; 155 156 typedef struct Cam1x12IntMatrix_s 157 { 158 int Coeff[12]; 159 } Cam1x12IntMatrix_t; 160 typedef struct Cam1x17IntMatrix_s 161 { 162 int Coeff[17]; 163 } Cam1x17IntMatrix_t; 164 165 typedef struct Cam2x3IntMatrix_s 166 { 167 int Coeff[2 * 3]; 168 } Cam2x3IntMatrix_t; 169 170 typedef struct Cam3x3IntMatrix_s 171 { 172 int Coeff[3 * 3]; 173 } Cam3x3IntMatrix_t; 174 175 typedef struct Cam5x5IntMatrix_s 176 { 177 int Coeff[5 * 5]; 178 } Cam5x5IntMatrix_t; 179 180 /*****************************************************************************/ 181 /** 182 * @brief Matrix coefficients 183 * 184 * | 0 | 185 * 186 * @note Coefficients are represented as float numbers 187 */ 188 /*****************************************************************************/ 189 typedef struct Cam1x1FloatMatrix_s { 190 float fCoeff[1]; 191 } Cam1x1FloatMatrix_t; 192 193 /*****************************************************************************/ 194 /** 195 * @brief Matrix coefficients 196 * 197 * | 0 | 1 | 2 | 198 * 199 * @note Coefficients are represented as float numbers 200 */ 201 /*****************************************************************************/ 202 typedef struct Cam1x3FloatMatrix_s { 203 // M4_ARRAY_DESC("fCoeff", "f32", M4_SIZE(1,3), M4_RANGE(-65535,65535), "0", M4_DIGIT(6), M4_DYNAMIC(0)) 204 float fCoeff[3]; 205 } Cam1x3FloatMatrix_t; 206 207 /*****************************************************************************/ 208 /** 209 * @brief Matrix coefficients 210 * 211 * | 0 | 1 | ... | 4 | 212 * 213 * @note Coefficients are represented as float numbers 214 */ 215 /*****************************************************************************/ 216 typedef struct Cam1x4FloatMatrix_s { 217 // M4_ARRAY_DESC("fCoeff", "f32", M4_SIZE(1,4), M4_RANGE(-65535,65535), "0", M4_DIGIT(6), M4_DYNAMIC(0)) 218 float fCoeff[4]; 219 } Cam1x4FloatMatrix_t; 220 221 typedef struct Cam1x5FloatMatrix_s 222 { 223 float fCoeff[5]; 224 } Cam1x5FloatMatrix_t; 225 226 /*****************************************************************************/ 227 /** 228 * @brief Matrix coefficients 229 * 230 * | 0 | 1 | ... | 6 | 231 * 232 * @note Coefficients are represented as float numbers 233 */ 234 /*****************************************************************************/ 235 typedef struct Cam1x6FloatMatrix_s { 236 float fCoeff[6]; 237 } Cam1x6FloatMatrix_t; 238 239 typedef struct Cam1x8FloatMatrix_s 240 { 241 float fCoeff[8]; 242 } Cam1x8FloatMatrix_t; 243 244 typedef struct Cam1x9FloatMatrix_s 245 { 246 float fCoeff[9]; 247 } Cam1x9FloatMatrix_t; 248 249 /*****************************************************************************/ 250 /** 251 * @brief Matrix coefficients 252 * 253 * | 0 | 1 | ... | 15 | 254 * 255 * @note Coefficients are represented as float numbers 256 */ 257 /*****************************************************************************/ 258 typedef struct Cam1x16FloatMatrix_s { 259 float fCoeff[16]; 260 } Cam1x16FloatMatrix_t; 261 262 /*****************************************************************************/ 263 /** 264 * @brief Matrix coefficients 265 * 266 * | 0 | 1 | 267 * 268 * @note Coefficients are represented as float numbers 269 */ 270 /*****************************************************************************/ 271 typedef struct Cam2x1FloatMatrix { 272 // M4_ARRAY_DESC("fCoeff", "f32", M4_SIZE(1,2), M4_RANGE(-65535,65535), "0", M4_DIGIT(6), M4_DYNAMIC(0)) 273 float fCoeff[2]; 274 } Cam2x1FloatMatrix_t; 275 276 /*****************************************************************************/ 277 /** 278 * @brief Matrix coefficients 279 * 280 * | 0 | 1 | 281 * | 2 | 3 | 282 * 283 * @note Coefficients are represented as float numbers 284 */ 285 /*****************************************************************************/ 286 typedef struct Cam2x2FloatMatrix { 287 float fCoeff[4]; 288 } Cam2x2FloatMatrix_t; 289 290 /*****************************************************************************/ 291 /** 292 * @brief Matrix coefficients 293 * 294 * | 0 | 1 | 2 | 295 * 296 * @note Coefficients are represented as float numbers 297 */ 298 /*****************************************************************************/ 299 typedef struct Cam3x1FloatMatrix { 300 float fCoeff[3]; 301 } Cam3x1FloatMatrix_t; 302 303 /*****************************************************************************/ 304 /** 305 * @brief Matrix coefficients 306 * 307 * | 0 | 1 | 2 | 308 * | 3 | 4 | 5 | 309 * 310 * @note Coefficients are represented as float numbers 311 */ 312 /*****************************************************************************/ 313 typedef struct Cam3x2FloatMatrix_s { 314 float fCoeff[6]; 315 } Cam3x2FloatMatrix_t; 316 317 /*****************************************************************************/ 318 /** 319 * @brief Matrix coefficients 320 * 321 * | 0 | 1 | 2 | 322 * | 3 | 4 | 5 | 323 * | 6 | 7 | 8 | 324 * 325 * @note Coefficients are represented as float numbers 326 */ 327 /*****************************************************************************/ 328 typedef struct Cam3x3FloatMatrix_s { 329 float fCoeff[9]; 330 } Cam3x3FloatMatrix_t; 331 332 /******************************************************************************/ 333 /** 334 * @brief A structure to represent a 5x5 matrix. 335 * 336 * The 25 values are laid out as follows (zero based index): 337 * 338 * | 00 01 02 03 04 | \n 339 * | 05 06 07 08 09 | \n 340 * | 10 11 12 13 14 | \n 341 * | 15 16 17 18 19 | \n 342 * | 20 21 22 23 24 | \n 343 * 344 * @note The 25 values are represented as float numbers. 345 * 346 *****************************************************************************/ 347 typedef struct Cam5x5FloatMatrix_s { 348 float fCoeff[25U]; /**< array of 5x5 float values */ 349 } Cam5x5FloatMatrix_t; 350 351 352 /*****************************************************************************/ 353 /** 354 * @brief Matrix coefficients 355 * 356 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | .... 357 * | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | .... 358 * | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | .... 359 * ... 360 * ... 361 * ... 362 * | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | .... | 288 | 363 * 364 * @note Coefficients are represented as short numbers 365 */ 366 /*****************************************************************************/ 367 typedef struct Cam17x17FloatMatrix_s { 368 float fCoeff[17 * 17]; 369 } Cam17x17FloatMatrix_t; 370 371 /*****************************************************************************/ 372 /** 373 * @brief Matrix coefficients 374 * 375 * | 0 | 1 | 2 | 376 * 377 * @note Coefficients are represented as short numbers 378 */ 379 /*****************************************************************************/ 380 typedef struct Cam1x3ShortMatrix_s { 381 // M4_ARRAY_DESC("fCoeff", "s16", M4_SIZE(1,3), M4_RANGE(-65535,65535), "0", M4_DIGIT(0), M4_DYNAMIC(0)) 382 int16_t Coeff[3]; 383 } Cam1x3ShortMatrix_t; 384 385 /*****************************************************************************/ 386 /** 387 * @brief Matrix coefficients 388 * 389 * | 0 | 1 | 2 | ... | 4 | 390 * 391 * @note Coefficients are represented as short numbers 392 */ 393 /*****************************************************************************/ 394 typedef struct Cam1x4UShortMatrix_s { 395 uint16_t uCoeff[4]; 396 } Cam1x4UShortMatrix_t; 397 398 /*****************************************************************************/ 399 /** 400 * @brief Matrix coefficients 401 * 402 * | 0 | 1 | 2 | ... | 16 | 403 * 404 * @note Coefficients are represented as short numbers 405 */ 406 /*****************************************************************************/ 407 typedef struct Cam1x17UShortMatrix_s { 408 uint16_t uCoeff[17]; 409 } Cam1x17UShortMatrix_t; 410 411 /*****************************************************************************/ 412 /** 413 * @brief Matrix coefficients 414 * 415 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | .... 416 * | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | .... 417 * | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | .... 418 * ... 419 * ... 420 * ... 421 * | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | .... | 288 | 422 * 423 * @note Coefficients are represented as short numbers 424 */ 425 /*****************************************************************************/ 426 typedef struct Cam17x17UShortMatrix_s { 427 // M4_ARRAY_DESC("uCoeff", "u16", M4_SIZE(17,17), M4_RANGE(0,10000), "1024", M4_DIGIT(0), M4_DYNAMIC(0)) 428 uint16_t uCoeff[17 * 17]; 429 } Cam17x17UShortMatrix_t; 430 431 typedef enum { 432 RK_AIQ_WORKING_MODE_NORMAL, 433 RK_AIQ_WORKING_MODE_ISP_HDR2 = 0x10, 434 RK_AIQ_WORKING_MODE_ISP_HDR3 = 0x20, 435 // RK_AIQ_WORKING_MODE_SENSOR_HDR = 10, // sensor built-in hdr mode 436 } rk_aiq_working_mode_t; 437 438 typedef enum { 439 RK_AIQ_ISP_HDR_MODE_2_FRAME_HDR = RK_AIQ_WORKING_MODE_ISP_HDR2 + 1, 440 RK_AIQ_ISP_HDR_MODE_2_LINE_HDR = RK_AIQ_WORKING_MODE_ISP_HDR2 + 2, 441 RK_AIQ_ISP_HDR_MODE_3_FRAME_HDR = RK_AIQ_WORKING_MODE_ISP_HDR3 + 1, 442 RK_AIQ_ISP_HDR_MODE_3_LINE_HDR = RK_AIQ_WORKING_MODE_ISP_HDR3 + 2, 443 } rk_aiq_isp_hdr_mode_t; 444 445 typedef enum { 446 RKAIQ_SENSOR_HDR_MODE_DCG, // 2frame: share the same exptime, use dual conversion gain; 3frame: DCG+VS, VS frame use individual gain & time 447 RKAIQ_SENSOR_HDR_MODE_STAGGER, // 2frame or 3frame 448 } rk_aiq_sensor_hdr_line_mode_t; 449 450 #define RK_AIQ_HDR_GET_WORKING_MODE(mode) (mode & 0xF0) 451 452 typedef enum { 453 RKAIQ_ISPP_TNR_MODE_2TO1, 454 RKAIQ_ISPP_TNR_MODE_3TO1, 455 } rkaiq_ispp_tnr_mode_t; 456 457 typedef enum { 458 RKAIQ_ISPP_FEC_MODE_STABLE, 459 RKAIQ_ISPP_FEC_MODE_FISHEYE, 460 } rkaiq_ispp_fec_mode_t; 461 462 typedef enum { 463 RK_MODULE_INVAL = 0, 464 RK_MODULE_DPCC, 465 RK_MODULE_BLS, 466 RK_MODULE_LSC, 467 RK_MODULE_AWB_GAIN, 468 RK_MODULE_CTK, 469 RK_MODULE_GOC, 470 RK_MODULE_SHARP, 471 RK_MODULE_AE, 472 RK_MODULE_AWB, 473 RK_MODULE_NR,//10 474 RK_MODULE_GIC, 475 RK_MODULE_3DLUT, 476 RK_MODULE_LDCH, 477 RK_MODULE_TNR,//14 478 RK_MODULE_FEC, 479 RK_MODULE_RAWNR,//16 480 RK_MODULE_MAX 481 } rk_aiq_module_id_t; 482 483 typedef enum 484 { 485 RK_AIQ_BAYER_INVALID = -1, 486 RK_AIQ_BAYER_BGGR = 0, 487 RK_AIQ_BAYER_GBRG = 1, 488 RK_AIQ_BAYER_GRBG = 2, 489 RK_AIQ_BAYER_RGGB = 3, 490 } RkAiqBayerPattern_t; 491 492 typedef enum { 493 RK_AIQ_UAPI_MODE_DEFAULT = 0, 494 RK_AIQ_UAPI_MODE_SYNC, 495 RK_AIQ_UAPI_MODE_ASYNC 496 } rk_aiq_uapi_mode_sync_e; 497 498 /* 499 * @sync_mode (param in): flags for param update mode, 500 * @setAttrib: 501 * RK_AIQ_UAPI_MODE_DEFAULT: default is sync mode. 502 * RK_AIQ_UAPI_MODE_SYNC: sync mode. 503 * RK_AIQ_UAPI_MODE_ASYNC: async mode. 504 * @getAttrib: 505 * RK_AIQ_UAPI_MODE_DEFAULT: default to get the attrib that was 506 * set(sync_mode == RK_AIQ_UAPI_MODE_ASYNC) last time, which 507 * may not be in effect yet. 508 * RK_AIQ_UAPI_MODE_SYNC: get the attrib currently in use. 509 * RK_AIQ_UAPI_MODE_ASYNC: the same as RK_AIQ_UAPI_MODE_DEFAULT. 510 * 511 * @done (parsm out): flags for param update status, 512 * true indicate param has been updated, false 513 * indicate param has not been updated. 514 */ 515 typedef struct rk_aiq_uapi_sync_s { 516 rk_aiq_uapi_mode_sync_e sync_mode; 517 bool done; 518 } rk_aiq_uapi_sync_t; 519 520 extern int g_rkaiq_isp_hw_ver; 521 522 #define CHECK_ISP_HW_V20() \ 523 (g_rkaiq_isp_hw_ver == 20 ? true : false) 524 525 #define CHECK_ISP_HW_V21() \ 526 (g_rkaiq_isp_hw_ver == 21 ? true : false) 527 528 #define CHECK_ISP_HW_V30() \ 529 (g_rkaiq_isp_hw_ver == 30 ? true : false) 530 531 #define CHECK_ISP_HW_V32() \ 532 (g_rkaiq_isp_hw_ver == 32 ? true : false) 533 534 #define CHECK_ISP_HW_V32_LITE() \ 535 (g_rkaiq_isp_hw_ver == 321 ? true : false) 536 537 #define CHECK_ISP_HW_V3X() \ 538 (g_rkaiq_isp_hw_ver == 30 ? true : \ 539 g_rkaiq_isp_hw_ver == 31 ? true : false) 540 541 #ifndef AIQ_MAYBE_UNUSED 542 #ifdef __GNUC__ 543 #define AIQ_MAYBE_UNUSED __attribute__((unused)) 544 #else 545 #define AIQ_MAYBE_UNUSED 546 #endif 547 #endif // AIQ_MAYBE_UNUSED 548 549 #ifndef AIQ_UNUSED_PARAM 550 #ifdef __cplusplus 551 #define AIQ_UNUSED_PARAM(x) static_cast<void>(x) 552 #else 553 #define AIQ_UNUSED_PARAM(x) (void)(x) 554 #endif 555 #endif // AIQ_UNUSED_PARAM 556 557 RKAIQ_END_DECLARE 558 559 #endif 560