Skip to content

Commit

Permalink
better code safety
Browse files Browse the repository at this point in the history
avoid UMR and division by zero
  • Loading branch information
devernay committed Sep 29, 2021
1 parent 0d69b7c commit c09fc39
Show file tree
Hide file tree
Showing 31 changed files with 68 additions and 59 deletions.
4 changes: 2 additions & 2 deletions Add/Add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ class AddProcessor
unused(rs);
assert(nComponents == 1 || nComponents == 3 || nComponents == 4);
assert(_dstImg);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
4 changes: 2 additions & 2 deletions Clamp/Clamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ class ImageClamper
void processClampTo(const OfxRectI& procWindow, const OfxPointD& rs)
{
unused(rs);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};

for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
Expand Down
4 changes: 2 additions & 2 deletions ClipTest/ClipTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ class ClipTestProcessor
unused(rs);
assert(nComponents == 1 || nComponents == 3 || nComponents == 4);
assert(_dstImg);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
4 changes: 2 additions & 2 deletions ColorCorrect/ColorCorrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ class ColorCorrecter
assert( (!processR && !processG && !processB) || (nComponents == 3 || nComponents == 4) );
assert( !processA || (nComponents == 1 || nComponents == 4) );
assert(nComponents == 3 || nComponents == 4);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
6 changes: 3 additions & 3 deletions ColorLookup/ColorLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ class ColorLookupProcessor
unused(rs);
assert(nComponents == 1 || nComponents == 3 || nComponents == 4);
assert(_dstImg);
float tmpPix[4];
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down Expand Up @@ -542,7 +542,7 @@ class ColorLookupProcessor
ofxsMaskMixPix<PIX, nComponents, maxValue, true>(tmpPix, x, y, srcPix, _doMasking, _maskImg, (float)_mix, _maskInvert, dstPix);
} else {
//assert(nComponents == 4);
float unpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
ofxsUnPremult<PIX, nComponents, maxValue>(srcPix, unpPix, _premult, _premultChannel);
float r = unpPix[0];
float g = unpPix[1];
Expand Down Expand Up @@ -870,7 +870,7 @@ class HistogramProcessor
PIX *dstPix = (PIX *) _dstImg->getPixelAddress(procWindow.x1, y);

for (int x = procWindow.x1; x < procWindow.x2; ++x) {
float unpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
ofxsUnPremult<PIX, nComponents, maxValue>(dstPix, unpPix, _premult, _premultChannel);

for (int c = 0; c < (std::min)(nComponents, 3); ++c) {
Expand Down
4 changes: 2 additions & 2 deletions ColorMatrix/ColorMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ class ColorMatrixProcessor
unused(rs);
assert(nComponents == 1 || nComponents == 3 || nComponents == 4);
assert(_dstImg);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
4 changes: 2 additions & 2 deletions ColorSuppress/ColorSuppress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ class ColorSuppressProcessor
unused(rs);
assert(nComponents == 1 || nComponents == 3 || nComponents == 4);
assert(_dstImg);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
4 changes: 2 additions & 2 deletions ColorTransform/ColorTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ class ColorTransformProcessor
unused(rs);
assert(nComponents == 3 || nComponents == 4);
assert(_dstImg);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
const bool dounpremult = _premult && fromRGB(transform);
const bool dopremult = _premult && toRGB(transform);

Expand Down
3 changes: 3 additions & 0 deletions ColorWheel/ColorWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ class ColorWheelProcessor
{
double par = _dstImg->getPixelAspectRatio();
OfxPointD c; // center position in pixel
if (par <= 0.) {
par = 1.;
}

Coords::toPixelSub(_center, rs, par, &c);
OfxPointD r; // radius in pixel
Expand Down
4 changes: 2 additions & 2 deletions DenoiseSharpen/DenoiseSharpen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2545,7 +2545,7 @@ DenoiseSharpenPlugin::renderForBitDepth(const RenderArguments &args)

for (int x = p.srcWindow.x1; x < p.srcWindow.x2; x++) {
const PIX *srcPix = (const PIX *) (src.get() ? src->getPixelAddress(x, y) : 0);
float unpPix[4] = {0., 0., 0., 0.};
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
ofxsUnPremult<PIX, nComponents, maxValue>(srcPix, unpPix, p.premult, p.premultChannel);
unsigned int pix = (x - p.srcWindow.x1) + (y - p.srcWindow.y1) * iwidth;
// convert to the appropriate color model and store in tmpPixelData
Expand Down Expand Up @@ -3159,7 +3159,7 @@ DenoiseSharpenPlugin::analyzeNoiseLevelsForBitDepth(const InstanceChangedArgs &a

for (int x = srcWindow.x1; x < srcWindow.x2; x++) {
const PIX *srcPix = (const PIX *) (src.get() ? src->getPixelAddress(x, y) : 0);
float unpPix[4] = {0., 0., 0., 0.};
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
ofxsUnPremult<PIX, nComponents, maxValue>(srcPix, unpPix, premult, premultChannel);
unsigned int pix = (x - srcWindow.x1) + (y - srcWindow.y1) * iwidth;
// convert to the appropriate color model and store in tmpPixelData
Expand Down
2 changes: 1 addition & 1 deletion Despill/Despill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class DespillProcessor
void multiThreadProcessImages(const OfxRectI& procWindow, const OfxPointD& rs) OVERRIDE FINAL
{
unused(rs);
float tmpPix[4];
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};

assert(nComponents == 3 || nComponents == 4);
assert(_dstImg);
Expand Down
2 changes: 1 addition & 1 deletion Distortion/Distortion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ DistortionProcessor<PIX, nComponents, maxValue, plugin, filter, clamp>::multiThr
int srcy1 = int(std::ceil(_format.y1));
int srcy2 = int(std::floor(_format.y2));
//}
float tmpPix[4];
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
4 changes: 2 additions & 2 deletions Gamma/Gamma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ class GammaProcessor
unused(rs);
assert(nComponents == 1 || nComponents == 3 || nComponents == 4);
assert(_dstImg);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
4 changes: 2 additions & 2 deletions Grade/Grade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,8 @@ class GradeProcessor
assert( !processA || (nComponents == 1 || nComponents == 4) );
assert(nComponents == 3 || nComponents == 4);
assert(_dstImg);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
if ( reverse() ) {
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
Expand Down
4 changes: 2 additions & 2 deletions HSVTool/HSVTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ class HSVToolProcessor
unused(rs);
assert(nComponents == 3 || nComponents == 4);
assert(_dstImg);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
// only premultiply output if keeping the source alpha
const bool premultOut = _premult && (_outputAlpha == eOutputAlphaSource);
for (int y = procWindow.y1; y < procWindow.y2; y++) {
Expand Down
4 changes: 2 additions & 2 deletions HueCorrect/HueCorrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class HueCorrectProcessor
unused(rs);
assert(nComponents == 3 || nComponents == 4);
assert(_dstImg);
float tmpPix[4];
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand All @@ -336,7 +336,7 @@ class HueCorrectProcessor

for (int x = procWindow.x1; x < procWindow.x2; x++) {
const PIX *srcPix = (const PIX *) (_srcImg ? _srcImg->getPixelAddress(x, y) : 0);
float unpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
ofxsUnPremult<PIX, nComponents, maxValue>(srcPix, unpPix, _premult, _premultChannel);
// ofxsUnPremult outputs normalized data

Expand Down
4 changes: 2 additions & 2 deletions HueCorrect/HueCorrect1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class HueCorrectProcessor
unused(rs);
assert(nComponents == 3 || nComponents == 4);
assert(_dstImg);
float tmpPix[4];
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand All @@ -330,7 +330,7 @@ class HueCorrectProcessor

for (int x = procWindow.x1; x < procWindow.x2; x++) {
const PIX *srcPix = (const PIX *) (_srcImg ? _srcImg->getPixelAddress(x, y) : 0);
float unpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
ofxsUnPremult<PIX, nComponents, maxValue>(srcPix, unpPix, _premult, _premultChannel);
// ofxsUnPremult outputs normalized data

Expand Down
4 changes: 2 additions & 2 deletions Invert/Invert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ class ImageInverter
void process(const OfxRectI& procWindow, const OfxPointD& rs)
{
unused(rs);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};

for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
Expand Down
2 changes: 1 addition & 1 deletion KeyMix/KeyMix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class KeyMixProcessor
void multiThreadProcessImages(const OfxRectI& procWindow, const OfxPointD& rs) OVERRIDE FINAL
{
unused(rs);
float tmpPix[4];
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int c = 0; c < 4; ++c) {
tmpPix[c] = 0;
}
Expand Down
8 changes: 4 additions & 4 deletions Log2Lin/Log2Lin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ class PLog2LinProcessor
unused(rs);
assert( (!processR && !processG && !processB) || (nComponents == 3 || nComponents == 4) );
assert(nComponents == 3 || nComponents == 4);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down Expand Up @@ -403,8 +403,8 @@ class PLin2LogProcessor
unused(rs);
assert( (!processR && !processG && !processB) || (nComponents == 3 || nComponents == 4) );
assert(nComponents == 3 || nComponents == 4);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
4 changes: 2 additions & 2 deletions Multiply/Multiply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ class MultiplyProcessor
unused(rs);
assert(nComponents == 1 || nComponents == 3 || nComponents == 4);
assert(_dstImg);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
8 changes: 4 additions & 4 deletions PLogLin/PLogLin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ class PLog2LinProcessor
unused(rs);
assert( (!processR && !processG && !processB) || (nComponents == 3 || nComponents == 4) );
assert(nComponents == 3 || nComponents == 4);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down Expand Up @@ -407,8 +407,8 @@ class PLin2LogProcessor
unused(rs);
assert( (!processR && !processG && !processB) || (nComponents == 3 || nComponents == 4) );
assert(nComponents == 3 || nComponents == 4);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
4 changes: 2 additions & 2 deletions Quantize/Quantize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ class QuantizeProcessor
assert( (!processR && !processG && !processB) || (nComponents == 3 || nComponents == 4) );
assert( !processA || (nComponents == 1 || nComponents == 4) );
assert(nComponents == 3 || nComponents == 4);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
// set up a random number generator and set the seed
#ifdef USE_RANDOMGENERATOR
RandomGenerator randy;
Expand Down
5 changes: 4 additions & 1 deletion Radial/Radial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,11 @@ class RadialProcessor
assert( (!processR && !processG && !processB) || (nComponents == 3 || nComponents == 4) );
assert( !processA || (nComponents == 1 || nComponents == 4) );

float tmpPix[4];
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
double par = _dstImg->getPixelAspectRatio();
if (par <= 0.) {
par = 1.;
}

// center of the ellipse
OfxPointD c_canonical = { ( _btmLeft.x + (_btmLeft.x + _size.x) ) / 2, ( _btmLeft.y + (_btmLeft.y + _size.y) ) / 2 };
Expand Down
2 changes: 1 addition & 1 deletion Ramp/Ramp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class RampProcessor
template<bool processR, bool processG, bool processB, bool processA, RampTypeEnum type>
void processForType(const OfxRectI& procWindow, const OfxPointD& rs)
{
float tmpPix[4];
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
const double norm2 = (_point1.x - _point0.x) * (_point1.x - _point0.x) + (_point1.y - _point0.y) * (_point1.y - _point0.y);
const double nx = norm2 == 0. ? 0. : (_point1.x - _point0.x) / norm2;
const double ny = norm2 == 0. ? 0. : (_point1.y - _point0.y) / norm2;
Expand Down
7 changes: 5 additions & 2 deletions Rectangle/Rectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,11 @@ class RectangleProcessor
assert( (!processR && !processG && !processB) || (nComponents == 3 || nComponents == 4) );
assert( !processA || (nComponents == 1 || nComponents == 4) );

float tmpPix[4];
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
double par = _dstImg->getPixelAspectRatio();
if (par <= 0.) {
par = 1.;
}
OfxPointD btmLeft_canonical = { _btmLeft.x, _btmLeft.y };
OfxPointD topRight_canonical = { _btmLeft.x + _size.x, _btmLeft.y + _size.y };
OfxPointD btmLeft; // btmLeft position in pixel
Expand Down Expand Up @@ -449,7 +452,7 @@ class RectangleProcessor
tmpPix[3] = (float)_color0.a;
} else {
// always consider the value closest top the center to avoid discontinuities/artifacts
if (_softness == 0) {
if (_softness <= 0) {
// solid color
tmpPix[0] = (float)_color1.r;
tmpPix[1] = (float)_color1.g;
Expand Down
4 changes: 2 additions & 2 deletions Saturation/Saturation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ class SaturationProcessor
assert( !processA || (nComponents == 1 || nComponents == 4) );
assert(nComponents == 3 || nComponents == 4);
assert(_dstImg);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
2 changes: 1 addition & 1 deletion SupportExt
Submodule SupportExt updated 1 files
+31 −18 ofxsCopier.h
4 changes: 2 additions & 2 deletions Templates/MaskableFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ class MaskableFilterProcessor
assert( (!processR && !processG && !processB) || (nComponents == 3 || nComponents == 4) );
assert( !processA || (nComponents == 1 || nComponents == 4) );
assert(nComponents == 3 || nComponents == 4);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
4 changes: 2 additions & 2 deletions Templates/MixableFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ class MixableFilterProcessor
assert( (!processR && !processG && !processB) || (nComponents == 3 || nComponents == 4) );
assert( !processA || (nComponents == 1 || nComponents == 4) );
assert(nComponents == 3 || nComponents == 4);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down
4 changes: 2 additions & 2 deletions Templates/SimpleFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ class SimpleFilterProcessor
assert( (!processR && !processG && !processB) || (nComponents == 3 || nComponents == 4) );
assert( !processA || (nComponents == 1 || nComponents == 4) );
assert(nComponents == 3 || nComponents == 4);
float unpPix[4];
float tmpPix[4];
float unpPix[4] = {0.f, 0.f, 0.f, 0.f};
float tmpPix[4] = {0.f, 0.f, 0.f, 0.f};
for (int y = procWindow.y1; y < procWindow.y2; y++) {
if ( _effect.abort() ) {
break;
Expand Down

0 comments on commit c09fc39

Please sign in to comment.