Chromium Code Reviews| 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 | |
| 7 #include "xfa/src/fxbarcode/barcode.h" | 9 #include "xfa/src/fxbarcode/barcode.h" |
| 8 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h" | 10 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h" |
| 9 #include "xfa/src/fxbarcode/BC_Writer.h" | 11 #include "xfa/src/fxbarcode/BC_Writer.h" |
| 10 #include "xfa/src/fxbarcode/BC_TwoDimWriter.h" | 12 #include "xfa/src/fxbarcode/BC_TwoDimWriter.h" |
| 11 CBC_TwoDimWriter::CBC_TwoDimWriter() { | 13 CBC_TwoDimWriter::CBC_TwoDimWriter() { |
| 12 m_iCorrectLevel = 1; | 14 m_iCorrectLevel = 1; |
| 13 m_bFixedSize = TRUE; | 15 m_bFixedSize = TRUE; |
| 14 m_output = NULL; | 16 m_output = NULL; |
| 15 } | 17 } |
| 16 CBC_TwoDimWriter::~CBC_TwoDimWriter() { | 18 CBC_TwoDimWriter::~CBC_TwoDimWriter() { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 } | 87 } |
| 86 pOutBitmap = pStretchBitmap; | 88 pOutBitmap = pStretchBitmap; |
| 87 } | 89 } |
| 88 } | 90 } |
| 89 void CBC_TwoDimWriter::RenderResult(uint8_t* code, | 91 void CBC_TwoDimWriter::RenderResult(uint8_t* code, |
| 90 int32_t codeWidth, | 92 int32_t codeWidth, |
| 91 int32_t codeHeight, | 93 int32_t codeHeight, |
| 92 int32_t& e) { | 94 int32_t& e) { |
| 93 int32_t inputWidth = codeWidth; | 95 int32_t inputWidth = codeWidth; |
| 94 int32_t inputHeight = codeHeight; | 96 int32_t inputHeight = codeHeight; |
| 95 int32_t tempWidth = inputWidth + (1 << 1); | 97 int32_t tempWidth = inputWidth + 2; |
| 96 int32_t tempHeight = inputHeight + (1 << 1); | 98 int32_t tempHeight = inputHeight + 2; |
| 97 FX_FLOAT moduleHSize = (FX_FLOAT)FX_MIN(m_ModuleWidth, m_ModuleHeight); | 99 FX_FLOAT moduleHSize = std::min(m_ModuleWidth, m_ModuleHeight); |
| 98 if (moduleHSize > 8) { | 100 moduleHSize = std::min(moduleHSize, 8.0f); |
| 99 moduleHSize = 8; | 101 moduleHSize = std::max(moduleHSize, 1.0f); |
| 100 } else if (moduleHSize < 1) { | 102 int32_t outputWidth = static_cast<int32_t>( |
| 101 moduleHSize = 1; | 103 std::max(static_cast<int32_t>(tempWidth * moduleHSize), tempWidth)); |
|
Tom Sepez
2016/01/09 00:35:52
This code is troubling. moduleHSize is constrained
| |
| 102 } | 104 int32_t outputHeight = static_cast<int32_t>( |
| 103 int32_t outputWidth = (int32_t)FX_MAX(tempWidth * moduleHSize, tempWidth); | 105 std::max(static_cast<int32_t>(tempHeight * moduleHSize), tempHeight)); |
|
Tom Sepez
2016/01/09 00:35:52
in any event, I don't think the outer cast is requ
| |
| 104 int32_t outputHeight = (int32_t)FX_MAX(tempHeight * moduleHSize, tempHeight); | |
| 105 int32_t multiX = 1; | 106 int32_t multiX = 1; |
| 106 int32_t multiY = 1; | 107 int32_t multiY = 1; |
| 107 if (m_bFixedSize) { | 108 if (m_bFixedSize) { |
| 108 if (m_Width < outputWidth || m_Height < outputHeight) { | 109 if (m_Width < outputWidth || m_Height < outputHeight) { |
| 109 e = BCExceptionBitmapSizeError; | 110 e = BCExceptionBitmapSizeError; |
| 110 return; | 111 return; |
| 111 } | 112 } |
| 112 } else { | 113 } else { |
| 113 if (m_Width > outputWidth || m_Height > outputHeight) { | 114 if (m_Width > outputWidth || m_Height > outputHeight) { |
| 114 outputWidth = (int32_t)(outputWidth * | 115 outputWidth = (int32_t)(outputWidth * |
| 115 ceil((FX_FLOAT)m_Width / (FX_FLOAT)outputWidth)); | 116 ceil((FX_FLOAT)m_Width / (FX_FLOAT)outputWidth)); |
| 116 outputHeight = (int32_t)( | 117 outputHeight = (int32_t)( |
| 117 outputHeight * ceil((FX_FLOAT)m_Height / (FX_FLOAT)outputHeight)); | 118 outputHeight * ceil((FX_FLOAT)m_Height / (FX_FLOAT)outputHeight)); |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 multiX = (int32_t)ceil((FX_FLOAT)outputWidth / (FX_FLOAT)tempWidth); | 121 multiX = (int32_t)ceil((FX_FLOAT)outputWidth / (FX_FLOAT)tempWidth); |
| 121 multiY = (int32_t)ceil((FX_FLOAT)outputHeight / (FX_FLOAT)tempHeight); | 122 multiY = (int32_t)ceil((FX_FLOAT)outputHeight / (FX_FLOAT)tempHeight); |
| 122 if (m_bFixedSize) { | 123 if (m_bFixedSize) { |
| 123 multiX = FX_MIN(multiX, multiY); | 124 multiX = std::min(multiX, multiY); |
| 124 multiY = multiX; | 125 multiY = multiX; |
| 125 } | 126 } |
| 126 int32_t leftPadding = (outputWidth - (inputWidth * multiX)) / 2; | 127 int32_t leftPadding = (outputWidth - (inputWidth * multiX)) / 2; |
| 127 int32_t topPadding = (outputHeight - (inputHeight * multiY)) / 2; | 128 int32_t topPadding = (outputHeight - (inputHeight * multiY)) / 2; |
| 128 if (leftPadding < 0) { | 129 if (leftPadding < 0) { |
| 129 leftPadding = 0; | 130 leftPadding = 0; |
| 130 } | 131 } |
| 131 if (topPadding < 0) { | 132 if (topPadding < 0) { |
| 132 topPadding = 0; | 133 topPadding = 0; |
| 133 } | 134 } |
| 134 m_output = new CBC_CommonBitMatrix; | 135 m_output = new CBC_CommonBitMatrix; |
| 135 m_output->Init(outputWidth, outputHeight); | 136 m_output->Init(outputWidth, outputHeight); |
| 136 for (int32_t inputY = 0, outputY = topPadding; | 137 for (int32_t inputY = 0, outputY = topPadding; |
| 137 (inputY < inputHeight) && (outputY < outputHeight - multiY); | 138 (inputY < inputHeight) && (outputY < outputHeight - multiY); |
| 138 inputY++, outputY += multiY) { | 139 inputY++, outputY += multiY) { |
| 139 for (int32_t inputX = 0, outputX = leftPadding; | 140 for (int32_t inputX = 0, outputX = leftPadding; |
| 140 (inputX < inputWidth) && (outputX < outputWidth - multiX); | 141 (inputX < inputWidth) && (outputX < outputWidth - multiX); |
| 141 inputX++, outputX += multiX) { | 142 inputX++, outputX += multiX) { |
| 142 if (code[inputX + inputY * inputWidth] == 1) { | 143 if (code[inputX + inputY * inputWidth] == 1) { |
| 143 m_output->SetRegion(outputX, outputY, multiX, multiY, e); | 144 m_output->SetRegion(outputX, outputY, multiX, multiY, e); |
| 144 BC_EXCEPTION_CHECK_ReturnVoid(e); | 145 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 } | 148 } |
| 148 } | 149 } |
| OLD | NEW |