1 /*
2 * Copyright (c) 2022 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 #include "RkIspFecGenMesh.h"
19
20 #include <stdio.h>
21
22 namespace RKISPFEC {
23
24 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 RkIspFecGenMesh::init(int32_t srcWidth, int32_t srcHeight,
26 int32_t dstWidth, int32_t dstHeight,
27 const double *lightCenter,
28 const double *coeff,
29 enum rk_ispfec_correct_direction direction,
30 enum rk_ispfec_correct_style style)
31 {
32 int32_t ret = -1;
33
34 if (mInited) {
35 printf("genFecMesh has been initialized!!\n");
36 return 0;
37 }
38
39 if (!lightCenter || !coeff) {
40 printf("E: lightCenter or coeff is null!\n");
41 return ret;
42 }
43
44 printf("I: src w: %d, h: %d, dst w: %d, h: %d\n", srcWidth, srcHeight, dstWidth, dstHeight);
45 printf("I: the light center of lens: %.16f, %.16f\n", lightCenter[0], lightCenter[1]);
46 printf("I: the coeff of lens: %.16f, %.16f, %.16f, %.16f\n", coeff[0], coeff[1], coeff[2], coeff[3]);
47
48 mParams.isFecOld = 1;
49
50 if (direction == RK_ISPFEC_CORRECT_DIRECTION_X) {
51 mParams.correctX = 1;
52 mParams.correctY = 0;
53 } else if (direction == RK_ISPFEC_CORRECT_DIRECTION_X) {
54 mParams.correctX = 0;
55 mParams.correctY = 1;
56 } else {
57 mParams.correctX = 1;
58 mParams.correctY = 1;
59 }
60
61 if (style == RK_ISPFEC_COMPRES_IMAGE_KEEP_FOV) {
62 mParams.saveMaxFovX = 1;
63 } else if (style == RK_ISPFEC_KEEP_ASPECT_RATIO_REDUCE_FOV) {
64 mParams.saveMaxFovX = 0;
65 }
66
67 mParams.saveMesh4bin = false;
68 if (mParams.saveMesh4bin) {
69 sprintf(mParams.mesh4binPath, "/tmp/");
70 }
71
72 mCoeff.cx = lightCenter[0];
73 mCoeff.cy = lightCenter[1];
74 mCoeff.a0 = coeff[0];
75 mCoeff.a2 = coeff[1];
76 mCoeff.a3 = coeff[2];
77 mCoeff.a4 = coeff[3];
78
79 genFecMeshInit(srcWidth, srcHeight, dstWidth, dstHeight, mParams, mCoeff);
80
81 printf("I: fec mode: %d, direction: %d, level: %d, mesh: w: %d, h: %d, total size: %d\n",
82 mStyle, mDirection, mLevel,
83 mParams.meshSizeW, mParams.meshSizeH, mParams.meshSize4bin);
84
85 mInited = true;
86
87 return 0;
88 }
89
deinit()90 int32_t RkIspFecGenMesh::deinit()
91 {
92 if (!mInited) {
93 printf("genFecMesh hasn't been initialized!\n");
94 return 0;
95 }
96
97 genFecMeshDeInit(mParams);
98
99 return 0;
100 }
101
genMesh(int32_t level)102 int32_t RkIspFecGenMesh::genMesh(int32_t level)
103 {
104 int32_t ret = -1;
105
106 if (!mInited) {
107 printf("E: genfecMesh hasn't been initialized!\n");
108 return 0;
109 }
110
111 if (!mMeshXi || !mMeshYi || !mMeshXf || !mMeshYf) {
112 printf("E: mesh buffer is null!\n");
113 return ret;
114 }
115
116 printf("I: the light center of lens: %.16f, %.16f\n", mCoeff.cx, mCoeff.cy);
117 printf("I: the coeff of lens: %.16f, %.16f, %.16f, %.16f\n",
118 mCoeff.a0, mCoeff.a2, mCoeff.a3, mCoeff.a4);
119
120 printf("I: the level of mesh to be generated: %d\n", level);
121
122 bool b_ret = genFECMeshNLevel(mParams, mCoeff, level,
123 (uint16_t*)mMeshXi, (uint8_t*)mMeshXf,
124 (uint16_t*)mMeshYi, (uint8_t*)mMeshYf);
125 if (!b_ret) {
126 printf("E: Failed to generate fec mesh!\n");
127 return ret;
128 }
129
130 return 0;
131 }
132
133 };
134