xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/IspFec/src/RkIspFecGenMesh.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *  Copyright (c) 2022 Rockchip Corporation
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Licensed under the Apache License, Version 2.0 (the "License");
5*4882a593Smuzhiyun  * you may not use this file except in compliance with the License.
6*4882a593Smuzhiyun  * You may obtain a copy of the License at
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *      http://www.apache.org/licenses/LICENSE-2.0
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * Unless required by applicable law or agreed to in writing, software
11*4882a593Smuzhiyun  * distributed under the License is distributed on an "AS IS" BASIS,
12*4882a593Smuzhiyun  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4882a593Smuzhiyun  * See the License for the specific language governing permissions and
14*4882a593Smuzhiyun  * limitations under the License.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  */
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #include "RkIspFecGenMesh.h"
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include <stdio.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun namespace RKISPFEC {
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun int32_t
init(int32_t srcWidth,int32_t srcHeight,int32_t dstWidth,int32_t dstHeight,const double * lightCenter,const double * coeff,enum rk_ispfec_correct_direction direction,enum rk_ispfec_correct_style style)25*4882a593Smuzhiyun RkIspFecGenMesh::init(int32_t srcWidth, int32_t srcHeight,
26*4882a593Smuzhiyun                          int32_t dstWidth, int32_t dstHeight,
27*4882a593Smuzhiyun                          const double *lightCenter,
28*4882a593Smuzhiyun                          const double *coeff,
29*4882a593Smuzhiyun                          enum rk_ispfec_correct_direction direction,
30*4882a593Smuzhiyun                          enum rk_ispfec_correct_style style)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun     int32_t ret = -1;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun     if (mInited) {
35*4882a593Smuzhiyun         printf("genFecMesh has been initialized!!\n");
36*4882a593Smuzhiyun         return 0;
37*4882a593Smuzhiyun     }
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun     if (!lightCenter || !coeff) {
40*4882a593Smuzhiyun         printf("E: lightCenter or coeff is null!\n");
41*4882a593Smuzhiyun         return ret;
42*4882a593Smuzhiyun     }
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun     printf("I: src w: %d, h: %d, dst w: %d, h: %d\n", srcWidth, srcHeight, dstWidth, dstHeight);
45*4882a593Smuzhiyun     printf("I: the light center of lens: %.16f, %.16f\n", lightCenter[0], lightCenter[1]);
46*4882a593Smuzhiyun     printf("I: the coeff of lens: %.16f, %.16f, %.16f, %.16f\n", coeff[0], coeff[1], coeff[2], coeff[3]);
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun     mParams.isFecOld = 1;
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun     if (direction == RK_ISPFEC_CORRECT_DIRECTION_X) {
51*4882a593Smuzhiyun         mParams.correctX = 1;
52*4882a593Smuzhiyun         mParams.correctY = 0;
53*4882a593Smuzhiyun     } else if (direction == RK_ISPFEC_CORRECT_DIRECTION_X) {
54*4882a593Smuzhiyun         mParams.correctX = 0;
55*4882a593Smuzhiyun         mParams.correctY = 1;
56*4882a593Smuzhiyun     } else {
57*4882a593Smuzhiyun         mParams.correctX = 1;
58*4882a593Smuzhiyun         mParams.correctY = 1;
59*4882a593Smuzhiyun     }
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun     if (style == RK_ISPFEC_COMPRES_IMAGE_KEEP_FOV) {
62*4882a593Smuzhiyun         mParams.saveMaxFovX = 1;
63*4882a593Smuzhiyun     } else if (style == RK_ISPFEC_KEEP_ASPECT_RATIO_REDUCE_FOV) {
64*4882a593Smuzhiyun         mParams.saveMaxFovX = 0;
65*4882a593Smuzhiyun     }
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun     mParams.saveMesh4bin = false;
68*4882a593Smuzhiyun     if (mParams.saveMesh4bin) {
69*4882a593Smuzhiyun         sprintf(mParams.mesh4binPath, "/tmp/");
70*4882a593Smuzhiyun     }
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun     mCoeff.cx = lightCenter[0];
73*4882a593Smuzhiyun     mCoeff.cy = lightCenter[1];
74*4882a593Smuzhiyun     mCoeff.a0 = coeff[0];
75*4882a593Smuzhiyun     mCoeff.a2 = coeff[1];
76*4882a593Smuzhiyun     mCoeff.a3 = coeff[2];
77*4882a593Smuzhiyun     mCoeff.a4 = coeff[3];
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun     genFecMeshInit(srcWidth, srcHeight, dstWidth, dstHeight, mParams, mCoeff);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun     printf("I: fec mode: %d, direction: %d, level: %d, mesh: w: %d, h: %d, total size: %d\n",
82*4882a593Smuzhiyun            mStyle, mDirection, mLevel,
83*4882a593Smuzhiyun            mParams.meshSizeW, mParams.meshSizeH, mParams.meshSize4bin);
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun     mInited = true;
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun     return 0;
88*4882a593Smuzhiyun }
89*4882a593Smuzhiyun 
deinit()90*4882a593Smuzhiyun int32_t RkIspFecGenMesh::deinit()
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun     if (!mInited) {
93*4882a593Smuzhiyun         printf("genFecMesh hasn't been initialized!\n");
94*4882a593Smuzhiyun         return 0;
95*4882a593Smuzhiyun     }
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun     genFecMeshDeInit(mParams);
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun     return 0;
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun 
genMesh(int32_t level)102*4882a593Smuzhiyun int32_t RkIspFecGenMesh::genMesh(int32_t level)
103*4882a593Smuzhiyun {
104*4882a593Smuzhiyun     int32_t ret = -1;
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun     if (!mInited) {
107*4882a593Smuzhiyun         printf("E: genfecMesh hasn't been initialized!\n");
108*4882a593Smuzhiyun         return 0;
109*4882a593Smuzhiyun     }
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun     if (!mMeshXi || !mMeshYi || !mMeshXf || !mMeshYf) {
112*4882a593Smuzhiyun         printf("E: mesh buffer is null!\n");
113*4882a593Smuzhiyun         return ret;
114*4882a593Smuzhiyun     }
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun     printf("I: the light center of lens: %.16f, %.16f\n", mCoeff.cx, mCoeff.cy);
117*4882a593Smuzhiyun     printf("I: the coeff of lens: %.16f, %.16f, %.16f, %.16f\n",
118*4882a593Smuzhiyun            mCoeff.a0, mCoeff.a2, mCoeff.a3, mCoeff.a4);
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun     printf("I: the level of mesh to be generated: %d\n", level);
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun     bool b_ret = genFECMeshNLevel(mParams, mCoeff, level,
123*4882a593Smuzhiyun             (uint16_t*)mMeshXi, (uint8_t*)mMeshXf,
124*4882a593Smuzhiyun             (uint16_t*)mMeshYi, (uint8_t*)mMeshYf);
125*4882a593Smuzhiyun     if (!b_ret) {
126*4882a593Smuzhiyun         printf("E: Failed to generate fec mesh!\n");
127*4882a593Smuzhiyun         return ret;
128*4882a593Smuzhiyun     }
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun     return 0;
131*4882a593Smuzhiyun }
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun };
134