[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49367] branches/soc-2011-tomato/source/ blender/compositor/operations/COM_InpaintOperation.cpp: inpaint - gain some speed by not doing X/Y clamping in inner loops.
Campbell Barton
ideasman42 at gmail.com
Sun Jul 29 21:36:10 CEST 2012
Revision: 49367
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49367
Author: campbellbarton
Date: 2012-07-29 19:36:09 +0000 (Sun, 29 Jul 2012)
Log Message:
-----------
inpaint - gain some speed by not doing X/Y clamping in inner loops.
add assert() so we can ensure its not happening still.
Modified Paths:
--------------
branches/soc-2011-tomato/source/blender/compositor/operations/COM_InpaintOperation.cpp
Modified: branches/soc-2011-tomato/source/blender/compositor/operations/COM_InpaintOperation.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_InpaintOperation.cpp 2012-07-29 19:20:45 UTC (rev 49366)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_InpaintOperation.cpp 2012-07-29 19:36:09 UTC (rev 49367)
@@ -24,6 +24,12 @@
#include "BLI_math.h"
#include "COM_OpenCLDevice.h"
+
+#define ASSERT_XY_RANGE(x, y) \
+ BLI_assert(x >= 0 && x < this->getWidth() && \
+ y >= 0 && y < this->getHeight())
+
+
// Inpaint (simple convolve using average of known pixels)
InpaintSimpleOperation::InpaintSimpleOperation() : NodeOperation()
{
@@ -57,13 +63,14 @@
if (x < 0) {
x = 0;
}
- if (x >= width) {
+ else if (x >= width) {
x = width - 1;
}
+
if (y < 0) {
y = 0;
}
- if (y >= height) {
+ else if (y >= height) {
y = height - 1;
}
}
@@ -72,7 +79,8 @@
{
int width = this->getWidth();
- clamp_xy(x, y);
+ ASSERT_XY_RANGE(x, y);
+
return this->m_cached_buffer[
y * width * COM_NUMBER_OF_CHANNELS
+ x * COM_NUMBER_OF_CHANNELS + component];
@@ -82,6 +90,8 @@
{
int width = this->getWidth();
+ ASSERT_XY_RANGE(x, y);
+
this->m_cached_buffer[
y * width * COM_NUMBER_OF_CHANNELS
+ x * COM_NUMBER_OF_CHANNELS + component] = v;
@@ -90,7 +100,9 @@
int InpaintSimpleOperation::mdist(int x, int y)
{
int width = this->getWidth();
- clamp_xy(x, y);
+
+ ASSERT_XY_RANGE(x, y);
+
return this->m_manhatten_distance[y * width + x];
}
@@ -126,6 +138,7 @@
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
int r = 0;
+ /* no need to clamp here */
if (get(i, j, 3) < 1.0f) {
r = width + height;
if (i > 0)
@@ -174,26 +187,34 @@
float n = 0;
- float pix[3];
+ float pix[3] = {0.0f, 0.0f, 0.0f};
- memset(pix, 0, sizeof(pix));
-
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
- if (dx != 0 && dy != 0 &&
- this->mdist(x + dx, y + dy) < d) {
- float weight = M_SQRT1_2; /* 1.0f / sqrt(2) */
+ if (dx != 0 && dy != 0) {
- if (dx == 0 || dy == 0) {
- weight = 1.0f;
- }
-
- for (int c = 0; c < 3; c++) {
- float fk = this->get(x + dx, y + dy, c);
+ int x_ofs = x + dx;
+ int y_ofs = y + dy;
+ clamp_xy(x_ofs, y_ofs);
- pix[c] += fk * weight;
+ if (this->mdist(x_ofs, y_ofs) < d) {
+
+ float weight;
+
+ if (dx == 0 || dy == 0) {
+ weight = 1.0f;
+ }
+ else {
+ weight = M_SQRT1_2; /* 1.0f / sqrt(2) */
+ }
+
+ for (int c = 0; c < 3; c++) {
+ float fk = this->get(x_ofs, y_ofs, c);
+
+ pix[c] += fk * weight;
+ }
+ n += weight;
}
- n += weight;
}
}
}
@@ -233,6 +254,7 @@
void InpaintSimpleOperation::executePixel(float *color, int x, int y, void *data)
{
+ clamp_xy(x, y);
for (int c = 0; c < 3; c++) {
color[c] = get(x, y, c);
}
More information about the Bf-blender-cvs
mailing list