fix for bokeh blur using uninitialized memory - it would cause some tiles not to...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 3 Aug 2012 09:51:10 +0000 (09:51 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 3 Aug 2012 09:51:10 +0000 (09:51 +0000)
was in fact a bug in MemoryBuffer::getMaximumValue

source/blender/compositor/intern/COM_MemoryBuffer.cpp
source/blender/compositor/intern/COM_MemoryBuffer.h

index f8c842d8e678489c1699a524f18275baa82338b1..eae98a1211f454b1e891cd897ac1ad9983ec0b62 100644 (file)
@@ -105,13 +105,24 @@ float MemoryBuffer::getMaximumValue()
        return result;
 }
 
-float MemoryBuffer::getMaximumValue(rctirect)
+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;
index 411c5b9ad8a581e6d7a74eebe97b4ccca5fd89b3..f64603ed5d94626ad001effd377f91ca914b9c1d 100644 (file)
@@ -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(rctirect);
+       float getMaximumValue(rcti *rect);
 private:
        unsigned int determineBufferSize();