-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLaowa_4.0mm_f2.8.dctl
More file actions
122 lines (102 loc) · 4.47 KB
/
Copy pathLaowa_4.0mm_f2.8.dctl
File metadata and controls
122 lines (102 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
Fisheye correction for Laowa 4.0 mm F/2.8 in DCTL
*/
#include "defisheye.h"
DEFINE_UI_PARAMS(CIRCLE_ADJ, adjustment mode, DCTLUI_CHECK_BOX, 1)
DEFINE_UI_PARAMS(CIRCLE_CENTX, adjust:center x, DCTLUI_SLIDER_FLOAT, 0.0, -2.0, 2.0, 0.01)
DEFINE_UI_PARAMS(CIRCLE_CENTY, adjust:center y, DCTLUI_SLIDER_FLOAT, 0.0, -2.0, 2.0, 0.01)
DEFINE_UI_PARAMS(CIRCLE_RAD, adjust:radius, DCTLUI_SLIDER_FLOAT, 29.0, 25.0, 75.0, 0.01)
DEFINE_UI_PARAMS(PIX_ASPECT, adjust:aspect, DCTLUI_SLIDER_FLOAT, 1.0, 1.0, 2.0, 0.01)
DEFINE_UI_PARAMS(FOCAL_LENGTH, focal length log2,DCTLUI_SLIDER_FLOAT, 2.322, 2.0, 5.0, 0.1)
DEFINE_UI_PARAMS(INTERP, use bicubic, DCTLUI_CHECK_BOX, 1)
DEFINE_UI_PARAMS(EQUIRECT, equirectangular map, DCTLUI_CHECK_BOX, 0)
DEFINE_UI_PARAMS(HIDE_OUTSIDE, hide outside of circle, DCTLUI_CHECK_BOX, 0)
DEFINE_UI_PARAMS(ANGLE_PAN, pan, DCTLUI_SLIDER_FLOAT, 0.0, -180.0, 180.0, 0.1)
DEFINE_UI_PARAMS(ANGLE_TILT, tilt, DCTLUI_SLIDER_FLOAT, 0.0, -180.0, 180.0, 0.1)
DEFINE_UI_PARAMS(ANGLE_ROTATE, rotate, DCTLUI_SLIDER_FLOAT, 0.0, -180.0, 180.0, 0.1)
DEFINE_UI_PARAMS(DEFISH_RATE, defish rate, DCTLUI_SLIDER_FLOAT, 100.0, 0.0, 100.0, 1.0)
DEFINE_UI_PARAMS(ANGLE_PAN2, pan 2, DCTLUI_SLIDER_FLOAT, 0.0, -180.0, 180.0, 0.1)
DEFINE_UI_PARAMS(ANGLE_TILT2, tilt 2, DCTLUI_SLIDER_FLOAT, 0.0, -180.0, 180.0, 0.1)
DEFINE_UI_PARAMS(ANGLE_ROTATE2, rotate 2, DCTLUI_SLIDER_FLOAT, 0.0, -180.0, 180.0, 0.1)
DEFINE_UI_PARAMS(HIDE_OUTSIDE_DEGREE, hide outside in degree, DCTLUI_SLIDER_FLOAT, 210.0, 90.0, 360.0, 1.0)
#define SensorWidth (36.0)
#define maxTH (210.0 / 2);
__DEVICE__ float theta2radius(const float theta){
const float C1 = 0.95007;
const float C2 = 0.32225;
const float C3 = -0.26131;
const float K1 = 1.24016;
const float K2 = -0.24017;
const float TH = maxTH;
const float x = _saturatef(degree(theta) / TH);
if (degree(theta) > 90.0) {
return _fmaf(K2, x, K1) * x;
} else{
return _fmaf(_fmaf(C3, x, C2), x, C1) * x;
}
return 0;
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, __TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB)
{
float pX = p_X;
float pY = p_Y;
const float pWidth = p_Width;
const float pHeight = p_Height;
const float scale = _fmaxf(pWidth, pHeight);
const float half_w = _fdivide(pWidth, 2);
const float half_h = _fdivide(pHeight, 2);
const float sX = _fdivide(p_X - half_w, scale);
const float sY = _fdivide(p_Y - half_h, scale);
const float centX = _fdivide(CIRCLE_CENTX, 100);
const float centY = _fdivide(CIRCLE_CENTY, 100);
const float centR = _fdivide(CIRCLE_RAD, 100);
const float focalL = _exp2f(FOCAL_LENGTH);
if(CIRCLE_ADJ){
const float rad = _hypotf(_fdivide(sX - centX, PIX_ASPECT), sY - centY);
const float flag = _fminf(_fminf(_fabs(sX - centX), _fabs(sY - centY)), _fabs(rad - centR));
if(flag * scale <= 2.0) return make_float3(1.0, 0, 0);
}else{
float3 xyz;
if(EQUIRECT){
// (eq_theta, eq_phi) -> space (x,y,z)
float2 eq_thetaphi;
eq_thetaphi.x = (sY * 2 + 0.5) * PI;
eq_thetaphi.y = sX * 2 * PI;
xyz = equirect_angel2space(eq_thetaphi);
}else{
// film plane (sX,sY) -> space (x,y,z)
const float _sw = SensorWidth;
xyz.z = _fdivide(focalL, _sw);
xyz.x = - sX;
xyz.y = sY;
xyz = pan_tilt_rotate(xyz, make_float3(ANGLE_PAN2, ANGLE_TILT2, ANGLE_ROTATE2));
}
xyz = pan_tilt_rotate(xyz, make_float3(ANGLE_PAN, ANGLE_TILT, ANGLE_ROTATE));
// space (x,y,z) to angle (theta, phi)
float2 thetaphi = space2angle(xyz);
const float theta = thetaphi.x;
const float phi = thetaphi.y;
// angle (theta, phi) -> fisheye plane (pic_x, pic_y)
const float radius = theta2radius(theta) * centR;
const float pic_x = _fmaf(- _cosf(phi), radius * PIX_ASPECT, centX);
const float pic_y = _fmaf( _sinf(phi), radius, centY);
pX = _fmaf(pic_x, scale, half_w);
pY = _fmaf(pic_y, scale, half_h);
const float transf = _fdivide(100 - DEFISH_RATE, 100);
pX += (p_X - pX) * transf;
pY += (p_Y - pY) * transf;
if(HIDE_OUTSIDE){
const float th = _fdivide(HIDE_OUTSIDE_DEGREE, 2);
if(degree(theta) > th || pX < 0.0 || pX > pWidth || pY < 0.0 || pY > pHeight){
return make_float3(0.0, 0.0, 0.0);
}
}
}
float3 rgb;
if(INTERP & !CIRCLE_ADJ){
rgb = text2D_bicubicRGB(pX, pY, p_TexR, p_TexG, p_TexB);
}else{
rgb = text2D_RGB(pX, pY, p_TexR, p_TexG, p_TexB);
}
return rgb;
}