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 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
7 /* | 7 /* |
8 * Copyright 2008 ZXing authors | 8 * Copyright 2008 ZXing authors |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
(...skipping 37 matching lines...) Loading... |
48 FX_BOOL CBC_DataMatrixWriter::SetErrorCorrectionLevel(int32_t level) { | 48 FX_BOOL CBC_DataMatrixWriter::SetErrorCorrectionLevel(int32_t level) { |
49 m_iCorrectLevel = level; | 49 m_iCorrectLevel = level; |
50 return TRUE; | 50 return TRUE; |
51 } | 51 } |
52 uint8_t* CBC_DataMatrixWriter::Encode(const CFX_WideString& contents, | 52 uint8_t* CBC_DataMatrixWriter::Encode(const CFX_WideString& contents, |
53 int32_t& outWidth, | 53 int32_t& outWidth, |
54 int32_t& outHeight, | 54 int32_t& outHeight, |
55 int32_t& e) { | 55 int32_t& e) { |
56 if (outWidth < 0 || outHeight < 0) { | 56 if (outWidth < 0 || outHeight < 0) { |
57 e = BCExceptionHeightAndWidthMustBeAtLeast1; | 57 e = BCExceptionHeightAndWidthMustBeAtLeast1; |
58 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 58 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
59 } | 59 } |
60 CBC_SymbolShapeHint::SymbolShapeHint shape = | 60 CBC_SymbolShapeHint::SymbolShapeHint shape = |
61 CBC_SymbolShapeHint::FORCE_SQUARE; | 61 CBC_SymbolShapeHint::FORCE_SQUARE; |
62 CBC_Dimension* minSize = NULL; | 62 CBC_Dimension* minSize = nullptr; |
63 CBC_Dimension* maxSize = NULL; | 63 CBC_Dimension* maxSize = nullptr; |
64 CFX_WideString ecLevel; | 64 CFX_WideString ecLevel; |
65 CFX_WideString encoded = CBC_HighLevelEncoder::encodeHighLevel( | 65 CFX_WideString encoded = CBC_HighLevelEncoder::encodeHighLevel( |
66 contents, ecLevel, shape, minSize, maxSize, e); | 66 contents, ecLevel, shape, minSize, maxSize, e); |
67 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 67 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
68 CBC_SymbolInfo* symbolInfo = CBC_SymbolInfo::lookup( | 68 CBC_SymbolInfo* symbolInfo = CBC_SymbolInfo::lookup( |
69 encoded.GetLength(), shape, minSize, maxSize, TRUE, e); | 69 encoded.GetLength(), shape, minSize, maxSize, TRUE, e); |
70 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 70 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
71 CFX_WideString codewords = | 71 CFX_WideString codewords = |
72 CBC_ErrorCorrection::encodeECC200(encoded, symbolInfo, e); | 72 CBC_ErrorCorrection::encodeECC200(encoded, symbolInfo, e); |
73 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 73 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
74 CBC_DefaultPlacement* placement = | 74 CBC_DefaultPlacement* placement = |
75 new CBC_DefaultPlacement(codewords, symbolInfo->getSymbolDataWidth(e), | 75 new CBC_DefaultPlacement(codewords, symbolInfo->getSymbolDataWidth(e), |
76 symbolInfo->getSymbolDataHeight(e)); | 76 symbolInfo->getSymbolDataHeight(e)); |
77 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 77 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
78 placement->place(); | 78 placement->place(); |
79 CBC_CommonByteMatrix* bytematrix = encodeLowLevel(placement, symbolInfo, e); | 79 CBC_CommonByteMatrix* bytematrix = encodeLowLevel(placement, symbolInfo, e); |
80 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 80 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
81 outWidth = bytematrix->GetWidth(); | 81 outWidth = bytematrix->GetWidth(); |
82 outHeight = bytematrix->GetHeight(); | 82 outHeight = bytematrix->GetHeight(); |
83 uint8_t* result = FX_Alloc2D(uint8_t, outWidth, outHeight); | 83 uint8_t* result = FX_Alloc2D(uint8_t, outWidth, outHeight); |
84 FXSYS_memcpy(result, bytematrix->GetArray(), outWidth * outHeight); | 84 FXSYS_memcpy(result, bytematrix->GetArray(), outWidth * outHeight); |
85 delete bytematrix; | 85 delete bytematrix; |
86 delete placement; | 86 delete placement; |
87 return result; | 87 return result; |
88 } | 88 } |
89 CBC_CommonByteMatrix* CBC_DataMatrixWriter::encodeLowLevel( | 89 CBC_CommonByteMatrix* CBC_DataMatrixWriter::encodeLowLevel( |
90 CBC_DefaultPlacement* placement, | 90 CBC_DefaultPlacement* placement, |
91 CBC_SymbolInfo* symbolInfo, | 91 CBC_SymbolInfo* symbolInfo, |
92 int32_t& e) { | 92 int32_t& e) { |
93 int32_t symbolWidth = symbolInfo->getSymbolDataWidth(e); | 93 int32_t symbolWidth = symbolInfo->getSymbolDataWidth(e); |
94 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 94 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
95 int32_t symbolHeight = symbolInfo->getSymbolDataHeight(e); | 95 int32_t symbolHeight = symbolInfo->getSymbolDataHeight(e); |
96 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 96 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
97 CBC_CommonByteMatrix* matrix = new CBC_CommonByteMatrix( | 97 CBC_CommonByteMatrix* matrix = new CBC_CommonByteMatrix( |
98 symbolInfo->getSymbolWidth(e), symbolInfo->getSymbolHeight(e)); | 98 symbolInfo->getSymbolWidth(e), symbolInfo->getSymbolHeight(e)); |
99 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 99 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
100 matrix->Init(); | 100 matrix->Init(); |
101 int32_t matrixY = 0; | 101 int32_t matrixY = 0; |
102 for (int32_t y = 0; y < symbolHeight; y++) { | 102 for (int32_t y = 0; y < symbolHeight; y++) { |
103 int32_t matrixX; | 103 int32_t matrixX; |
104 if ((y % symbolInfo->m_matrixHeight) == 0) { | 104 if ((y % symbolInfo->m_matrixHeight) == 0) { |
105 matrixX = 0; | 105 matrixX = 0; |
106 for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) { | 106 for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) { |
107 matrix->Set(matrixX, matrixY, (x % 2) == 0); | 107 matrix->Set(matrixX, matrixY, (x % 2) == 0); |
108 matrixX++; | 108 matrixX++; |
109 } | 109 } |
(...skipping 17 matching lines...) Loading... |
127 matrixX = 0; | 127 matrixX = 0; |
128 for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) { | 128 for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) { |
129 matrix->Set(matrixX, matrixY, TRUE); | 129 matrix->Set(matrixX, matrixY, TRUE); |
130 matrixX++; | 130 matrixX++; |
131 } | 131 } |
132 matrixY++; | 132 matrixY++; |
133 } | 133 } |
134 } | 134 } |
135 return matrix; | 135 return matrix; |
136 } | 136 } |
OLD | NEW |