diff options
author | Lei Zhang <thestig@chromium.org> | 2016-01-11 11:59:17 -0800 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2016-01-11 11:59:17 -0800 |
commit | 375a86403b7fa8d17d7b142c270e2d8e33bb924f (patch) | |
tree | 1db1ffddb2bbbcd429cd1d7954b1949bfa54e1ab /xfa/src/fxbarcode | |
parent | 492961df3011ccc25646eae12ac6e6dcfe7f26da (diff) | |
download | pdfium-375a86403b7fa8d17d7b142c270e2d8e33bb924f.tar.xz |
Merge to XFA: Switch most min/max macros to std::min/max.
Fix lint errors along the way.
R=tsepez@chromium.org
TBR=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1567343002 .
(cherry picked from commit 9adfbb0920a258e916003b1ee9515e97879db82a)
Review URL: https://codereview.chromium.org/1577503002 .
Diffstat (limited to 'xfa/src/fxbarcode')
-rw-r--r-- | xfa/src/fxbarcode/BC_TwoDimWriter.cpp | 34 | ||||
-rw-r--r-- | xfa/src/fxbarcode/common/BC_CommonByteArray.cpp | 4 | ||||
-rw-r--r-- | xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp | 16 | ||||
-rw-r--r-- | xfa/src/fxbarcode/oned/BC_OneDReader.cpp | 4 | ||||
-rw-r--r-- | xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp | 6 | ||||
-rw-r--r-- | xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp | 4 | ||||
-rw-r--r-- | xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp | 8 | ||||
-rw-r--r-- | xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp | 4 | ||||
-rw-r--r-- | xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.cpp | 6 | ||||
-rw-r--r-- | xfa/src/fxbarcode/qrcode/BC_QRDetector.cpp | 10 |
10 files changed, 59 insertions, 37 deletions
diff --git a/xfa/src/fxbarcode/BC_TwoDimWriter.cpp b/xfa/src/fxbarcode/BC_TwoDimWriter.cpp index d6d6614449..b270378a87 100644 --- a/xfa/src/fxbarcode/BC_TwoDimWriter.cpp +++ b/xfa/src/fxbarcode/BC_TwoDimWriter.cpp @@ -4,10 +4,14 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <algorithm>
+
+#include "third_party/base/numerics/safe_math.h"
#include "xfa/src/fxbarcode/barcode.h"
#include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h"
#include "xfa/src/fxbarcode/BC_Writer.h"
#include "xfa/src/fxbarcode/BC_TwoDimWriter.h"
+
CBC_TwoDimWriter::CBC_TwoDimWriter() {
m_iCorrectLevel = 1;
m_bFixedSize = TRUE;
@@ -92,18 +96,18 @@ void CBC_TwoDimWriter::RenderResult(uint8_t* code, int32_t& e) {
int32_t inputWidth = codeWidth;
int32_t inputHeight = codeHeight;
- int32_t tempWidth = inputWidth + (1 << 1);
- int32_t tempHeight = inputHeight + (1 << 1);
- FX_FLOAT moduleHSize = (FX_FLOAT)FX_MIN(m_ModuleWidth, m_ModuleHeight);
- if (moduleHSize > 8) {
- moduleHSize = 8;
- } else if (moduleHSize < 1) {
- moduleHSize = 1;
- }
- int32_t outputWidth = (int32_t)FX_MAX(tempWidth * moduleHSize, tempWidth);
- int32_t outputHeight = (int32_t)FX_MAX(tempHeight * moduleHSize, tempHeight);
- int32_t multiX = 1;
- int32_t multiY = 1;
+ int32_t tempWidth = inputWidth + 2;
+ int32_t tempHeight = inputHeight + 2;
+ FX_FLOAT moduleHSize = std::min(m_ModuleWidth, m_ModuleHeight);
+ moduleHSize = std::min(moduleHSize, 8.0f);
+ moduleHSize = std::max(moduleHSize, 1.0f);
+ pdfium::base::CheckedNumeric<int32_t> scaledWidth = tempWidth;
+ pdfium::base::CheckedNumeric<int32_t> scaledHeight = tempHeight;
+ scaledWidth *= moduleHSize;
+ scaledHeight *= moduleHSize;
+
+ int32_t outputWidth = scaledWidth.ValueOrDie();
+ int32_t outputHeight = scaledHeight.ValueOrDie();
if (m_bFixedSize) {
if (m_Width < outputWidth || m_Height < outputHeight) {
e = BCExceptionBitmapSizeError;
@@ -117,10 +121,10 @@ void CBC_TwoDimWriter::RenderResult(uint8_t* code, outputHeight * ceil((FX_FLOAT)m_Height / (FX_FLOAT)outputHeight));
}
}
- multiX = (int32_t)ceil((FX_FLOAT)outputWidth / (FX_FLOAT)tempWidth);
- multiY = (int32_t)ceil((FX_FLOAT)outputHeight / (FX_FLOAT)tempHeight);
+ int32_t multiX = (int32_t)ceil((FX_FLOAT)outputWidth / (FX_FLOAT)tempWidth);
+ int32_t multiY = (int32_t)ceil((FX_FLOAT)outputHeight / (FX_FLOAT)tempHeight);
if (m_bFixedSize) {
- multiX = FX_MIN(multiX, multiY);
+ multiX = std::min(multiX, multiY);
multiY = multiX;
}
int32_t leftPadding = (outputWidth - (inputWidth * multiX)) / 2;
diff --git a/xfa/src/fxbarcode/common/BC_CommonByteArray.cpp b/xfa/src/fxbarcode/common/BC_CommonByteArray.cpp index 967a1849d5..c36ff34a6d 100644 --- a/xfa/src/fxbarcode/common/BC_CommonByteArray.cpp +++ b/xfa/src/fxbarcode/common/BC_CommonByteArray.cpp @@ -20,6 +20,8 @@ * limitations under the License.
*/
+#include <algorithm>
+
#include "xfa/src/fxbarcode/barcode.h"
#include "BC_CommonByteArray.h"
CBC_CommonByteArray::CBC_CommonByteArray() {
@@ -61,7 +63,7 @@ FX_BOOL CBC_CommonByteArray::IsEmpty() { }
void CBC_CommonByteArray::AppendByte(int32_t value) {
if (m_size == 0 || m_index >= m_size) {
- int32_t newSize = FX_MAX(32, m_size << 1);
+ int32_t newSize = std::max(32, m_size << 1);
Reserve(newSize);
}
m_bytes[m_index] = (uint8_t)value;
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp index c930f0e45d..27c29afe77 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp @@ -20,6 +20,8 @@ * limitations under the License.
*/
+#include <algorithm>
+
#include "xfa/src/fxbarcode/barcode.h"
#include "xfa/src/fxbarcode/BC_ResultPoint.h"
#include "xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.h"
@@ -166,7 +168,7 @@ CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) { correctedTopRight.get(), dimensionTop, dimensionRight, e));
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
} else {
- int32_t dimension = FX_MIN(dimensionRight, dimensionTop);
+ int32_t dimension = std::min(dimensionRight, dimensionTop);
correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(
CorrectTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension));
if (correctedTopRight.get() == NULL) {
@@ -176,12 +178,12 @@ CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) { topRight = NULL;
}
int32_t dimensionCorrected =
- FX_MAX(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
- TransitionsBetween(topLeft, correctedTopRight.get()))
- ->GetTransitions(),
- CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
- TransitionsBetween(bottomRight, correctedTopRight.get()))
- ->GetTransitions());
+ std::max(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(topLeft, correctedTopRight.get()))
+ ->GetTransitions(),
+ CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(bottomRight, correctedTopRight.get()))
+ ->GetTransitions());
dimensionCorrected++;
if ((dimensionCorrected & 0x01) == 1) {
dimensionCorrected++;
diff --git a/xfa/src/fxbarcode/oned/BC_OneDReader.cpp b/xfa/src/fxbarcode/oned/BC_OneDReader.cpp index 61448d21e7..b89f76423e 100644 --- a/xfa/src/fxbarcode/oned/BC_OneDReader.cpp +++ b/xfa/src/fxbarcode/oned/BC_OneDReader.cpp @@ -20,6 +20,8 @@ * limitations under the License.
*/
+#include <algorithm>
+
#include "xfa/src/fxbarcode/barcode.h"
#include "xfa/src/fxbarcode/BC_Reader.h"
#include "xfa/src/fxbarcode/BC_BinaryBitmap.h"
@@ -48,7 +50,7 @@ CFX_ByteString CBC_OneDReader::DeDecode(CBC_BinaryBitmap* image, CBC_CommonBitArray* row = NULL;
int32_t middle = height >> 1;
FX_BOOL tryHarder = FALSE;
- int32_t rowStep = FX_MAX(1, height >> (tryHarder ? 8 : 5));
+ int32_t rowStep = std::max(1, height >> (tryHarder ? 8 : 5));
int32_t maxLines;
if (tryHarder) {
maxLines = height;
diff --git a/xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp b/xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp index 8f4b226e8c..159f27f826 100644 --- a/xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp +++ b/xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp @@ -22,6 +22,7 @@ #include "BC_OneDimWriter.h"
+#include <algorithm>
#include <memory>
#include "xfa/src/fxbarcode/BC_Writer.h"
@@ -391,7 +392,8 @@ void CBC_OneDimWriter::RenderResult(const CFX_WideStringC& contents, m_outputHScale = (FX_FLOAT)m_Width / (FX_FLOAT)codeLength;
}
if (!isDevice) {
- m_outputHScale = FX_MAX(m_outputHScale, m_ModuleWidth);
+ m_outputHScale =
+ std::max(m_outputHScale, static_cast<FX_FLOAT>(m_ModuleWidth));
}
FX_FLOAT dataLengthScale = 1.0;
if (m_iDataLenth > 0 && contents.GetLength() != 0) {
@@ -407,7 +409,7 @@ void CBC_OneDimWriter::RenderResult(const CFX_WideStringC& contents, int32_t outputHeight = 1;
if (!isDevice) {
if (m_Height == 0) {
- outputHeight = FX_MAX(20, m_ModuleHeight);
+ outputHeight = std::max(20, m_ModuleHeight);
} else {
outputHeight = m_Height;
}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp b/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp index a2177fd699..c75ddd48ee 100644 --- a/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp +++ b/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp @@ -20,6 +20,8 @@ * limitations under the License.
*/
+#include <algorithm>
+
#include "xfa/src/fxbarcode/barcode.h"
#include "xfa/src/fxbarcode/BC_Reader.h"
#include "xfa/src/fxbarcode/common/BC_CommonBitArray.h"
@@ -140,7 +142,7 @@ CFX_Int32Array* CBC_OnedCodaBarReader::FindAsteriskPattern( if (counterPosition == patternLength - 1) {
if (ArrayContains(STARTEND_ENCODING, ToNarrowWidePattern(&counters))) {
FX_BOOL btemp3 =
- row->IsRange(FX_MAX(0, patternStart - (i - patternStart) / 2),
+ row->IsRange(std::max(0, patternStart - (i - patternStart) / 2),
patternStart, FALSE, e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
if (btemp3) {
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp b/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp index 601baa2a4c..cbc7a5a859 100644 --- a/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp +++ b/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp @@ -20,6 +20,8 @@ * limitations under the License.
*/
+#include <algorithm>
+
#include "xfa/src/fxbarcode/barcode.h"
#include "xfa/src/fxbarcode/BC_Reader.h"
#include "xfa/src/fxbarcode/common/BC_CommonBitArray.h"
@@ -115,7 +117,7 @@ CFX_Int32Array* CBC_OnedCode128Reader::FindStartPattern(CBC_CommonBitArray* row, }
if (bestMatch >= 0) {
FX_BOOL btemp2 =
- row->IsRange(FX_MAX(0, patternStart - (i - patternStart) / 2),
+ row->IsRange(std::max(0, patternStart - (i - patternStart) / 2),
patternStart, FALSE, e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
if (btemp2) {
@@ -338,8 +340,8 @@ CFX_ByteString CBC_OnedCode128Reader::DecodeRow(int32_t rowNumber, nextStart++;
}
FX_BOOL boolT1 = row->IsRange(
- nextStart, FX_MIN(width, nextStart + (nextStart - lastStart) / 2), FALSE,
- e);
+ nextStart, std::min(width, nextStart + (nextStart - lastStart) / 2),
+ FALSE, e);
BC_EXCEPTION_CHECK_ReturnValue(e, "");
if (!boolT1) {
e = BCExceptionNotFound;
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp b/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp index a5b77ed13f..18d1e96494 100644 --- a/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp +++ b/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp @@ -20,6 +20,8 @@ * limitations under the License.
*/
+#include <algorithm>
+
#include "xfa/src/fxbarcode/barcode.h"
#include "xfa/src/fxbarcode/BC_Reader.h"
#include "xfa/src/fxbarcode/common/BC_CommonBitArray.h"
@@ -144,7 +146,7 @@ CFX_Int32Array* CBC_OnedCode39Reader::FindAsteriskPattern( if (counterPosition == patternLength - 1) {
if (ToNarrowWidePattern(&counters) == ASTERISK_ENCODING) {
FX_BOOL bT1 =
- row->IsRange(FX_MAX(0, patternStart - (i - patternStart) / 2),
+ row->IsRange(std::max(0, patternStart - (i - patternStart) / 2),
patternStart, FALSE, e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
if (bT1) {
diff --git a/xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.cpp index 2610db95dc..2e16c036ca 100644 --- a/xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.cpp +++ b/xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.cpp @@ -20,6 +20,8 @@ * limitations under the License.
*/
+#include <algorithm>
+
#include "xfa/src/fxbarcode/barcode.h"
#include "xfa/src/fxbarcode/BC_UtilCodingConvert.h"
#include "xfa/src/fxbarcode/common/BC_CommonByteArray.h"
@@ -876,8 +878,8 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, GenerateECBytes(dataBytes, numEcBytesInBlosk, e);
BC_EXCEPTION_CHECK_ReturnVoid(e);
blocks.Add(new CBC_QRCoderBlockPair(dataBytes, ecBytes));
- maxNumDataBytes = FX_MAX(maxNumDataBytes, dataBytes->Size());
- maxNumEcBytes = FX_MAX(maxNumEcBytes, ecBytes->Size());
+ maxNumDataBytes = std::max(maxNumDataBytes, dataBytes->Size());
+ maxNumEcBytes = std::max(maxNumEcBytes, ecBytes->Size());
dataBytesOffset += numDataBytesInBlock;
}
if (numDataBytes != dataBytesOffset) {
diff --git a/xfa/src/fxbarcode/qrcode/BC_QRDetector.cpp b/xfa/src/fxbarcode/qrcode/BC_QRDetector.cpp index 1b799114b4..2280e9a4b8 100644 --- a/xfa/src/fxbarcode/qrcode/BC_QRDetector.cpp +++ b/xfa/src/fxbarcode/qrcode/BC_QRDetector.cpp @@ -20,6 +20,8 @@ * limitations under the License.
*/
+#include <algorithm>
+
#include "xfa/src/fxbarcode/barcode.h"
#include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h"
#include "xfa/src/fxbarcode/BC_ResultPoint.h"
@@ -255,16 +257,16 @@ CBC_QRAlignmentPattern* CBC_QRDetector::FindAlignmentInRegion( FX_FLOAT allowanceFactor,
int32_t& e) {
int32_t allowance = (int32_t)(allowanceFactor * overallEstModuleSize);
- int32_t alignmentAreaLeftX = FX_MAX(0, estAlignmentX - allowance);
+ int32_t alignmentAreaLeftX = std::max(0, estAlignmentX - allowance);
int32_t alignmentAreaRightX =
- FX_MIN(m_image->GetWidth() - 1, estAlignmentX + allowance);
+ std::min(m_image->GetWidth() - 1, estAlignmentX + allowance);
if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) {
e = BCExceptionRead;
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
}
- int32_t alignmentAreaTopY = FX_MAX(0, estAlignmentY - allowance);
+ int32_t alignmentAreaTopY = std::max(0, estAlignmentY - allowance);
int32_t alignmentAreaBottomY =
- FX_MIN(m_image->GetHeight() - 1, estAlignmentY + allowance);
+ std::min(m_image->GetHeight() - 1, estAlignmentY + allowance);
CBC_QRAlignmentPatternFinder alignmentFinder(
m_image, alignmentAreaLeftX, alignmentAreaTopY,
alignmentAreaRightX - alignmentAreaLeftX,
|