OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "third_party/base/numerics/safe_math.h" |
7 #include "xfa/src/fxbarcode/barcode.h" | 10 #include "xfa/src/fxbarcode/barcode.h" |
8 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h" | 11 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h" |
9 #include "xfa/src/fxbarcode/BC_Writer.h" | 12 #include "xfa/src/fxbarcode/BC_Writer.h" |
10 #include "xfa/src/fxbarcode/BC_TwoDimWriter.h" | 13 #include "xfa/src/fxbarcode/BC_TwoDimWriter.h" |
| 14 |
11 CBC_TwoDimWriter::CBC_TwoDimWriter() { | 15 CBC_TwoDimWriter::CBC_TwoDimWriter() { |
12 m_iCorrectLevel = 1; | 16 m_iCorrectLevel = 1; |
13 m_bFixedSize = TRUE; | 17 m_bFixedSize = TRUE; |
14 m_output = NULL; | 18 m_output = NULL; |
15 } | 19 } |
16 CBC_TwoDimWriter::~CBC_TwoDimWriter() { | 20 CBC_TwoDimWriter::~CBC_TwoDimWriter() { |
17 if (m_output != NULL) { | 21 if (m_output != NULL) { |
18 delete m_output; | 22 delete m_output; |
19 m_output = NULL; | 23 m_output = NULL; |
20 } | 24 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 89 } |
86 pOutBitmap = pStretchBitmap; | 90 pOutBitmap = pStretchBitmap; |
87 } | 91 } |
88 } | 92 } |
89 void CBC_TwoDimWriter::RenderResult(uint8_t* code, | 93 void CBC_TwoDimWriter::RenderResult(uint8_t* code, |
90 int32_t codeWidth, | 94 int32_t codeWidth, |
91 int32_t codeHeight, | 95 int32_t codeHeight, |
92 int32_t& e) { | 96 int32_t& e) { |
93 int32_t inputWidth = codeWidth; | 97 int32_t inputWidth = codeWidth; |
94 int32_t inputHeight = codeHeight; | 98 int32_t inputHeight = codeHeight; |
95 int32_t tempWidth = inputWidth + (1 << 1); | 99 int32_t tempWidth = inputWidth + 2; |
96 int32_t tempHeight = inputHeight + (1 << 1); | 100 int32_t tempHeight = inputHeight + 2; |
97 FX_FLOAT moduleHSize = (FX_FLOAT)FX_MIN(m_ModuleWidth, m_ModuleHeight); | 101 FX_FLOAT moduleHSize = std::min(m_ModuleWidth, m_ModuleHeight); |
98 if (moduleHSize > 8) { | 102 moduleHSize = std::min(moduleHSize, 8.0f); |
99 moduleHSize = 8; | 103 moduleHSize = std::max(moduleHSize, 1.0f); |
100 } else if (moduleHSize < 1) { | 104 pdfium::base::CheckedNumeric<int32_t> scaledWidth = tempWidth; |
101 moduleHSize = 1; | 105 pdfium::base::CheckedNumeric<int32_t> scaledHeight = tempHeight; |
102 } | 106 scaledWidth *= moduleHSize; |
103 int32_t outputWidth = (int32_t)FX_MAX(tempWidth * moduleHSize, tempWidth); | 107 scaledHeight *= moduleHSize; |
104 int32_t outputHeight = (int32_t)FX_MAX(tempHeight * moduleHSize, tempHeight); | 108 |
105 int32_t multiX = 1; | 109 int32_t outputWidth = scaledWidth.ValueOrDie(); |
106 int32_t multiY = 1; | 110 int32_t outputHeight = scaledHeight.ValueOrDie(); |
107 if (m_bFixedSize) { | 111 if (m_bFixedSize) { |
108 if (m_Width < outputWidth || m_Height < outputHeight) { | 112 if (m_Width < outputWidth || m_Height < outputHeight) { |
109 e = BCExceptionBitmapSizeError; | 113 e = BCExceptionBitmapSizeError; |
110 return; | 114 return; |
111 } | 115 } |
112 } else { | 116 } else { |
113 if (m_Width > outputWidth || m_Height > outputHeight) { | 117 if (m_Width > outputWidth || m_Height > outputHeight) { |
114 outputWidth = (int32_t)(outputWidth * | 118 outputWidth = (int32_t)(outputWidth * |
115 ceil((FX_FLOAT)m_Width / (FX_FLOAT)outputWidth)); | 119 ceil((FX_FLOAT)m_Width / (FX_FLOAT)outputWidth)); |
116 outputHeight = (int32_t)( | 120 outputHeight = (int32_t)( |
117 outputHeight * ceil((FX_FLOAT)m_Height / (FX_FLOAT)outputHeight)); | 121 outputHeight * ceil((FX_FLOAT)m_Height / (FX_FLOAT)outputHeight)); |
118 } | 122 } |
119 } | 123 } |
120 multiX = (int32_t)ceil((FX_FLOAT)outputWidth / (FX_FLOAT)tempWidth); | 124 int32_t multiX = (int32_t)ceil((FX_FLOAT)outputWidth / (FX_FLOAT)tempWidth); |
121 multiY = (int32_t)ceil((FX_FLOAT)outputHeight / (FX_FLOAT)tempHeight); | 125 int32_t multiY = (int32_t)ceil((FX_FLOAT)outputHeight / (FX_FLOAT)tempHeight); |
122 if (m_bFixedSize) { | 126 if (m_bFixedSize) { |
123 multiX = FX_MIN(multiX, multiY); | 127 multiX = std::min(multiX, multiY); |
124 multiY = multiX; | 128 multiY = multiX; |
125 } | 129 } |
126 int32_t leftPadding = (outputWidth - (inputWidth * multiX)) / 2; | 130 int32_t leftPadding = (outputWidth - (inputWidth * multiX)) / 2; |
127 int32_t topPadding = (outputHeight - (inputHeight * multiY)) / 2; | 131 int32_t topPadding = (outputHeight - (inputHeight * multiY)) / 2; |
128 if (leftPadding < 0) { | 132 if (leftPadding < 0) { |
129 leftPadding = 0; | 133 leftPadding = 0; |
130 } | 134 } |
131 if (topPadding < 0) { | 135 if (topPadding < 0) { |
132 topPadding = 0; | 136 topPadding = 0; |
133 } | 137 } |
134 m_output = new CBC_CommonBitMatrix; | 138 m_output = new CBC_CommonBitMatrix; |
135 m_output->Init(outputWidth, outputHeight); | 139 m_output->Init(outputWidth, outputHeight); |
136 for (int32_t inputY = 0, outputY = topPadding; | 140 for (int32_t inputY = 0, outputY = topPadding; |
137 (inputY < inputHeight) && (outputY < outputHeight - multiY); | 141 (inputY < inputHeight) && (outputY < outputHeight - multiY); |
138 inputY++, outputY += multiY) { | 142 inputY++, outputY += multiY) { |
139 for (int32_t inputX = 0, outputX = leftPadding; | 143 for (int32_t inputX = 0, outputX = leftPadding; |
140 (inputX < inputWidth) && (outputX < outputWidth - multiX); | 144 (inputX < inputWidth) && (outputX < outputWidth - multiX); |
141 inputX++, outputX += multiX) { | 145 inputX++, outputX += multiX) { |
142 if (code[inputX + inputY * inputWidth] == 1) { | 146 if (code[inputX + inputY * inputWidth] == 1) { |
143 m_output->SetRegion(outputX, outputY, multiX, multiY, e); | 147 m_output->SetRegion(outputX, outputY, multiX, multiY, e); |
144 BC_EXCEPTION_CHECK_ReturnVoid(e); | 148 BC_EXCEPTION_CHECK_ReturnVoid(e); |
145 } | 149 } |
146 } | 150 } |
147 } | 151 } |
148 } | 152 } |
OLD | NEW |