36 this->m_inputProgram =
nullptr;
37 this->m_distortion = 0.0f;
38 this->m_dispersion = 0.0f;
39 this->m_distortion_const =
false;
40 this->m_dispersion_const =
false;
41 this->m_variables_ready =
false;
46 m_distortion = distortion;
47 m_distortion_const =
true;
52 m_dispersion = dispersion;
53 m_dispersion_const =
true;
69 if (m_distortion_const && m_dispersion_const) {
70 updateVariables(m_distortion, m_dispersion);
71 m_variables_ready =
true;
83 if (!m_variables_ready) {
86 if (!m_distortion_const) {
91 if (!m_dispersion_const) {
97 updateVariables(m_distortion, m_dispersion);
98 m_variables_ready =
true;
106 void ScreenLensDistortionOperation::get_uv(
const float xy[2],
float uv[2])
const
108 uv[0] = m_sc * ((xy[0] + 0.5f) - m_cx) / m_cx;
109 uv[1] = m_sc * ((xy[1] + 0.5f) - m_cy) / m_cy;
112 void ScreenLensDistortionOperation::distort_uv(
const float uv[2],
float t,
float xy[2])
const
114 float d = 1.0f / (1.0f +
sqrtf(
t));
115 xy[0] = (uv[0] * d + 0.5f) *
getWidth() - 0.5f;
116 xy[1] = (uv[1] * d + 0.5f) *
getHeight() - 0.5f;
119 bool ScreenLensDistortionOperation::get_delta(
float r_sq,
122 float delta[2])
const
124 float t = 1.0f - k4 * r_sq;
126 distort_uv(uv,
t, delta);
133 void ScreenLensDistortionOperation::accumulate(MemoryBuffer *
buffer,
138 const float delta[3][2],
144 float dsf =
len_v2v2(delta[
a], delta[b]) + 1.0f;
145 int ds = m_jitter ? (dsf < 4.0f ? 2 : (int)
sqrtf(dsf)) : (
int)dsf;
146 float sd = 1.0f / (
float)ds;
149 float dk4 = m_dk4[
a];
151 for (
float z = 0;
z < ds;
z++) {
153 float t = 1.0f - (k4 + tz * dk4) * r_sq;
156 distort_uv(uv,
t, xy);
157 buffer->readBilinear(color, xy[0], xy[1]);
159 sum[
a] += (1.0f - tz) * color[
a];
160 sum[b] += (tz)*color[b];
169 float xy[2] = {(
float)
x, (
float)
y};
174 int count[3] = {0, 0, 0};
176 float sum[4] = {0, 0, 0, 0};
178 bool valid_r = get_delta(uv_dot, m_k4[0], uv, delta[0]);
179 bool valid_g = get_delta(uv_dot, m_k4[1], uv, delta[1]);
180 bool valid_b = get_delta(uv_dot, m_k4[2], uv, delta[2]);
182 if (valid_r && valid_g && valid_b) {
207 this->m_inputProgram =
nullptr;
211 void ScreenLensDistortionOperation::determineUV(
float result[6],
float x,
float y)
const
213 const float xy[2] = {
x,
y};
221 get_delta(uv_dot, m_k4[0], uv,
result + 0);
222 get_delta(uv_dot, m_k4[1], uv,
result + 2);
223 get_delta(uv_dot, m_k4[2], uv,
result + 4);
230 newInputValue.
xmin = 0;
231 newInputValue.
ymin = 0;
232 newInputValue.
xmax = 2;
233 newInputValue.
ymax = 2;
265 const float margin = 2;
269 if (m_dispersion_const && m_distortion_const) {
271 # define UPDATE_INPUT(x, y) \
274 determineUV(coords, x, y); \
275 newInput.xmin = min_ffff(newInput.xmin, coords[0], coords[2], coords[4]); \
276 newInput.ymin = min_ffff(newInput.ymin, coords[1], coords[3], coords[5]); \
277 newInput.xmax = max_ffff(newInput.xmax, coords[0], coords[2], coords[4]); \
278 newInput.ymax = max_ffff(newInput.ymax, coords[1], coords[3], coords[5]); \
282 UPDATE_INPUT(input->xmin, input->xmax);
283 UPDATE_INPUT(input->xmin, input->ymax);
284 UPDATE_INPUT(input->xmax, input->ymax);
285 UPDATE_INPUT(input->xmax, input->ymin);
291 float dispersion = m_dispersion_const ? m_dispersion : 1.0f;
293 # define UPDATE_INPUT(x, y, distortion) \
296 updateVariables(distortion, dispersion); \
297 determineUV(coords, x, y); \
298 newInput.xmin = min_ffff(newInput.xmin, coords[0], coords[2], coords[4]); \
299 newInput.ymin = min_ffff(newInput.ymin, coords[1], coords[3], coords[5]); \
300 newInput.xmax = max_ffff(newInput.xmax, coords[0], coords[2], coords[4]); \
301 newInput.ymax = max_ffff(newInput.ymax, coords[1], coords[3], coords[5]); \
305 if (m_distortion_const) {
307 UPDATE_INPUT(input->xmin, input->xmax, m_distortion);
308 UPDATE_INPUT(input->xmin, input->ymax, m_distortion);
309 UPDATE_INPUT(input->xmax, input->ymax, m_distortion);
310 UPDATE_INPUT(input->xmax, input->ymin, m_distortion);
314 UPDATE_INPUT(input->xmin, input->xmax, -1.0f);
315 UPDATE_INPUT(input->xmin, input->ymax, -1.0f);
316 UPDATE_INPUT(input->xmax, input->ymax, -1.0f);
317 UPDATE_INPUT(input->xmax, input->ymin, -1.0f);
319 UPDATE_INPUT(input->xmin, input->xmax, 1.0f);
320 UPDATE_INPUT(input->xmin, input->ymax, 1.0f);
321 UPDATE_INPUT(input->xmax, input->ymax, 1.0f);
322 UPDATE_INPUT(input->xmax, input->ymin, 1.0f);
328 newInput.
xmin -= margin;
329 newInput.
ymin -= margin;
330 newInput.
xmax += margin;
331 newInput.
ymax += margin;
341 void ScreenLensDistortionOperation::updateVariables(
float distortion,
float dispersion)
345 float d = 0.25f *
max_ff(
min_ff(dispersion, 1.0f), 0.0f);
348 m_maxk =
max_fff(m_k[0], m_k[1], m_k[2]);
349 m_sc = (m_fit && (m_maxk > 0.0f)) ? (1.0f / (1.0f + 2.0f * m_maxk)) : (1.0f / (1.0f + m_maxk));
350 m_dk4[0] = 4.0f * (m_k[1] - m_k[0]);
351 m_dk4[1] = 4.0f * (m_k[2] - m_k[1]);
typedef float(TangentPoint)[2]
MINLINE float max_fff(float a, float b, float c)
MINLINE float max_ff(float a, float b)
MINLINE float min_ff(float a, float b)
MINLINE float len_squared_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void zero_v4(float r[4])
MINLINE float len_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
struct RNG * BLI_rng_new(unsigned int seed)
float BLI_rng_get_float(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_rcti_init_minmax(struct rcti *rect)
#define POINTER_AS_INT(i)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Platform independent time functions.
static T sum(const btAlignedObjectArray< T > &items)
a MemoryBuffer contains access to the data of a chunk
NodeOperation contains calculation logic.
virtual void * initializeTileData(rcti *)
void readSampled(float result[4], float x, float y, PixelSampler sampler)
unsigned int getHeight() const
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
NodeOperation * getInputOperation(unsigned int inputSocketindex)
void addOutputSocket(DataType datatype)
unsigned int getWidth() const
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
virtual bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
void deinitExecution() override
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) override
void setDispersion(float dispersion)
void setDistortion(float distortion)
void * initializeTileData(rcti *rect) override
ScreenLensDistortionOperation()
void initExecution() override
void executePixel(float output[4], int x, int y, void *data) override
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
long int PIL_check_seconds_timer_i(void)