diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-06-03 20:23:47 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-06-03 20:23:47 +0400 |
commit | 5e424cacb53214507a40c439fb1e61d8a570db12 (patch) | |
tree | 4826385d7349d405016cf2a6298224da211254c7 /source/blender/compositor/intern/COM_MemoryBuffer.cpp | |
parent | c66f3571681bcf9595bb79540a687b058aa9988c (diff) |
minor optimizations to compositor, avoid indirections when operating array members multiple times
Diffstat (limited to 'source/blender/compositor/intern/COM_MemoryBuffer.cpp')
-rw-r--r-- | source/blender/compositor/intern/COM_MemoryBuffer.cpp | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cpp b/source/blender/compositor/intern/COM_MemoryBuffer.cpp index d22c75c922b..37d79607d12 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.cpp +++ b/source/blender/compositor/intern/COM_MemoryBuffer.cpp @@ -73,12 +73,16 @@ void MemoryBuffer::clear() float *MemoryBuffer::convertToValueBuffer() { - int size = this->determineBufferSize(); - int i; - int offset4; + const unsigned int size = this->determineBufferSize(); + unsigned int i; + float *result = new float[size]; - for (i = 0, offset4 = 0 ; i < size ; i ++, offset4 +=COM_NUMBER_OF_CHANNELS) { - result[i] = this->buffer[offset4]; + + const float *fp_src = this->buffer; + float *fp_dst = result; + + for (i = 0; i < size ; i++, fp_dst++, fp_src += COM_NUMBER_OF_CHANNELS) { + *fp_dst = *fp_src; } return result; @@ -113,38 +117,31 @@ void MemoryBuffer::copyContentFrom(MemoryBuffer *otherBuffer) } } -void MemoryBuffer::read(float *result, int x, int y) +void MemoryBuffer::read(float result[4], int x, int y) { if (x>=this->rect.xmin && x < this->rect.xmax && - y>=this->rect.ymin && y < this->rect.ymax) { - int dx = x-this->rect.xmin; - int dy = y-this->rect.ymin; - int offset = (this->chunkWidth*dy+dx)*COM_NUMBER_OF_CHANNELS; - result[0] = this->buffer[offset]; - result[1] = this->buffer[offset+1]; - result[2] = this->buffer[offset+2]; - result[3] = this->buffer[offset+3]; + y>=this->rect.ymin && y < this->rect.ymax) + { + const int dx = x - this->rect.xmin; + const int dy = y - this->rect.ymin; + const int offset = (this->chunkWidth * dy + dx) * COM_NUMBER_OF_CHANNELS; + copy_v4_v4(result, &this->buffer[offset]); } else { - result[0] = 0.0f; - result[1] = 0.0f; - result[2] = 0.0f; - result[3] = 0.0f; + zero_v4(result); } } -void MemoryBuffer::writePixel(int x, int y, float color[4]) +void MemoryBuffer::writePixel(int x, int y, const float color[4]) { - if (x>=this->rect.xmin && x < this->rect.xmax && - y>=this->rect.ymin && y < this->rect.ymax) { - int offset = (this->chunkWidth*y+x)*COM_NUMBER_OF_CHANNELS; - this->buffer[offset] = color[0]; - this->buffer[offset+1] = color[1]; - this->buffer[offset+2] = color[2]; - this->buffer[offset+3] = color[3]; + if (x >= this->rect.xmin && x < this->rect.xmax && + y >= this->rect.ymin && y < this->rect.ymax) + { + const int offset = (this->chunkWidth * y + x) * COM_NUMBER_OF_CHANNELS; + copy_v4_v4(&this->buffer[offset], color); } } -void MemoryBuffer::readCubic(float *result, float x, float y) +void MemoryBuffer::readCubic(float result[4], float x, float y) { int x1 = floor(x); int x2 = x1 + 1; @@ -266,9 +263,9 @@ float clipuv(float x, float limit) return x; } -void MemoryBuffer::readEWA(float *result, float fx, float fy, float dx, float dy) +void MemoryBuffer::readEWA(float result[4], float fx, float fy, float dx, float dy) { - int width = this->getWidth(), height = this->getHeight(); + const int width = this->getWidth(), height = this->getHeight(); // scaling dxt/dyt by full resolution can cause overflow because of huge A/B/C and esp. F values, // scaling by aspect ratio alone does the opposite, so try something in between instead... |