1 /* 2 * rk_aiq_algo_alsc_itf.h 3 * 4 * Copyright (c) 2019 Rockchip Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 */ 19 20 #ifndef _RK_AIQ_ALSC_CONVERT_OTP_H_ 21 #define _RK_AIQ_ALSC_CONVERT_OTP_H_ 22 23 #include "stdint.h" 24 #include "alsc/rk_aiq_types_alsc_algo_int.h" 25 #include "alsc/rk_aiq_types_alsc_algo_prvt.h" 26 27 #define c_lsc_ram_ad_bw 9 // bit width for the RAM address 28 #define c_lsc_ram_d_bw 26 // double correction factor, must be even numbers 29 30 #define c_lsc_size_bw 10 // bit width for xsize and ysize values 31 #define c_lsc_grad_bw 12 // bit width of the factor for x and y gradients calculation 32 #define c_lsc_size_bw_2x (2*c_lsc_size_bw) 33 #define c_lsc_grad_bw_2x (2*c_lsc_grad_bw) 34 35 #define c_lsc_sample_bw (c_lsc_ram_d_bw/2) // bit width of the correction factor values stored in RAM 36 #define c_lsc_sample_bw_2x c_lsc_ram_d_bw 37 38 #define c_lsc_corr_bw 15 // bit width of the correction factor values used internal. 39 #define c_lsc_corr_frac_bw 12 // bit width of the fractional part of correction factor values used internal 40 41 #define c_lsc_grad_exp 15 // fixed exponent for the x and y gradients 42 #define c_lsc_corr_extend 10 // extended fractal part of dx,dy of internal correction factor 43 // constraint : c_lsc_corr_extend <= c_lsc_grad_exp 44 #define c_extend_round (1 << (c_lsc_corr_extend - 1)) 45 #define c_frac_round (1 << (c_lsc_corr_frac_bw-1)) 46 47 // bit width difference of correction factor values between used internal and stored in RAM 48 #define c_corr_diff (c_lsc_corr_bw - c_lsc_sample_bw) 49 50 #define c_dx_shift (c_lsc_grad_exp - c_lsc_corr_extend) 51 #define c_dx_round (1 << (c_dx_shift - 1)) 52 #define c_dy_shift (c_lsc_grad_exp - c_lsc_corr_extend - c_corr_diff) 53 #define c_dy_round (1 << (c_dy_shift - 1)) 54 55 #define c_dx_bw (c_lsc_corr_bw + c_lsc_grad_bw - c_dx_shift) 56 #define c_dy_bw (c_lsc_sample_bw + c_lsc_grad_bw - c_dy_shift) 57 58 #define LSCDATA_LEN 289 59 60 typedef enum 61 { 62 BAYER_BGGR = 0, 63 BAYER_GBRG = 1, 64 BAYER_GRBG = 2, 65 BAYER_RGGB = 3, 66 } BayerPattern; 67 68 typedef enum 69 { 70 R_INDEX = 0, 71 GR_INDEX = 1, 72 GB_INDEX = 2, 73 B_INDEX = 3, 74 } BayerIndex; 75 76 void convertLscTableParameter(resolution_t *cur_res, alsc_otp_grad_t *otpGrad, RkAiqBayerPattern_t bayerPattern); 77 void computeSamplingPoint(int size, int *pos); 78 void computeSamplingInterval(int width, int height, int *xInterval, int *yInterval); 79 void getLscParameter(uint16_t *r, uint16_t *gr, uint16_t *gb, uint16_t *b, uint16_t *table, int width, int height, int bayer); 80 void calculateCorrectFactor(uint16_t *table, uint16_t *correctTable, int width, int height, int *xInterval, int *yInterval); 81 void computeGradient(int *xInterval, int *yInterval, int *xGradient, int *yGradient); 82 int getBayerIndex(int pattern, int row, int col); 83 void separateBayerChannel(uint16_t* src, uint16_t* disR, uint16_t* disGr, uint16_t* disGb, uint16_t* disB, int width, int height, int bayer); 84 void writeFile(char *fileName, uint16_t *buf); 85 void adjustVignettingForLscOTP(uint16_t *tableB, uint16_t *tableGb, uint16_t *tableGr, uint16_t *tableR, float newVig, int width, int height); 86 #endif 87