diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-08-08 22:04:40 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-08-08 22:04:40 +0400 |
commit | a401971cf88e3acadb04243929822da6fcf03174 (patch) | |
tree | d88097772419fb4976839a2037bd3167ba0c38f3 | |
parent | 543cee14ca9a6b89a1b26ccbfda1d58743db71af (diff) |
sync changes between opencl and C++ VariableSizeBokehBlurOperation, also remove absf() check on pixel radius, this is ensured to be unsigned.
3 files changed, 42 insertions, 40 deletions
diff --git a/source/blender/compositor/operations/COM_OpenCLKernels.cl b/source/blender/compositor/operations/COM_OpenCLKernels.cl index 4f43650370d..441f6af79a5 100644 --- a/source/blender/compositor/operations/COM_OpenCLKernels.cl +++ b/source/blender/compositor/operations/COM_OpenCLKernels.cl @@ -86,8 +86,9 @@ __kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2 const int2 realCoordinate = coords + offsetOutput; float4 readColor; + float4 tempColor; float4 bokeh; - float tempSize; + float size; float4 multiplier_accum = {1.0f, 1.0f, 1.0f, 1.0f}; float4 color_accum; @@ -98,10 +99,10 @@ __kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2 { int2 inputCoordinate = realCoordinate - offsetInput; - float size = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0; + float size_center = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0; color_accum = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate); - if (size > threshold) { + if (size_center > threshold) { for (int ny = miny; ny < maxy; ny += step) { inputCoordinate.s1 = ny - offsetInput.s1; float dy = ny - realCoordinate.s1; @@ -109,13 +110,14 @@ __kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2 float dx = nx - realCoordinate.s0; if (dx != 0 || dy != 0) { inputCoordinate.s0 = nx - offsetInput.s0; - tempSize = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0; - if (tempSize > threshold) { - if (tempSize >= fabs(dx) && tempSize >= fabs(dy)) { - float2 uv = { 256.0f + dx * 255.0f / tempSize, 256.0f + dy * 255.0f / tempSize}; + size = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0; + if (size > threshold) { + if (size >= fabs(dx) && size >= fabs(dy)) { + float2 uv = {256.0f + dx * 255.0f / size, + 256.0f + dy * 255.0f / size}; bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv); - readColor = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate); - color_accum += bokeh*readColor; + tempColor = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate); + color_accum += bokeh * tempColor; multiplier_accum += bokeh; } } @@ -150,7 +152,7 @@ __kernel void dilateKernel(__read_only image2d_t inputImage, __write_only image const float deltaY = (realCoordinate.y - ny); for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx ++, inputXy.x++) { const float deltaX = (realCoordinate.x - nx); - const float measuredDistance = deltaX*deltaX+deltaY*deltaY; + const float measuredDistance = deltaX * deltaX + deltaY * deltaY; if (measuredDistance <= distanceSquared) { value = max(value, read_imagef(inputImage, SAMPLER_NEAREST, inputXy).s0); } @@ -181,7 +183,7 @@ __kernel void erodeKernel(__read_only image2d_t inputImage, __write_only image2 for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx ++, inputXy.x++) { const float deltaX = (realCoordinate.x - nx); const float deltaY = (realCoordinate.y - ny); - const float measuredDistance = deltaX*deltaX+deltaY*deltaY; + const float measuredDistance = deltaX * deltaX+deltaY * deltaY; if (measuredDistance <= distanceSquared) { value = min(value, read_imagef(inputImage, SAMPLER_NEAREST, inputXy).s0); } diff --git a/source/blender/compositor/operations/COM_OpenCLKernels.cl.h b/source/blender/compositor/operations/COM_OpenCLKernels.cl.h index 7f60f97dfe8..e7de861710f 100644 --- a/source/blender/compositor/operations/COM_OpenCLKernels.cl.h +++ b/source/blender/compositor/operations/COM_OpenCLKernels.cl.h @@ -41,7 +41,7 @@ const char * clkernelstoh_COM_OpenCLKernels_cl = "/*\n" \ " float4 color = {0.0f,0.0f,0.0f,0.0f};\n" \ " float4 multiplyer = {0.0f,0.0f,0.0f,0.0f};\n" \ " float4 bokeh;\n" \ -" const float radius2 = radius * 2.0f;\n" \ +" const float radius2 = radius*2.0f;\n" \ " const int2 realCoordinate = coords + offsetOutput;\n" \ "\n" \ " tempBoundingBox = read_imagef(boundingBox, SAMPLER_NEAREST, coords).s0;\n" \ @@ -56,10 +56,10 @@ const char * clkernelstoh_COM_OpenCLKernels_cl = "/*\n" \ " float2 uv;\n" \ " int2 inputXy;\n" \ "\n" \ -" for (ny = minXY.y, inputXy.y = ny - offsetInput.y ; ny < maxXY.y ; ny += step, inputXy.y += step) {\n" \ +" for (ny = minXY.y, inputXy.y = ny - offsetInput.y ; ny < maxXY.y ; ny +=step, inputXy.y+=step) {\n" \ " uv.y = ((realCoordinate.y-ny)/radius2)*bokehImageDim.y+bokehImageCenter.y;\n" \ "\n" \ -" for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx += step, inputXy.x += step) {\n" \ +" for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx +=step, inputXy.x+=step) {\n" \ " uv.x = ((realCoordinate.x-nx)/radius2)*bokehImageDim.x+bokehImageCenter.x;\n" \ " bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv);\n" \ " color += bokeh * read_imagef(inputImage, SAMPLER_NEAREST, inputXy);\n" \ @@ -88,8 +88,9 @@ const char * clkernelstoh_COM_OpenCLKernels_cl = "/*\n" \ " const int2 realCoordinate = coords + offsetOutput;\n" \ "\n" \ " float4 readColor;\n" \ +" float4 tempColor;\n" \ " float4 bokeh;\n" \ -" float tempSize;\n" \ +" float size;\n" \ " float4 multiplier_accum = {1.0f, 1.0f, 1.0f, 1.0f};\n" \ " float4 color_accum;\n" \ "\n" \ @@ -100,10 +101,10 @@ const char * clkernelstoh_COM_OpenCLKernels_cl = "/*\n" \ "\n" \ " {\n" \ " int2 inputCoordinate = realCoordinate - offsetInput;\n" \ -" float size = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0;\n" \ +" float size_center = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0;\n" \ " color_accum = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate);\n" \ "\n" \ -" if (size > threshold) {\n" \ +" if (size_center > threshold) {\n" \ " for (int ny = miny; ny < maxy; ny += step) {\n" \ " inputCoordinate.s1 = ny - offsetInput.s1;\n" \ " float dy = ny - realCoordinate.s1;\n" \ @@ -111,13 +112,14 @@ const char * clkernelstoh_COM_OpenCLKernels_cl = "/*\n" \ " float dx = nx - realCoordinate.s0;\n" \ " if (dx != 0 || dy != 0) {\n" \ " inputCoordinate.s0 = nx - offsetInput.s0;\n" \ -" tempSize = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0;\n" \ -" if (tempSize > threshold) {\n" \ -" if (tempSize >= fabs(dx) && tempSize >= fabs(dy)) {\n" \ -" float2 uv = { 256.0f + dx * 256.0f / tempSize, 256.0f + dy * 256.0f / tempSize};\n" \ +" size = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0;\n" \ +" if (size > threshold) {\n" \ +" if (size >= fabs(dx) && size >= fabs(dy)) {\n" \ +" float2 uv = {256.0f + dx * 255.0f / size,\n" \ +" 256.0f + dy * 255.0f / size};\n" \ " bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv);\n" \ -" readColor = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate);\n" \ -" color_accum += bokeh * readColor;\n" \ +" tempColor = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate);\n" \ +" color_accum += bokeh * tempColor;\n" \ " multiplier_accum += bokeh;\n" \ " }\n" \ " }\n" \ @@ -183,7 +185,7 @@ const char * clkernelstoh_COM_OpenCLKernels_cl = "/*\n" \ " for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx ++, inputXy.x++) {\n" \ " const float deltaX = (realCoordinate.x - nx);\n" \ " const float deltaY = (realCoordinate.y - ny);\n" \ -" const float measuredDistance = deltaX * deltaX + deltaY * deltaY;\n" \ +" const float measuredDistance = deltaX * deltaX+deltaY * deltaY;\n" \ " if (measuredDistance <= distanceSquared) {\n" \ " value = min(value, read_imagef(inputImage, SAMPLER_NEAREST, inputXy).s0);\n" \ " }\n" \ diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp index 5508eb4c8bd..0507cbed165 100644 --- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp @@ -113,10 +113,10 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, vo int maxx = search[2]; int maxy = search[3]; #else - int minx = MAX2(x - maxBlur, 0.0f); - int miny = MAX2(y - maxBlur, 0.0f); - int maxx = MIN2(x + maxBlur, m_width); - int maxy = MIN2(y + maxBlur, m_height); + int minx = max(x - maxBlur, 0); + int miny = max(y - maxBlur, 0); + int maxx = min(x + maxBlur, (int)m_width); + int maxy = min(y + maxBlur, (int)m_height); #endif { inputSizeBuffer->readNoCheck(tempSize, x, y); @@ -124,26 +124,24 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, vo add_v4_v4(color_accum, readColor); add_v4_fl(multiplier_accum, 1.0f); - float sizeCenter = tempSize[0]; + float size_center = tempSize[0]; const int addXStep = QualityStepHelper::getStep() * COM_NUMBER_OF_CHANNELS; - if (sizeCenter > this->m_threshold) { + if (size_center > this->m_threshold) { for (int ny = miny; ny < maxy; ny += QualityStepHelper::getStep()) { float dy = ny - y; int offsetNy = ny * inputSizeBuffer->getWidth() * COM_NUMBER_OF_CHANNELS; int offsetNxNy = offsetNy + (minx * COM_NUMBER_OF_CHANNELS); for (int nx = minx; nx < maxx; nx += QualityStepHelper::getStep()) { - if (nx != x || ny != y) - { + if (nx != x || ny != y) { float size = inputSizeFloatBuffer[offsetNxNy]; if (size > this->m_threshold) { - float fsize = fabsf(size); float dx = nx - x; - if (fsize > fabsf(dx) && fsize > fabsf(dy)) { - float u = (256.0f + (dx/size) * 255.0f); - float v = (256.0f + (dy/size) * 255.0f); - inputBokehBuffer->readNoCheck(bokeh, u, v); + if (size > fabsf(dx) && size > fabsf(dy)) { + float uv[2] = {256.0f + (dx / size) * 255.0f, + 256.0f + (dy / size) * 255.0f}; + inputBokehBuffer->readNoCheck(bokeh, uv[0], uv[1]); madd_v4_v4v4(color_accum, bokeh, &inputProgramFloatBuffer[offsetNxNy]); add_v4_v4(multiplier_accum, bokeh); } @@ -160,11 +158,11 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, vo color[3] = color_accum[3] / multiplier_accum[3]; /* blend in out values over the threshold, otherwise we get sharp, ugly transitions */ - if ((sizeCenter > this->m_threshold) && - (sizeCenter < this->m_threshold * 2.0f)) + if ((size_center > this->m_threshold) && + (size_center < this->m_threshold * 2.0f)) { /* factor from 0-1 */ - float fac = (sizeCenter - this->m_threshold) / this->m_threshold; + float fac = (size_center - this->m_threshold) / this->m_threshold; interp_v4_v4v4(color, readColor, color, fac); } } |