Skip to content

Commit

Permalink
avoid issues when min() and max() are defined as macros
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed Jun 6, 2018
1 parent b6a61d7 commit eeb975a
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 72 deletions.
4 changes: 2 additions & 2 deletions EXR/ReadEXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ ReadEXRPlugin::decode(const string& filename,
//int r = roi.x2;
//int x = roi.x1;

//const int X = std::max(x, datawin.min.x + file->dataOffset);
//const int R = std::min(r, datawin.max.x + file->dataOffset + 1);
//const int X = (std::max)(x, datawin.min.x + file->dataOffset);
//const int R = (std::min)(r, datawin.max.x + file->dataOffset + 1);

// if we're below or above the data window
if ( (exrY < datawin.min.y) || (exrY > datawin.max.y) /* || R <= X*/ ) {
Expand Down
4 changes: 2 additions & 2 deletions FFmpeg/FFmpegFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ FFmpegFile::FFmpegFile(const string & filename)
//} else
# endif
{
avctx->thread_count = std::min( (int)MultiThread::getNumCPUs(), OFX_FFMPEG_MAX_THREADS ); // ask for the number of available cores for multithreading
avctx->thread_count = (std::min)( (int)MultiThread::getNumCPUs(), OFX_FFMPEG_MAX_THREADS ); // ask for the number of available cores for multithreading
# ifdef AV_CODEC_CAP_SLICE_THREADS
if ( avctx->codec && (avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ) {
// multiple threads are used to decode a single frame. Reduces delay
Expand Down Expand Up @@ -1248,7 +1248,7 @@ FFmpegFile::decode(const ImageEffect* plugin,
// file but those same frames will decode succesfully on a second attempt. The root cause of this is not understood but
// it appears to be some oddity of FFmpeg. While I don't really like it, retrying decode enables us to successfully
// decode those files rather than having to fail the read.
int retriesRemaining = std::max(1, maxRetries);
int retriesRemaining = (std::max)(1, maxRetries);

// Whether we have just performed a seek and are still awaiting the first decoded frame after that seek. This controls
// how we respond when a decode stall is detected.
Expand Down
2 changes: 1 addition & 1 deletion FFmpeg/FFmpegFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class FFmpegFile
// Sometimes AVCodec reports a bitdepth of 0 (eg PNG codec).

// In this case, assume 8 bit.
return std::max(8, _streams[0]->_bitDepth);
return (std::max)(8, _streams[0]->_bitDepth);
}

int getNumberOfComponents() const
Expand Down
10 changes: 5 additions & 5 deletions FFmpeg/WriteFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2711,8 +2711,8 @@ WriteFFmpegPlugin::configureVideoStream(AVCodec* avCodec,
double bitrateTolerance = _bitrateTolerance->getValue();
if (bitrateTolerance >= 0) {
double fps = _fps->getValue();
double bitrateToleranceMin = std::ceil( (bitrate / std::min(fps, 4.)) * 1000000) / 1000000.;
bitrateTolerance = std::max( bitrateToleranceMin, bitrateTolerance );
double bitrateToleranceMin = std::ceil( (bitrate / (std::min)(fps, 4.)) * 1000000) / 1000000.;
bitrateTolerance = (std::max)( bitrateToleranceMin, bitrateTolerance );

avCodecContext->bit_rate_tolerance = (int)(bitrateTolerance * 1000000);
}
Expand Down Expand Up @@ -4004,7 +4004,7 @@ WriteFFmpegPlugin::beginEncode(const string& filename,
} else
# endif
{
avCodecContext->thread_count = std::min( (int)MultiThread::getNumCPUs(), OFX_FFMPEG_MAX_THREADS );
avCodecContext->thread_count = (std::min)( (int)MultiThread::getNumCPUs(), OFX_FFMPEG_MAX_THREADS );
}

if (openCodec(formatContext_, audioCodec, streamAudio_) < 0) {
Expand Down Expand Up @@ -4181,7 +4181,7 @@ WriteFFmpegPlugin::beginEncode(const string& filename,
} else
# endif
{
avCodecContext->thread_count = std::min( (int)MultiThread::getNumCPUs(), OFX_FFMPEG_MAX_THREADS );
avCodecContext->thread_count = (std::min)( (int)MultiThread::getNumCPUs(), OFX_FFMPEG_MAX_THREADS );
}
# ifdef AV_CODEC_CAP_SLICE_THREADS
if (avCodecContext->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) {
Expand Down Expand Up @@ -4669,7 +4669,7 @@ WriteFFmpegPlugin::updateBitrateToleranceRange()
double bitrate = _bitrate->getValue();
double fps = _fps->getValue();
// guard agains division by zero - the 4 comes from the ffserver.c code
double minRange = std::ceil( (bitrate / std::min(fps, 4.)) * 1000000) / 1000000.;
double minRange = std::ceil( (bitrate / (std::min)(fps, 4.)) * 1000000) / 1000000.;

_bitrateTolerance->setRange(minRange, kParamBitrateToleranceMax);
_bitrateTolerance->setDisplayRange(minRange, kParamBitrateToleranceMax);
Expand Down
22 changes: 11 additions & 11 deletions IOSupport/GenericReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1583,9 +1583,9 @@ GenericReaderPlugin::render(const RenderArguments &args)
_originalProxyScale->getValue(proxyOriginalScale.x, proxyOriginalScale.y);

///We only support downscaling at a power of two.
unsigned int renderMipmapLevel = getLevelFromScale( std::min(args.renderScale.x, args.renderScale.y) );
unsigned int proxyMipMapThresholdLevel = (proxyScaleThreshold.x == 0 || proxyScaleThreshold.y == 0) ? renderMipmapLevel : getLevelFromScale( std::min(proxyScaleThreshold.x, proxyScaleThreshold.y) );
unsigned int originalProxyMipMapLevel = (proxyOriginalScale.x == 0 || proxyOriginalScale.y == 0) ? renderMipmapLevel : getLevelFromScale( std::min(proxyOriginalScale.x, proxyOriginalScale.y) );
unsigned int renderMipmapLevel = getLevelFromScale( (std::min)(args.renderScale.x, args.renderScale.y) );
unsigned int proxyMipMapThresholdLevel = (proxyScaleThreshold.x == 0 || proxyScaleThreshold.y == 0) ? renderMipmapLevel : getLevelFromScale( (std::min)(proxyScaleThreshold.x, proxyScaleThreshold.y) );
unsigned int originalProxyMipMapLevel = (proxyOriginalScale.x == 0 || proxyOriginalScale.y == 0) ? renderMipmapLevel : getLevelFromScale( (std::min)(proxyOriginalScale.x, proxyOriginalScale.y) );

if ( kSupportsRenderScale && (renderMipmapLevel >= proxyMipMapThresholdLevel) ) {
useProxy = true;
Expand Down Expand Up @@ -1810,15 +1810,15 @@ GenericReaderPlugin::render(const RenderArguments &args)
frameBounds.y1 = frameHeight - frameBounds.y1;
frameBounds.y2 = frameHeight - frameBounds.y2;

renderWindowFullRes.x1 = std::min( (double)std::ceil( (double)renderWindowFullRes.x1 / tile_width ) * tile_width, (double)frameBounds.x1 );
renderWindowFullRes.y1 = std::min( (double)std::ceil( (double)renderWindowFullRes.y1 / tile_height ) * tile_height, (double)frameBounds.y1 );
renderWindowFullRes.x2 = std::max( (double)std::floor( (double)renderWindowFullRes.x2 / tile_width ) * tile_width, (double)frameBounds.x2 );
renderWindowFullRes.y2 = std::max( (double)std::floor( (double)renderWindowFullRes.y2 / tile_height ) * tile_height, (double)frameBounds.y2 );
renderWindowFullRes.x1 = (std::min)( (double)std::ceil( (double)renderWindowFullRes.x1 / tile_width ) * tile_width, (double)frameBounds.x1 );
renderWindowFullRes.y1 = (std::min)( (double)std::ceil( (double)renderWindowFullRes.y1 / tile_height ) * tile_height, (double)frameBounds.y1 );
renderWindowFullRes.x2 = (std::max)( (double)std::floor( (double)renderWindowFullRes.x2 / tile_width ) * tile_width, (double)frameBounds.x2 );
renderWindowFullRes.y2 = (std::max)( (double)std::floor( (double)renderWindowFullRes.y2 / tile_height ) * tile_height, (double)frameBounds.y2 );
} else {
renderWindowFullRes.x1 = std::max( (double)std::floor( (double)renderWindowFullRes.x1 / tile_width ) * tile_width, (double)frameBounds.x1 );
renderWindowFullRes.y1 = std::max( (double)std::floor( (double)renderWindowFullRes.y1 / tile_height ) * tile_height, (double)frameBounds.y1 );
renderWindowFullRes.x2 = std::min( (double)std::ceil( (double)renderWindowFullRes.x2 / tile_width ) * tile_width, (double)frameBounds.x2 );
renderWindowFullRes.y2 = std::min( (double)std::ceil( (double)renderWindowFullRes.y2 / tile_height ) * tile_height, (double)frameBounds.y2 );
renderWindowFullRes.x1 = (std::max)( (double)std::floor( (double)renderWindowFullRes.x1 / tile_width ) * tile_width, (double)frameBounds.x1 );
renderWindowFullRes.y1 = (std::max)( (double)std::floor( (double)renderWindowFullRes.y1 / tile_height ) * tile_height, (double)frameBounds.y1 );
renderWindowFullRes.x2 = (std::min)( (double)std::ceil( (double)renderWindowFullRes.x2 / tile_width ) * tile_width, (double)frameBounds.x2 );
renderWindowFullRes.y2 = (std::min)( (double)std::ceil( (double)renderWindowFullRes.y2 / tile_height ) * tile_height, (double)frameBounds.y2 );
}

if ( isTileOrientationTopDown() ) {
Expand Down
4 changes: 2 additions & 2 deletions IOSupport/GenericWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,14 @@ GenericWriterPlugin::fetchPlaneConvertAndCopy(const string& plane,
// Be careful: src may have more components than dst (eg dst is RGB, src is RGBA).
// In this case, only copy the first components (thus the std::min)

assert( ( /*dstPixelComponentStartIndex=*/ 0 + /*desiredSrcNComps=*/ std::min(srcMappedComponentsCount, dstMappedComponentsCount) ) <= /*dstPixelComponentCount=*/ dstMappedComponentsCount );
assert( ( /*dstPixelComponentStartIndex=*/ 0 + /*desiredSrcNComps=*/ (std::min)(srcMappedComponentsCount, dstMappedComponentsCount) ) <= /*dstPixelComponentCount=*/ dstMappedComponentsCount );
interleavePixelBuffers(renderWindowClipped,
srcPixelData,
*bounds,
pixelComponents,
srcMappedComponentsCount,
0, // srcNCompsStartIndex
std::min(srcMappedComponentsCount, dstMappedComponentsCount), // desiredSrcNComps
(std::min)(srcMappedComponentsCount, dstMappedComponentsCount), // desiredSrcNComps
bitDepth,
srcRowBytes,
dstBounds,
Expand Down
8 changes: 4 additions & 4 deletions IOSupport/IOUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ intersect(const OfxRectI& r1,
return false;
}

intersection->x1 = std::max(r1.x1, r2.x1);
intersection->x2 = std::min(r1.x2, r2.x2);
intersection->y1 = std::max(r1.y1, r2.y1);
intersection->y2 = std::min(r1.y2, r2.y2);
intersection->x1 = (std::max)(r1.x1, r2.x1);
intersection->x2 = (std::min)(r1.x2, r2.x2);
intersection->y1 = (std::max)(r1.y1, r2.y1);
intersection->y2 = (std::min)(r1.y2, r2.y2);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion OCIO/OCIODisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ OCIODisplayPlugin::getProcessor(OfxTime time)

// Specify an (optional) post-display transform.
{
float exponent = 1.0f / std::max(1e-6f, (float)gamma);
float exponent = 1.0f / (std::max)(1e-6f, (float)gamma);
const float exponent4f[] = { exponent, exponent, exponent, exponent };
OCIO::ExponentTransformRcPtr cc = OCIO::ExponentTransform::Create();
cc->setValue(exponent4f);
Expand Down
12 changes: 6 additions & 6 deletions OIIO/OIIOResize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ OIIOResizePlugin::renderInternal(const RenderArguments & /*args*/,
}
}
// older versions of OIIO 1.2 don't have ImageBufAlgo::resize(dstBuf, srcBuf, fd.name, fd.width)
float w = fd.width * std::max(1.0f, wratio);
float h = fd.width * std::max(1.0f, hratio);
float w = fd.width * (std::max)(1.0f, wratio);
float h = fd.width * (std::max)(1.0f, hratio);
auto_ptr<Filter2D> filter( Filter2D::create(fd.name, w, h) );

if ( !ImageBufAlgo::resize( dstBuf, srcBuf, filter.get(), ROI::All(), MultiThread::getNumCPUs() ) ) {
Expand Down Expand Up @@ -725,10 +725,10 @@ OIIOResizePlugin::getRegionOfDefinition(const RegionOfDefinitionArguments &args,
srcRoD.y1 *= sy;
srcRoD.x2 *= sx;
srcRoD.y2 *= sy;
rod.x1 = std::min(srcRoD.x1, srcRoD.x2 - 1);
rod.x2 = std::max(srcRoD.x1 + 1, srcRoD.x2);
rod.y1 = std::min(srcRoD.y1, srcRoD.y2 - 1);
rod.y2 = std::max(srcRoD.y1 + 1, srcRoD.y2);
rod.x1 = (std::min)(srcRoD.x1, srcRoD.x2 - 1);
rod.x2 = (std::max)(srcRoD.x1 + 1, srcRoD.x2);
rod.y1 = (std::min)(srcRoD.y1, srcRoD.y2 - 1);
rod.y2 = (std::max)(srcRoD.y1 + 1, srcRoD.y2);
break;
}
} // switch
Expand Down
26 changes: 13 additions & 13 deletions OIIO/ReadOIIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ ReadOIIOPlugin::getConfig(ImageSpec* config) const
config->attribute("raw:HighlightMode", (int)rawHighlightMode);
} else {
// rebuild level, from 0 to 7
int rawHighlightRebuildLevel = std::max( 0,std::min(_rawHighlightRebuildLevel->getValue(), 7) );
int rawHighlightRebuildLevel = (std::max)( 0,(std::min)(_rawHighlightRebuildLevel->getValue(), 7) );
config->attribute("raw:HighlightMode", (int)rawHighlightMode + rawHighlightRebuildLevel);
}
}
Expand Down Expand Up @@ -2328,10 +2328,10 @@ ReadOIIOPlugin::decodePlane(const string& filename,
// Where to write the data in the buffer, everything outside of that is black
// It depends on the extra padding we added in getFrameBounds
OfxRectI renderWindowUnPadded;
renderWindowUnPadded.x1 = std::max(renderWindow.x1, specBounds.x1);
renderWindowUnPadded.y1 = std::max(renderWindow.y1, specBounds.y1);
renderWindowUnPadded.x2 = std::min(renderWindow.x2, specBounds.x2);
renderWindowUnPadded.y2 = std::min(renderWindow.y2, specBounds.y2);
renderWindowUnPadded.x1 = (std::max)(renderWindow.x1, specBounds.x1);
renderWindowUnPadded.y1 = (std::max)(renderWindow.y1, specBounds.y1);
renderWindowUnPadded.x2 = (std::min)(renderWindow.x2, specBounds.x2);
renderWindowUnPadded.y2 = (std::min)(renderWindow.y2, specBounds.y2);

// The renderWindowUnPadded must be contained in the original render Window
assert(renderWindowUnPadded.x1 >= renderWindow.x1 && renderWindowUnPadded.x2 <= renderWindow.x2 &&
Expand Down Expand Up @@ -2483,10 +2483,10 @@ ReadOIIOPlugin::decodePlane(const string& filename,
assert( kSupportsTiles || (!kSupportsTiles && (renderWindow.x2 - renderWindow.x1) == spec.width && (renderWindow.y2 - renderWindow.y1) == spec.height) );

// We clamp to the valid scanlines portion.
int ybeginClamped = std::min(std::max(spec.y, ybegin), spec.y + spec.height);
int yendClamped = std::min(std::max(spec.y, yend), spec.y + spec.height);
int xbeginClamped = std::min(std::max(spec.x, xbegin), spec.x + spec.width);
int xendClamped = std::min(std::max(spec.x, xend), spec.x + spec.width);
int ybeginClamped = (std::min)((std::max)(spec.y, ybegin), spec.y + spec.height);
int yendClamped = (std::min)((std::max)(spec.y, yend), spec.y + spec.height);
int xbeginClamped = (std::min)((std::max)(spec.x, xbegin), spec.x + spec.width);
int xendClamped = (std::min)((std::max)(spec.x, xend), spec.x + spec.width);

// Do not call valid_tile_range because a tiled file can only be read with read_tiles with OpenImageIO.
// Otherwise it will give the following error: called OpenEXRInput::read_native_scanlines without an open file
Expand Down Expand Up @@ -2539,10 +2539,10 @@ ReadOIIOPlugin::decodePlane(const string& filename,
// tiledYEnd must be at a valid multiple of tile_height from spec.y
tiledYEnd = spec.y + (int)std::ceil((double)(yendClamped - spec.y) / spec.tile_height ) * spec.tile_height;

tiledXBegin = std::max(spec.x, tiledXBegin);
tiledYBegin = std::max(spec.y, tiledYBegin);
tiledXEnd = std::min(spec.x + spec.width, tiledXEnd);
tiledYEnd = std::min(spec.y + spec.height, tiledYEnd);
tiledXBegin = (std::max)(spec.x, tiledXBegin);
tiledYBegin = (std::max)(spec.y, tiledYBegin);
tiledXEnd = (std::min)(spec.x + spec.width, tiledXEnd);
tiledYEnd = (std::min)(spec.y + spec.height, tiledYEnd);

// Check that we made up a correct tile range
assert( spec.valid_tile_range(tiledXBegin, tiledXEnd, tiledYBegin, tiledYEnd, zbegin, zend) );
Expand Down
16 changes: 8 additions & 8 deletions OIIO/WriteOIIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,20 +1113,20 @@ WriteOIIOPlugin::beginEncodeParts(void* user_data,
EParamTileSize tileSizeE = (EParamTileSize)tileSize_i;
switch (tileSizeE) {
case eParamTileSize64:
spec.tile_width = std::min(64, spec.full_width);
spec.tile_height = std::min(64, spec.full_height);
spec.tile_width = (std::min)(64, spec.full_width);
spec.tile_height = (std::min)(64, spec.full_height);
break;
case eParamTileSize128:
spec.tile_width = std::min(128, spec.full_width);
spec.tile_height = std::min(128, spec.full_height);
spec.tile_width = (std::min)(128, spec.full_width);
spec.tile_height = (std::min)(128, spec.full_height);
break;
case eParamTileSize256:
spec.tile_width = std::min(256, spec.full_width);
spec.tile_height = std::min(256, spec.full_height);
spec.tile_width = (std::min)(256, spec.full_width);
spec.tile_height = (std::min)(256, spec.full_height);
break;
case eParamTileSize512:
spec.tile_width = std::min(512, spec.full_width);
spec.tile_height = std::min(512, spec.full_height);
spec.tile_width = (std::min)(512, spec.full_width);
spec.tile_height = (std::min)(512, spec.full_height);
break;
case eParamTileSizeScanLineBased:
default:
Expand Down
4 changes: 2 additions & 2 deletions PFM/ReadPFM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ copyLine(PIX *image,
for (int x = x1; x < x2; ++x) {
if (srcC == 1) {
// alpha/grayscale image
for (int c = 0; c < std::min(dstC, 3); ++c) {
for (int c = 0; c < (std::min)(dstC, 3); ++c) {
dstPix[c] = srcPix[0];
}
} else {
// color image (if dstC == 1, only the red channel is extracted)
for (int c = 0; c < std::min(dstC, 3); ++c) {
for (int c = 0; c < (std::min)(dstC, 3); ++c) {
dstPix[c] = srcPix[c];
}
}
Expand Down
4 changes: 2 additions & 2 deletions PFM/WritePFM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ copyLine(const PIX* pixelData,
for (int x = 0; x < W; ++x) {
if (srcC == 1) {
// alpha/grayscale image
for (int c = 0; c < std::min(dstC, 3); ++c) {
for (int c = 0; c < (std::min)(dstC, 3); ++c) {
dstPix[c] = srcPix[dstNCompsStartIndex];
}
} else {
// color image (if dstC == 1, only the red channel is extracted)
for (int c = 0; c < std::min(dstC, 3); ++c) {
for (int c = 0; c < (std::min)(dstC, 3); ++c) {
dstPix[c] = srcPix[dstNCompsStartIndex + c];
}
}
Expand Down
4 changes: 2 additions & 2 deletions PNG/WritePNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ WritePNGPlugin::encode(const string& filename,
int compressionLevelParam;
_compressionLevel->getValue(compressionLevelParam);
assert(compressionLevelParam >= 0 && compressionLevelParam <= 9);
int compressionLevel = std::max(std::min(compressionLevelParam, Z_BEST_COMPRESSION), Z_NO_COMPRESSION);
int compressionLevel = (std::max)((std::min)(compressionLevelParam, Z_BEST_COMPRESSION), Z_NO_COMPRESSION);
png_set_compression_level(png, compressionLevel);

int compression_i;
Expand Down Expand Up @@ -762,7 +762,7 @@ WritePNGPlugin::encode(const string& filename,
std::size_t scratchBufBytes = (bounds.y2 - bounds.y1) * pngRowBytes;

RamBuffer scratchBuffer(scratchBufBytes);
int nComps = std::min(dstNComps, pixelDataNComps);
int nComps = (std::min)(dstNComps, pixelDataNComps);
const int srcRowElements = rowBytes / sizeof(float);
const size_t numPixels = (size_t)(bounds.x2 - bounds.x1) * (size_t)(bounds.y2 - bounds.y1);

Expand Down
Loading

0 comments on commit eeb975a

Please sign in to comment.