Skip to content

Commit 09ca1df

Browse files
committed
Fix compiler errors for unused check() result
Cleanup reserved macro and function names for llvm
1 parent c3fed26 commit 09ca1df

File tree

2 files changed

+39
-42
lines changed

2 files changed

+39
-42
lines changed

src/librawspeed/decompressors/CrxDecompressor.cpp

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,23 @@
3939
#include <initializer_list> // for initializer_list
4040

4141
// this should be divisible by 4
42-
#define CRX_BUF_SIZE 0x10000
42+
#define CRX_BUF_SIZE (uint64_t)0x10000
4343

44-
// Definitions copied from libraw
45-
#ifdef _abs
46-
#undef _abs
47-
#undef _min
48-
#undef _constrain
49-
#endif
50-
#define _abs(x) (((x) ^ ((int32_t)(x) >> 31)) - ((int32_t)(x) >> 31))
51-
#define _min(a, b) ((a) < (b) ? (a) : (b))
52-
#define _constrain(x, l, u) ((x) < (l) ? (l) : ((x) > (u) ? (u) : (x)))
44+
#define crx_constrain(x, l, u) ((x) < (l) ? (l) : ((x) > (u) ? (u) : (x)))
5345

5446
#if !defined(_WIN32) || \
5547
(defined(__GNUC__) && !defined(__INTRINSIC_SPECIAL__BitScanReverse))
5648
/* __INTRINSIC_SPECIAL__BitScanReverse found in MinGW32-W64 v7.30 headers, may
5749
* be there is a better solution? */
5850
typedef uint32_t DWORD;
59-
inline void _BitScanReverse(DWORD* Index, unsigned long Mask) {
51+
inline void crx_BitScanReverse(DWORD* Index, unsigned long Mask) {
6052
*Index = sizeof(unsigned long) * 8 - 1 - __builtin_clzl(Mask);
6153
}
54+
#else
55+
typedef uint32_t DWORD;
56+
inline void crx_BitScanReverse(DWORD* Index, unsigned long Mask) {
57+
_BitScanReverse(Index, Mask);
58+
}
6259
#endif
6360

6461
namespace rawspeed {
@@ -217,7 +214,7 @@ static inline void crxFillBuffer(CrxBitstream* bitStrm) {
217214
auto sub = bitStrm->crxRawData.getSubView(bitStrm->curBufOffset);
218215

219216
bitStrm->mdatBuf.resize(CRX_BUF_SIZE);
220-
auto bytesToRead = _min(bitStrm->mdatSize, CRX_BUF_SIZE);
217+
auto bytesToRead = std::min(bitStrm->mdatSize, CRX_BUF_SIZE);
221218

222219
if (sub.getSize() >= bytesToRead) {
223220
auto data = sub.getData(0, bytesToRead);
@@ -238,7 +235,7 @@ inline int crxBitstreamGetZeros(CrxBitstream* bitStrm) {
238235
int32_t result = 0;
239236

240237
if (bitStrm->bitData) {
241-
_BitScanReverse(static_cast<DWORD*>(&nonZeroBit), static_cast<DWORD>(bitStrm->bitData));
238+
crx_BitScanReverse(static_cast<DWORD*>(&nonZeroBit), static_cast<DWORD>(bitStrm->bitData));
242239
result = 31 - nonZeroBit;
243240
bitStrm->bitData <<= 32 - nonZeroBit;
244241
bitStrm->bitsLeft -= 32 - nonZeroBit;
@@ -251,7 +248,7 @@ inline int crxBitstreamGetZeros(CrxBitstream* bitStrm) {
251248
bitStrm->curPos += 4;
252249
crxFillBuffer(bitStrm);
253250
if (nextData) {
254-
_BitScanReverse(static_cast<DWORD*>(&nonZeroBit), static_cast<DWORD>(nextData));
251+
crx_BitScanReverse(static_cast<DWORD*>(&nonZeroBit), static_cast<DWORD>(nextData));
255252
result = bitsLeft + 31 - nonZeroBit;
256253
bitStrm->bitData = nextData << (32 - nonZeroBit);
257254
bitStrm->bitsLeft = nonZeroBit;
@@ -267,7 +264,7 @@ inline int crxBitstreamGetZeros(CrxBitstream* bitStrm) {
267264
break;
268265
bitsLeft += 8;
269266
}
270-
_BitScanReverse(static_cast<DWORD*>(&nonZeroBit), static_cast<DWORD>(nextData));
267+
crx_BitScanReverse(static_cast<DWORD*>(&nonZeroBit), static_cast<DWORD>(nextData));
271268
result = static_cast<uint32_t>(bitsLeft + 7 - nonZeroBit);
272269
bitStrm->bitData = nextData << (32 - nonZeroBit);
273270
bitStrm->bitsLeft = nonZeroBit;
@@ -356,7 +353,7 @@ inline void crxDecodeSymbolL1(CrxBandParam* param, int32_t doMedianPrediction,
356353
// for not end of the line - use one symbol ahead to estimate next K
357354
if (notEOL) {
358355
int32_t nextDelta = (param->lineBuf0[2] - param->lineBuf0[1]) << 1;
359-
bitCode = (bitCode + _abs(nextDelta)) >> 1;
356+
bitCode = (bitCode + std::abs(nextDelta)) >> 1;
360357
++param->lineBuf0;
361358
}
362359

@@ -461,7 +458,7 @@ inline void crxDecodeSymbolL1Rounded(CrxBandParam* param, int32_t doSym = 1,
461458
}
462459

463460
param->kParam = crxPredictKParameter(param->kParam,
464-
(bitCode + 2 * _abs(code)) >> 1, 15);
461+
(bitCode + 2 * std::abs(code)) >> 1, 15);
465462
} else
466463
param->kParam = crxPredictKParameter(param->kParam, bitCode, 15);
467464

@@ -476,12 +473,12 @@ static int crxDecodeLineRounded(CrxBandParam* param) {
476473
int32_t length = param->subbandWidth;
477474

478475
for (; length > 1; --length) {
479-
if (_abs(param->lineBuf0[2] - param->lineBuf0[1]) >
476+
if (std::abs(param->lineBuf0[2] - param->lineBuf0[1]) >
480477
param->roundedBitsMask) {
481478
crxDecodeSymbolL1Rounded(param);
482479
++param->lineBuf0;
483480
valueReached = 1;
484-
} else if (valueReached || _abs(param->lineBuf0[0] - param->lineBuf1[0]) >
481+
} else if (valueReached || std::abs(param->lineBuf0[0] - param->lineBuf1[0]) >
485482
param->roundedBitsMask) {
486483
crxDecodeSymbolL1Rounded(param);
487484
++param->lineBuf0;
@@ -524,7 +521,7 @@ static int crxDecodeLineRounded(CrxBandParam* param) {
524521
if (length > 1) {
525522
crxDecodeSymbolL1Rounded(param, 0);
526523
++param->lineBuf0;
527-
valueReached = _abs(param->lineBuf0[1] - param->lineBuf0[0]) >
524+
valueReached = std::abs(param->lineBuf0[1] - param->lineBuf0[0]) >
528525
param->roundedBitsMask;
529526
} else if (length == 1)
530527
crxDecodeSymbolL1Rounded(param, 0, 0);
@@ -720,7 +717,7 @@ static int crxDecodeTopLineRounded(CrxBandParam* param) {
720717

721718
// read the line from bitstream
722719
for (; length > 1; --length) {
723-
if (_abs(param->lineBuf1[0]) > param->roundedBitsMask)
720+
if (std::abs(param->lineBuf1[0]) > param->roundedBitsMask)
724721
param->lineBuf1[1] = param->lineBuf1[0];
725722
else {
726723
int nSyms = 0;
@@ -1016,7 +1013,7 @@ static int crxDecodeLineWithIQuantization(CrxSubband* band, CrxQStep* qStep) {
10161013
for (int i = 0; i < band->colStartAddOn; ++i) {
10171014
uint32_t quantVal =
10181015
band->qStepBase + ((qStepTblPtr[0] * band->qStepMult) >> 3);
1019-
bandBuf[i] *= _constrain(quantVal, 1, 0x168000);
1016+
bandBuf[i] *= crx_constrain(quantVal, 1, 0x168000);
10201017
}
10211018

10221019
for (int i = band->colStartAddOn; i < band->width - band->colEndAddOn;
@@ -1026,14 +1023,14 @@ static int crxDecodeLineWithIQuantization(CrxSubband* band, CrxQStep* qStep) {
10261023
((qStepTblPtr[(i - band->colStartAddOn) >> band->levelShift] *
10271024
band->qStepMult) >>
10281025
3);
1029-
bandBuf[i] *= _constrain(quantVal, 1, 0x168000);
1026+
bandBuf[i] *= crx_constrain(quantVal, 1, 0x168000);
10301027
}
10311028
int lastIdx = (band->width - band->colEndAddOn - band->colStartAddOn - 1) >>
10321029
band->levelShift;
10331030
for (int i = band->width - band->colEndAddOn; i < band->width; ++i) {
10341031
uint32_t quantVal =
10351032
band->qStepBase + ((qStepTblPtr[lastIdx] * band->qStepMult) >> 3);
1036-
bandBuf[i] *= _constrain(quantVal, 1, 0x168000);
1033+
bandBuf[i] *= crx_constrain(quantVal, 1, 0x168000);
10371034
}
10381035
} else {
10391036
// prev. version
@@ -1525,7 +1522,7 @@ static void crxConvertPlaneLine(CrxImage* img, int imageRow, int imageCol = 0,
15251522
--maxVal;
15261523
for (int i = 0; i < lineLength; i++)
15271524
img->outBufs[plane][rawOffset + 2 * i] =
1528-
_constrain(lineData[i], minVal, maxVal);
1525+
crx_constrain(lineData[i], minVal, maxVal);
15291526
} else if (img->encType == 3) {
15301527
// copy to intermediate planeBuf
15311528
rawOffset = plane * img->planeWidth * img->planeHeight +
@@ -1537,14 +1534,14 @@ static void crxConvertPlaneLine(CrxImage* img, int imageRow, int imageCol = 0,
15371534
int32_t maxVal = (1 << img->nBits) - 1;
15381535
for (int i = 0; i < lineLength; i++)
15391536
img->outBufs[plane][rawOffset + 2 * i] =
1540-
_constrain(median + lineData[i], 0, maxVal);
1537+
crx_constrain(median + lineData[i], 0, maxVal);
15411538
} else if (img->nPlanes == 1) {
15421539
int32_t maxVal = (1 << img->nBits) - 1;
15431540
int32_t median = 1 << (img->nBits - 1);
15441541
rawOffset = img->planeWidth * imageRow + imageCol;
15451542
for (int i = 0; i < lineLength; i++)
15461543
img->outBufs[0][rawOffset + i] =
1547-
_constrain(median + lineData[i], 0, maxVal);
1544+
crx_constrain(median + lineData[i], 0, maxVal);
15481545
}
15491546
} else if (img->encType == 3 && img->planeBuf) {
15501547
int32_t planeSize = img->planeWidth * img->planeHeight;
@@ -1563,22 +1560,22 @@ static void crxConvertPlaneLine(CrxImage* img, int imageRow, int imageCol = 0,
15631560
median + (plane0[i] << 10) - 168 * plane1[i] - 585 * plane3[i];
15641561
int32_t val = 0;
15651562
if (gr < 0)
1566-
gr = -(((_abs(gr) + 512) >> 9) & ~1);
1563+
gr = -(((std::abs(gr) + 512) >> 9) & ~1);
15671564
else
1568-
gr = ((_abs(gr) + 512) >> 9) & ~1;
1565+
gr = ((std::abs(gr) + 512) >> 9) & ~1;
15691566

15701567
// Essentially R = round(median + P0 + 1.474*P3)
15711568
val = (median + (plane0[i] << 10) + 1510 * plane3[i] + 512) >> 10;
1572-
img->outBufs[0][rawLineOffset + 2 * i] = _constrain(val, 0, maxVal);
1569+
img->outBufs[0][rawLineOffset + 2 * i] = crx_constrain(val, 0, maxVal);
15731570
// Essentially G1 = round(median + P0 + P2 - 0.164*P1 - 0.571*P3)
15741571
val = (plane2[i] + gr + 1) >> 1;
1575-
img->outBufs[1][rawLineOffset + 2 * i] = _constrain(val, 0, maxVal);
1572+
img->outBufs[1][rawLineOffset + 2 * i] = crx_constrain(val, 0, maxVal);
15761573
// Essentially G2 = round(median + P0 - P2 - 0.164*P1 - 0.571*P3)
15771574
val = (gr - plane2[i] + 1) >> 1;
1578-
img->outBufs[2][rawLineOffset + 2 * i] = _constrain(val, 0, maxVal);
1575+
img->outBufs[2][rawLineOffset + 2 * i] = crx_constrain(val, 0, maxVal);
15791576
// Essentially B = round(median + P0 + 1.881*P1)
15801577
val = (median + (plane0[i] << 10) + 1927 * plane1[i] + 512) >> 10;
1581-
img->outBufs[3][rawLineOffset + 2 * i] = _constrain(val, 0, maxVal);
1578+
img->outBufs[3][rawLineOffset + 2 * i] = crx_constrain(val, 0, maxVal);
15821579
}
15831580
}
15841581
}
@@ -1832,7 +1829,7 @@ static void crxDecodeGolombNormal(CrxBitstream* bitStrm, int32_t width,
18321829
lineBuf1[1] += -(qp & 1) ^ (qp >> 1);
18331830
if (width) {
18341831
deltaH = lineBuf0[2] - lineBuf0[1];
1835-
*kParam = crxPredictKParameter(*kParam, (qp + 2 * _abs(deltaH)) >> 1, 7);
1832+
*kParam = crxPredictKParameter(*kParam, (qp + 2 * std::abs(deltaH)) >> 1, 7);
18361833
++lineBuf0;
18371834
} else
18381835
*kParam = crxPredictKParameter(*kParam, qp, 7);
@@ -1871,10 +1868,10 @@ static int crxMakeQStep(CrxImage* img, CrxTile* tile, int32_t* qpTable,
18711868
qStep->width = qpWidth;
18721869
qStep->height = qpHeight8;
18731870
for (int qpRow = 0; qpRow < qpHeight8; ++qpRow) {
1874-
int row0Idx = qpWidth * _min(4 * qpRow, qpHeight - 1);
1875-
int row1Idx = qpWidth * _min(4 * qpRow + 1, qpHeight - 1);
1876-
int row2Idx = qpWidth * _min(4 * qpRow + 2, qpHeight - 1);
1877-
int row3Idx = qpWidth * _min(4 * qpRow + 3, qpHeight - 1);
1871+
int row0Idx = qpWidth * std::min(4 * qpRow, qpHeight - 1);
1872+
int row1Idx = qpWidth * std::min(4 * qpRow + 1, qpHeight - 1);
1873+
int row2Idx = qpWidth * std::min(4 * qpRow + 2, qpHeight - 1);
1874+
int row3Idx = qpWidth * std::min(4 * qpRow + 3, qpHeight - 1);
18781875

18791876
for (int qpCol = 0; qpCol < qpWidth; ++qpCol, ++qStepTbl) {
18801877
int32_t quantVal = qpTable[row0Idx++] + qpTable[row1Idx++] +
@@ -1897,8 +1894,8 @@ static int crxMakeQStep(CrxImage* img, CrxTile* tile, int32_t* qpTable,
18971894
qStep->width = qpWidth;
18981895
qStep->height = qpHeight4;
18991896
for (int qpRow = 0; qpRow < qpHeight4; ++qpRow) {
1900-
int row0Idx = qpWidth * _min(2 * qpRow, qpHeight - 1);
1901-
int row1Idx = qpWidth * _min(2 * qpRow + 1, qpHeight - 1);
1897+
int row0Idx = qpWidth * std::min(2 * qpRow, qpHeight - 1);
1898+
int row1Idx = qpWidth * std::min(2 * qpRow + 1, qpHeight - 1);
19021899

19031900
for (int qpCol = 0; qpCol < qpWidth; ++qpCol, ++qStepTbl) {
19041901
int32_t quantVal = (qpTable[row0Idx++] + qpTable[row1Idx++]) / 2;

src/librawspeed/tiff/IsoMBox.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ IsoMSampleToChunkBox::IsoMSampleToChunkBox(const AbstractIsoMBox& base)
217217
: IsoMFullBox(base) {
218218
const auto entryCount = data.getU32();
219219

220-
data.check(entryCount, 3 * 4);
220+
(void)data.check(entryCount, 3 * 4);
221221
dscs.reserve(entryCount);
222222
std::generate_n(std::back_inserter(dscs), entryCount, [this]() {
223223
Dsc d;
@@ -278,7 +278,7 @@ IsoMChunkLargeOffsetBox::operator bool() const {
278278
IsoMChunkLargeOffsetBox::IsoMChunkLargeOffsetBox(const AbstractIsoMBox& base)
279279
: IsoMFullBox(base) {
280280
const auto entryCount = data.getU32();
281-
data.check(entryCount, 8);
281+
(void)data.check(entryCount, 8);
282282

283283
if (entryCount != 1)
284284
ThrowIPE("Don't know how to handle co64 box with %u entries", entryCount);

0 commit comments

Comments
 (0)