diff options
-rw-r--r-- | source/blender/compositor/intern/COM_MemoryBuffer.cpp | 24 | ||||
-rw-r--r-- | source/blender/compositor/intern/COM_MemoryBuffer.h | 5 |
2 files changed, 22 insertions, 7 deletions
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cpp b/source/blender/compositor/intern/COM_MemoryBuffer.cpp index f8c842d8e67..eae98a1211f 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.cpp +++ b/source/blender/compositor/intern/COM_MemoryBuffer.cpp @@ -105,13 +105,24 @@ float MemoryBuffer::getMaximumValue() return result; } -float MemoryBuffer::getMaximumValue(rcti* rect) +float MemoryBuffer::getMaximumValue(rcti *rect) { - MemoryBuffer *temp = new MemoryBuffer(NULL, rect); - temp->copyContentFrom(this); - float result = temp->getMaximumValue(); - delete temp; - return result; + rcti rect_clamp; + + /* first clamp the rect by the bounds or we get un-initialized values */ + BLI_rcti_isect(rect, &this->m_rect, &rect_clamp); + + if (!BLI_rcti_is_empty(&rect_clamp)) { + MemoryBuffer *temp = new MemoryBuffer(NULL, &rect_clamp); + temp->copyContentFrom(this); + float result = temp->getMaximumValue(); + delete temp; + return result; + } + else { + BLI_assert(0); + return 0.0f; + } } MemoryBuffer::~MemoryBuffer() @@ -125,6 +136,7 @@ MemoryBuffer::~MemoryBuffer() void MemoryBuffer::copyContentFrom(MemoryBuffer *otherBuffer) { if (!otherBuffer) { + BLI_assert(0); return; } unsigned int otherY; diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h index 411c5b9ad8a..f64603ed5d9 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.h +++ b/source/blender/compositor/intern/COM_MemoryBuffer.h @@ -202,6 +202,9 @@ public: /** * @brief add the content from otherBuffer to this MemoryBuffer * @param otherBuffer source buffer + * + * @note take care when running this on a new buffer since it wont fill in + * uninitialized values in areas where the buffers don't overlap. */ void copyContentFrom(MemoryBuffer *otherBuffer); @@ -229,7 +232,7 @@ public: float *convertToValueBuffer(); float getMaximumValue(); - float getMaximumValue(rcti* rect); + float getMaximumValue(rcti *rect); private: unsigned int determineBufferSize(); |