| 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 2006 Jeremias Maerki. | 8 * Copyright 2006 Jeremias Maerki. |
| 9 * | 9 * |
| 10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 * you may not use this file except in compliance with the License. | 11 * you may not use this file except in compliance with the License. |
| 12 * You may obtain a copy of the License at | 12 * You may obtain a copy of the License at |
| 13 * | 13 * |
| 14 * http://www.apache.org/licenses/LICENSE-2.0 | 14 * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 * | 15 * |
| 16 * Unless required by applicable law or agreed to in writing, software | 16 * Unless required by applicable law or agreed to in writing, software |
| 17 * distributed under the License is distributed on an "AS IS" BASIS, | 17 * distributed under the License is distributed on an "AS IS" BASIS, |
| 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 * See the License for the specific language governing permissions and | 19 * See the License for the specific language governing permissions and |
| 20 * limitations under the License. | 20 * limitations under the License. |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "../barcode.h" | 23 #include "../barcode.h" |
| 24 #include "BC_Encoder.h" | 24 #include "BC_Encoder.h" |
| 25 #include "BC_DefaultPlacement.h" | 25 #include "BC_DefaultPlacement.h" |
| 26 CBC_DefaultPlacement::CBC_DefaultPlacement(CFX_WideString codewords, FX_INT32 nu
mcols, FX_INT32 numrows) | 26 CBC_DefaultPlacement::CBC_DefaultPlacement(CFX_WideString codewords, int32_t num
cols, int32_t numrows) |
| 27 { | 27 { |
| 28 m_codewords = codewords; | 28 m_codewords = codewords; |
| 29 m_numcols = numcols; | 29 m_numcols = numcols; |
| 30 m_numrows = numrows; | 30 m_numrows = numrows; |
| 31 m_bits.SetSize(numcols * numrows); | 31 m_bits.SetSize(numcols * numrows); |
| 32 for (FX_INT32 i = 0; i < numcols * numrows; i++) { | 32 for (int32_t i = 0; i < numcols * numrows; i++) { |
| 33 m_bits[i] = (FX_BYTE) 2; | 33 m_bits[i] = (uint8_t) 2; |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 CBC_DefaultPlacement::~CBC_DefaultPlacement() | 36 CBC_DefaultPlacement::~CBC_DefaultPlacement() |
| 37 { | 37 { |
| 38 m_bits.RemoveAll(); | 38 m_bits.RemoveAll(); |
| 39 } | 39 } |
| 40 FX_INT32 CBC_DefaultPlacement::getNumrows() | 40 int32_t CBC_DefaultPlacement::getNumrows() |
| 41 { | 41 { |
| 42 return m_numrows; | 42 return m_numrows; |
| 43 } | 43 } |
| 44 FX_INT32 CBC_DefaultPlacement::getNumcols() | 44 int32_t CBC_DefaultPlacement::getNumcols() |
| 45 { | 45 { |
| 46 return m_numcols; | 46 return m_numcols; |
| 47 } | 47 } |
| 48 CFX_ByteArray& CBC_DefaultPlacement::getBits() | 48 CFX_ByteArray& CBC_DefaultPlacement::getBits() |
| 49 { | 49 { |
| 50 return m_bits; | 50 return m_bits; |
| 51 } | 51 } |
| 52 FX_BOOL CBC_DefaultPlacement::getBit(FX_INT32 col, FX_INT32 row) | 52 FX_BOOL CBC_DefaultPlacement::getBit(int32_t col, int32_t row) |
| 53 { | 53 { |
| 54 return m_bits[row * m_numcols + col] == 1; | 54 return m_bits[row * m_numcols + col] == 1; |
| 55 } | 55 } |
| 56 void CBC_DefaultPlacement::setBit(FX_INT32 col, FX_INT32 row, FX_BOOL bit) | 56 void CBC_DefaultPlacement::setBit(int32_t col, int32_t row, FX_BOOL bit) |
| 57 { | 57 { |
| 58 m_bits[row * m_numcols + col] = bit ? (FX_BYTE) 1 : (FX_BYTE) 0; | 58 m_bits[row * m_numcols + col] = bit ? (uint8_t) 1 : (uint8_t) 0; |
| 59 } | 59 } |
| 60 FX_BOOL CBC_DefaultPlacement::hasBit(FX_INT32 col, FX_INT32 row) | 60 FX_BOOL CBC_DefaultPlacement::hasBit(int32_t col, int32_t row) |
| 61 { | 61 { |
| 62 return m_bits[row * m_numcols + col] != 2; | 62 return m_bits[row * m_numcols + col] != 2; |
| 63 } | 63 } |
| 64 void CBC_DefaultPlacement::place() | 64 void CBC_DefaultPlacement::place() |
| 65 { | 65 { |
| 66 FX_INT32 pos = 0; | 66 int32_t pos = 0; |
| 67 FX_INT32 row = 4; | 67 int32_t row = 4; |
| 68 FX_INT32 col = 0; | 68 int32_t col = 0; |
| 69 do { | 69 do { |
| 70 if ((row == m_numrows) && (col == 0)) { | 70 if ((row == m_numrows) && (col == 0)) { |
| 71 corner1(pos++); | 71 corner1(pos++); |
| 72 } | 72 } |
| 73 if ((row == m_numrows - 2) && (col == 0) && ((m_numcols % 4) != 0)) { | 73 if ((row == m_numrows - 2) && (col == 0) && ((m_numcols % 4) != 0)) { |
| 74 corner2(pos++); | 74 corner2(pos++); |
| 75 } | 75 } |
| 76 if ((row == m_numrows - 2) && (col == 0) && (m_numcols % 8 == 4)) { | 76 if ((row == m_numrows - 2) && (col == 0) && (m_numcols % 8 == 4)) { |
| 77 corner3(pos++); | 77 corner3(pos++); |
| 78 } | 78 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 96 col -= 2; | 96 col -= 2; |
| 97 } while ((row < m_numrows) && (col >= 0)); | 97 } while ((row < m_numrows) && (col >= 0)); |
| 98 row += 3; | 98 row += 3; |
| 99 col++; | 99 col++; |
| 100 } while ((row < m_numrows) || (col < m_numcols)); | 100 } while ((row < m_numrows) || (col < m_numcols)); |
| 101 if (!hasBit(m_numcols - 1, m_numrows - 1)) { | 101 if (!hasBit(m_numcols - 1, m_numrows - 1)) { |
| 102 setBit(m_numcols - 1, m_numrows - 1, TRUE); | 102 setBit(m_numcols - 1, m_numrows - 1, TRUE); |
| 103 setBit(m_numcols - 2, m_numrows - 2, TRUE); | 103 setBit(m_numcols - 2, m_numrows - 2, TRUE); |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 void CBC_DefaultPlacement::module(FX_INT32 row, FX_INT32 col, FX_INT32 pos, FX_I
NT32 bit) | 106 void CBC_DefaultPlacement::module(int32_t row, int32_t col, int32_t pos, int32_t
bit) |
| 107 { | 107 { |
| 108 if (row < 0) { | 108 if (row < 0) { |
| 109 row += m_numrows; | 109 row += m_numrows; |
| 110 col += 4 - ((m_numrows + 4) % 8); | 110 col += 4 - ((m_numrows + 4) % 8); |
| 111 } | 111 } |
| 112 if (col < 0) { | 112 if (col < 0) { |
| 113 col += m_numcols; | 113 col += m_numcols; |
| 114 row += 4 - ((m_numcols + 4) % 8); | 114 row += 4 - ((m_numcols + 4) % 8); |
| 115 } | 115 } |
| 116 FX_INT32 v = m_codewords.GetAt(pos); | 116 int32_t v = m_codewords.GetAt(pos); |
| 117 v &= 1 << (8 - bit); | 117 v &= 1 << (8 - bit); |
| 118 setBit(col, row, v != 0); | 118 setBit(col, row, v != 0); |
| 119 } | 119 } |
| 120 void CBC_DefaultPlacement::utah(FX_INT32 row, FX_INT32 col, FX_INT32 pos) | 120 void CBC_DefaultPlacement::utah(int32_t row, int32_t col, int32_t pos) |
| 121 { | 121 { |
| 122 module(row - 2, col - 2, pos, 1); | 122 module(row - 2, col - 2, pos, 1); |
| 123 module(row - 2, col - 1, pos, 2); | 123 module(row - 2, col - 1, pos, 2); |
| 124 module(row - 1, col - 2, pos, 3); | 124 module(row - 1, col - 2, pos, 3); |
| 125 module(row - 1, col - 1, pos, 4); | 125 module(row - 1, col - 1, pos, 4); |
| 126 module(row - 1, col, pos, 5); | 126 module(row - 1, col, pos, 5); |
| 127 module(row, col - 2, pos, 6); | 127 module(row, col - 2, pos, 6); |
| 128 module(row, col - 1, pos, 7); | 128 module(row, col - 1, pos, 7); |
| 129 module(row, col, pos, 8); | 129 module(row, col, pos, 8); |
| 130 } | 130 } |
| 131 void CBC_DefaultPlacement::corner1(FX_INT32 pos) | 131 void CBC_DefaultPlacement::corner1(int32_t pos) |
| 132 { | 132 { |
| 133 module(m_numrows - 1, 0, pos, 1); | 133 module(m_numrows - 1, 0, pos, 1); |
| 134 module(m_numrows - 1, 1, pos, 2); | 134 module(m_numrows - 1, 1, pos, 2); |
| 135 module(m_numrows - 1, 2, pos, 3); | 135 module(m_numrows - 1, 2, pos, 3); |
| 136 module(0, m_numcols - 2, pos, 4); | 136 module(0, m_numcols - 2, pos, 4); |
| 137 module(0, m_numcols - 1, pos, 5); | 137 module(0, m_numcols - 1, pos, 5); |
| 138 module(1, m_numcols - 1, pos, 6); | 138 module(1, m_numcols - 1, pos, 6); |
| 139 module(2, m_numcols - 1, pos, 7); | 139 module(2, m_numcols - 1, pos, 7); |
| 140 module(3, m_numcols - 1, pos, 8); | 140 module(3, m_numcols - 1, pos, 8); |
| 141 } | 141 } |
| 142 void CBC_DefaultPlacement::corner2(FX_INT32 pos) | 142 void CBC_DefaultPlacement::corner2(int32_t pos) |
| 143 { | 143 { |
| 144 module(m_numrows - 3, 0, pos, 1); | 144 module(m_numrows - 3, 0, pos, 1); |
| 145 module(m_numrows - 2, 0, pos, 2); | 145 module(m_numrows - 2, 0, pos, 2); |
| 146 module(m_numrows - 1, 0, pos, 3); | 146 module(m_numrows - 1, 0, pos, 3); |
| 147 module(0, m_numcols - 4, pos, 4); | 147 module(0, m_numcols - 4, pos, 4); |
| 148 module(0, m_numcols - 3, pos, 5); | 148 module(0, m_numcols - 3, pos, 5); |
| 149 module(0, m_numcols - 2, pos, 6); | 149 module(0, m_numcols - 2, pos, 6); |
| 150 module(0, m_numcols - 1, pos, 7); | 150 module(0, m_numcols - 1, pos, 7); |
| 151 module(1, m_numcols - 1, pos, 8); | 151 module(1, m_numcols - 1, pos, 8); |
| 152 } | 152 } |
| 153 void CBC_DefaultPlacement::corner3(FX_INT32 pos) | 153 void CBC_DefaultPlacement::corner3(int32_t pos) |
| 154 { | 154 { |
| 155 module(m_numrows - 3, 0, pos, 1); | 155 module(m_numrows - 3, 0, pos, 1); |
| 156 module(m_numrows - 2, 0, pos, 2); | 156 module(m_numrows - 2, 0, pos, 2); |
| 157 module(m_numrows - 1, 0, pos, 3); | 157 module(m_numrows - 1, 0, pos, 3); |
| 158 module(0, m_numcols - 2, pos, 4); | 158 module(0, m_numcols - 2, pos, 4); |
| 159 module(0, m_numcols - 1, pos, 5); | 159 module(0, m_numcols - 1, pos, 5); |
| 160 module(1, m_numcols - 1, pos, 6); | 160 module(1, m_numcols - 1, pos, 6); |
| 161 module(2, m_numcols - 1, pos, 7); | 161 module(2, m_numcols - 1, pos, 7); |
| 162 module(3, m_numcols - 1, pos, 8); | 162 module(3, m_numcols - 1, pos, 8); |
| 163 } | 163 } |
| 164 void CBC_DefaultPlacement::corner4(FX_INT32 pos) | 164 void CBC_DefaultPlacement::corner4(int32_t pos) |
| 165 { | 165 { |
| 166 module(m_numrows - 1, 0, pos, 1); | 166 module(m_numrows - 1, 0, pos, 1); |
| 167 module(m_numrows - 1, m_numcols - 1, pos, 2); | 167 module(m_numrows - 1, m_numcols - 1, pos, 2); |
| 168 module(0, m_numcols - 3, pos, 3); | 168 module(0, m_numcols - 3, pos, 3); |
| 169 module(0, m_numcols - 2, pos, 4); | 169 module(0, m_numcols - 2, pos, 4); |
| 170 module(0, m_numcols - 1, pos, 5); | 170 module(0, m_numcols - 1, pos, 5); |
| 171 module(1, m_numcols - 3, pos, 6); | 171 module(1, m_numcols - 3, pos, 6); |
| 172 module(1, m_numcols - 2, pos, 7); | 172 module(1, m_numcols - 2, pos, 7); |
| 173 module(1, m_numcols - 1, pos, 8); | 173 module(1, m_numcols - 1, pos, 8); |
| 174 } | 174 } |
| OLD | NEW |