diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-03-19 18:07:32 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-03-19 19:11:47 +0300 |
commit | dc9aea9903d2af0b4333fcc6992fc9ea8e72876e (patch) | |
tree | e6fa2eca3d2ef034de69b9f7e0b43c252cc66448 /source/blender/compositor | |
parent | 260e50ed82ce015224c796a6354d2b4b18422b6f (diff) |
Cleanup: Add copy constructor to MemoryBuffer.
Diffstat (limited to 'source/blender/compositor')
6 files changed, 79 insertions, 82 deletions
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cc b/source/blender/compositor/intern/COM_MemoryBuffer.cc index 46c99623244..2664612beed 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.cc +++ b/source/blender/compositor/intern/COM_MemoryBuffer.cc @@ -74,6 +74,7 @@ MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, const rcti &rect) this->m_state = COM_MB_TEMPORARILY; this->m_datatype = memoryProxy->getDataType(); } + MemoryBuffer::MemoryBuffer(DataType dataType, const rcti &rect) { m_rect = rect; @@ -88,14 +89,17 @@ MemoryBuffer::MemoryBuffer(DataType dataType, const rcti &rect) this->m_state = COM_MB_TEMPORARILY; this->m_datatype = dataType; } -MemoryBuffer *MemoryBuffer::duplicate() + +MemoryBuffer::MemoryBuffer(const MemoryBuffer &src) : MemoryBuffer(src.m_memoryProxy, src.m_rect) { - MemoryBuffer *result = new MemoryBuffer(this->m_memoryProxy, this->m_rect); - memcpy(result->m_buffer, - this->m_buffer, - this->determineBufferSize() * this->m_num_channels * sizeof(float)); - return result; + memcpy(m_buffer, src.m_buffer, determineBufferSize() * m_num_channels * sizeof(float)); } + +// MemoryBuffer *MemoryBuffer::duplicate() +// { +// return new MemoryBuffer(*this); +// } + void MemoryBuffer::clear() { memset(this->m_buffer, 0, this->determineBufferSize() * this->m_num_channels * sizeof(float)); diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h index b80124ca136..e19837b49c2 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.h +++ b/source/blender/compositor/intern/COM_MemoryBuffer.h @@ -111,6 +111,11 @@ class MemoryBuffer { MemoryBuffer(DataType datatype, const rcti &rect); /** + * Copy constructor + */ + MemoryBuffer(const MemoryBuffer &src); + + /** * \brief destructor */ ~MemoryBuffer(); @@ -339,8 +344,6 @@ class MemoryBuffer { */ void clear(); - MemoryBuffer *duplicate(); - float getMaximumValue(); float getMaximumValue(rcti *rect); diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc index c896cfcc49f..922d6a859a3 100644 --- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc +++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc @@ -80,7 +80,7 @@ void *FastGaussianBlurOperation::initializeTileData(rcti *rect) lockMutex(); if (!this->m_iirgaus) { MemoryBuffer *newBuf = (MemoryBuffer *)this->m_inputProgram->initializeTileData(rect); - MemoryBuffer *copy = newBuf->duplicate(); + MemoryBuffer *copy = new MemoryBuffer(*newBuf); updateSize(); int c; @@ -310,7 +310,7 @@ void *FastGaussianBlurValueOperation::initializeTileData(rcti *rect) lockMutex(); if (!this->m_iirgaus) { MemoryBuffer *newBuf = (MemoryBuffer *)this->m_inputprogram->initializeTileData(rect); - MemoryBuffer *copy = newBuf->duplicate(); + MemoryBuffer *copy = new MemoryBuffer(*newBuf); FastGaussianBlurOperation::IIR_gauss(copy, this->m_sigma, 0, 3); if (this->m_overlay == FAST_GAUSS_OVERLAY_MIN) { diff --git a/source/blender/compositor/operations/COM_GlareGhostOperation.cc b/source/blender/compositor/operations/COM_GlareGhostOperation.cc index 760b833d1e1..a4cd6dc60c1 100644 --- a/source/blender/compositor/operations/COM_GlareGhostOperation.cc +++ b/source/blender/compositor/operations/COM_GlareGhostOperation.cc @@ -41,41 +41,41 @@ void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, No float sc, isc, u, v, sm, s, t, ofs, scalef[64]; const float cmo = 1.0f - settings->colmod; - MemoryBuffer *gbuf = inputTile->duplicate(); - MemoryBuffer *tbuf1 = inputTile->duplicate(); + MemoryBuffer gbuf(*inputTile); + MemoryBuffer tbuf1(*inputTile); bool breaked = false; - FastGaussianBlurOperation::IIR_gauss(tbuf1, s1, 0, 3); + FastGaussianBlurOperation::IIR_gauss(&tbuf1, s1, 0, 3); if (!breaked) { - FastGaussianBlurOperation::IIR_gauss(tbuf1, s1, 1, 3); + FastGaussianBlurOperation::IIR_gauss(&tbuf1, s1, 1, 3); } if (isBraked()) { breaked = true; } if (!breaked) { - FastGaussianBlurOperation::IIR_gauss(tbuf1, s1, 2, 3); + FastGaussianBlurOperation::IIR_gauss(&tbuf1, s1, 2, 3); } - MemoryBuffer *tbuf2 = tbuf1->duplicate(); + MemoryBuffer tbuf2(tbuf1); if (isBraked()) { breaked = true; } if (!breaked) { - FastGaussianBlurOperation::IIR_gauss(tbuf2, s2, 0, 3); + FastGaussianBlurOperation::IIR_gauss(&tbuf2, s2, 0, 3); } if (isBraked()) { breaked = true; } if (!breaked) { - FastGaussianBlurOperation::IIR_gauss(tbuf2, s2, 1, 3); + FastGaussianBlurOperation::IIR_gauss(&tbuf2, s2, 1, 3); } if (isBraked()) { breaked = true; } if (!breaked) { - FastGaussianBlurOperation::IIR_gauss(tbuf2, s2, 2, 3); + FastGaussianBlurOperation::IIR_gauss(&tbuf2, s2, 2, 3); } ofs = (settings->iter & 1) ? 0.5f : 0.0f; @@ -99,61 +99,57 @@ void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, No sc = 2.13; isc = -0.97; - for (y = 0; y < gbuf->getHeight() && (!breaked); y++) { - v = ((float)y + 0.5f) / (float)gbuf->getHeight(); - for (x = 0; x < gbuf->getWidth(); x++) { - u = ((float)x + 0.5f) / (float)gbuf->getWidth(); + for (y = 0; y < gbuf.getHeight() && (!breaked); y++) { + v = ((float)y + 0.5f) / (float)gbuf.getHeight(); + for (x = 0; x < gbuf.getWidth(); x++) { + u = ((float)x + 0.5f) / (float)gbuf.getWidth(); s = (u - 0.5f) * sc + 0.5f; t = (v - 0.5f) * sc + 0.5f; - tbuf1->readBilinear(c, s * gbuf->getWidth(), t * gbuf->getHeight()); + tbuf1.readBilinear(c, s * gbuf.getWidth(), t * gbuf.getHeight()); sm = smoothMask(s, t); mul_v3_fl(c, sm); s = (u - 0.5f) * isc + 0.5f; t = (v - 0.5f) * isc + 0.5f; - tbuf2->readBilinear(tc, s * gbuf->getWidth() - 0.5f, t * gbuf->getHeight() - 0.5f); + tbuf2.readBilinear(tc, s * gbuf.getWidth() - 0.5f, t * gbuf.getHeight() - 0.5f); sm = smoothMask(s, t); madd_v3_v3fl(c, tc, sm); - gbuf->writePixel(x, y, c); + gbuf.writePixel(x, y, c); } if (isBraked()) { breaked = true; } } - memset(tbuf1->getBuffer(), + memset(tbuf1.getBuffer(), 0, - tbuf1->getWidth() * tbuf1->getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float)); + tbuf1.getWidth() * tbuf1.getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float)); for (n = 1; n < settings->iter && (!breaked); n++) { - for (y = 0; y < gbuf->getHeight() && (!breaked); y++) { - v = ((float)y + 0.5f) / (float)gbuf->getHeight(); - for (x = 0; x < gbuf->getWidth(); x++) { - u = ((float)x + 0.5f) / (float)gbuf->getWidth(); + for (y = 0; y < gbuf.getHeight() && (!breaked); y++) { + v = ((float)y + 0.5f) / (float)gbuf.getHeight(); + for (x = 0; x < gbuf.getWidth(); x++) { + u = ((float)x + 0.5f) / (float)gbuf.getWidth(); tc[0] = tc[1] = tc[2] = 0.0f; for (p = 0; p < 4; p++) { np = (n << 2) + p; s = (u - 0.5f) * scalef[np] + 0.5f; t = (v - 0.5f) * scalef[np] + 0.5f; - gbuf->readBilinear(c, s * gbuf->getWidth() - 0.5f, t * gbuf->getHeight() - 0.5f); + gbuf.readBilinear(c, s * gbuf.getWidth() - 0.5f, t * gbuf.getHeight() - 0.5f); mul_v3_v3(c, cm[np]); sm = smoothMask(s, t) * 0.25f; madd_v3_v3fl(tc, c, sm); } - tbuf1->addPixel(x, y, tc); + tbuf1.addPixel(x, y, tc); } if (isBraked()) { breaked = true; } } - memcpy(gbuf->getBuffer(), - tbuf1->getBuffer(), - tbuf1->getWidth() * tbuf1->getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float)); + memcpy(gbuf.getBuffer(), + tbuf1.getBuffer(), + tbuf1.getWidth() * tbuf1.getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float)); } memcpy(data, - gbuf->getBuffer(), - gbuf->getWidth() * gbuf->getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float)); - - delete gbuf; - delete tbuf1; - delete tbuf2; + gbuf.getBuffer(), + gbuf.getWidth() * gbuf.getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float)); } diff --git a/source/blender/compositor/operations/COM_GlareSimpleStarOperation.cc b/source/blender/compositor/operations/COM_GlareSimpleStarOperation.cc index 75c2ae51bde..a2cecb7e171 100644 --- a/source/blender/compositor/operations/COM_GlareSimpleStarOperation.cc +++ b/source/blender/compositor/operations/COM_GlareSimpleStarOperation.cc @@ -27,8 +27,8 @@ void GlareSimpleStarOperation::generateGlare(float *data, const float f1 = 1.0f - settings->fade; const float f2 = (1.0f - f1) * 0.5f; - MemoryBuffer *tbuf1 = inputTile->duplicate(); - MemoryBuffer *tbuf2 = inputTile->duplicate(); + MemoryBuffer tbuf1(*inputTile); + MemoryBuffer tbuf2(*inputTile); bool breaked = false; for (i = 0; i < settings->iter && (!breaked); i++) { @@ -40,23 +40,23 @@ void GlareSimpleStarOperation::generateGlare(float *data, for (x = 0; x < this->getWidth(); x++) { xm = x - i; xp = x + i; - tbuf1->read(c, x, y); + tbuf1.read(c, x, y); mul_v3_fl(c, f1); - tbuf1->read(tc, (settings->star_45 ? xm : x), ym); + tbuf1.read(tc, (settings->star_45 ? xm : x), ym); madd_v3_v3fl(c, tc, f2); - tbuf1->read(tc, (settings->star_45 ? xp : x), yp); + tbuf1.read(tc, (settings->star_45 ? xp : x), yp); madd_v3_v3fl(c, tc, f2); c[3] = 1.0f; - tbuf1->writePixel(x, y, c); + tbuf1.writePixel(x, y, c); - tbuf2->read(c, x, y); + tbuf2.read(c, x, y); mul_v3_fl(c, f1); - tbuf2->read(tc, xm, (settings->star_45 ? yp : y)); + tbuf2.read(tc, xm, (settings->star_45 ? yp : y)); madd_v3_v3fl(c, tc, f2); - tbuf2->read(tc, xp, (settings->star_45 ? ym : y)); + tbuf2.read(tc, xp, (settings->star_45 ? ym : y)); madd_v3_v3fl(c, tc, f2); c[3] = 1.0f; - tbuf2->writePixel(x, y, c); + tbuf2.writePixel(x, y, c); } if (isBraked()) { breaked = true; @@ -69,23 +69,23 @@ void GlareSimpleStarOperation::generateGlare(float *data, for (x = this->getWidth() - 1; x >= 0; x--) { xm = x - i; xp = x + i; - tbuf1->read(c, x, y); + tbuf1.read(c, x, y); mul_v3_fl(c, f1); - tbuf1->read(tc, (settings->star_45 ? xm : x), ym); + tbuf1.read(tc, (settings->star_45 ? xm : x), ym); madd_v3_v3fl(c, tc, f2); - tbuf1->read(tc, (settings->star_45 ? xp : x), yp); + tbuf1.read(tc, (settings->star_45 ? xp : x), yp); madd_v3_v3fl(c, tc, f2); c[3] = 1.0f; - tbuf1->writePixel(x, y, c); + tbuf1.writePixel(x, y, c); - tbuf2->read(c, x, y); + tbuf2.read(c, x, y); mul_v3_fl(c, f1); - tbuf2->read(tc, xm, (settings->star_45 ? yp : y)); + tbuf2.read(tc, xm, (settings->star_45 ? yp : y)); madd_v3_v3fl(c, tc, f2); - tbuf2->read(tc, xp, (settings->star_45 ? ym : y)); + tbuf2.read(tc, xp, (settings->star_45 ? ym : y)); madd_v3_v3fl(c, tc, f2); c[3] = 1.0f; - tbuf2->writePixel(x, y, c); + tbuf2.writePixel(x, y, c); } if (isBraked()) { breaked = true; @@ -94,9 +94,6 @@ void GlareSimpleStarOperation::generateGlare(float *data, } for (i = 0; i < this->getWidth() * this->getHeight() * 4; i++) { - data[i] = tbuf1->getBuffer()[i] + tbuf2->getBuffer()[i]; + data[i] = tbuf1.getBuffer()[i] + tbuf2.getBuffer()[i]; } - - delete tbuf1; - delete tbuf2; } diff --git a/source/blender/compositor/operations/COM_GlareStreaksOperation.cc b/source/blender/compositor/operations/COM_GlareStreaksOperation.cc index 0da1174199d..0ea277881da 100644 --- a/source/blender/compositor/operations/COM_GlareStreaksOperation.cc +++ b/source/blender/compositor/operations/COM_GlareStreaksOperation.cc @@ -33,9 +33,9 @@ void GlareStreaksOperation::generateGlare(float *data, bool breaked = false; - MemoryBuffer *tsrc = inputTile->duplicate(); - MemoryBuffer *tdst = new MemoryBuffer(DataType::Color, inputTile->get_rect()); - tdst->clear(); + MemoryBuffer tsrc(*inputTile); + MemoryBuffer tdst(DataType::Color, inputTile->get_rect()); + tdst.clear(); memset(data, 0, size4 * sizeof(float)); for (a = 0.0f; a < DEG2RADF(360.0f) && (!breaked); a += ang) { @@ -49,20 +49,20 @@ void GlareStreaksOperation::generateGlare(float *data, (float)pow((double)settings->colmod, (double)n + 1); // colormodulation amount relative to current pass - float *tdstcol = tdst->getBuffer(); - for (y = 0; y < tsrc->getHeight() && (!breaked); y++) { - for (x = 0; x < tsrc->getWidth(); x++, tdstcol += 4) { + float *tdstcol = tdst.getBuffer(); + for (y = 0; y < tsrc.getHeight() && (!breaked); y++) { + for (x = 0; x < tsrc.getWidth(); x++, tdstcol += 4) { // first pass no offset, always same for every pass, exact copy, // otherwise results in uneven brightness, only need once if (n == 0) { - tsrc->read(c1, x, y); + tsrc.read(c1, x, y); } else { c1[0] = c1[1] = c1[2] = 0; } - tsrc->readBilinear(c2, x + vxp, y + vyp); - tsrc->readBilinear(c3, x + vxp * 2.0f, y + vyp * 2.0f); - tsrc->readBilinear(c4, x + vxp * 3.0f, y + vyp * 3.0f); + tsrc.readBilinear(c2, x + vxp, y + vyp); + tsrc.readBilinear(c3, x + vxp * 2.0f, y + vyp * 2.0f); + tsrc.readBilinear(c4, x + vxp * 3.0f, y + vyp * 3.0f); // modulate color to look vaguely similar to a color spectrum c2[1] *= cmo; c2[2] *= cmo; @@ -82,21 +82,18 @@ void GlareStreaksOperation::generateGlare(float *data, breaked = true; } } - memcpy(tsrc->getBuffer(), tdst->getBuffer(), sizeof(float) * size4); + memcpy(tsrc.getBuffer(), tdst.getBuffer(), sizeof(float) * size4); } - float *sourcebuffer = tsrc->getBuffer(); + float *sourcebuffer = tsrc.getBuffer(); float factor = 1.0f / (float)(6 - settings->iter); for (int i = 0; i < size4; i += 4) { madd_v3_v3fl(&data[i], &sourcebuffer[i], factor); data[i + 3] = 1.0f; } - tdst->clear(); - memcpy(tsrc->getBuffer(), inputTile->getBuffer(), sizeof(float) * size4); + tdst.clear(); + memcpy(tsrc.getBuffer(), inputTile->getBuffer(), sizeof(float) * size4); nump++; } - - delete tsrc; - delete tdst; } |