| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } else if (versionSpecify > 0 && versionSpecify <= 40) { | 81 } else if (versionSpecify > 0 && versionSpecify <= 40) { |
| 82 EncodeWithSpecifyVersion(content, ecLevel, qrCode, versionSpecify, e); | 82 EncodeWithSpecifyVersion(content, ecLevel, qrCode, versionSpecify, e); |
| 83 BC_EXCEPTION_CHECK_ReturnVoid(e); | 83 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 84 } else { | 84 } else { |
| 85 e = BCExceptionVersionMust1_40; | 85 e = BCExceptionVersionMust1_40; |
| 86 BC_EXCEPTION_CHECK_ReturnVoid(e); | 86 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 void CBC_QRCoderEncoder::AppendECI(CBC_QRCoderBitVector* bits) {} | 89 void CBC_QRCoderEncoder::AppendECI(CBC_QRCoderBitVector* bits) {} |
| 90 void CBC_QRCoderEncoder::AppendDataModeLenghInfo( | 90 void CBC_QRCoderEncoder::AppendDataModeLenghInfo( |
| 91 CFX_PtrArray& splitResult, | 91 const CFX_ArrayTemplate<Make_Pair*>& splitResult, |
| 92 CBC_QRCoderBitVector& headerAndDataBits, | 92 CBC_QRCoderBitVector& headerAndDataBits, |
| 93 CBC_QRCoderMode* tempMode, | 93 CBC_QRCoderMode* tempMode, |
| 94 CBC_QRCoder* qrCode, | 94 CBC_QRCoder* qrCode, |
| 95 CFX_ByteString& encoding, | 95 CFX_ByteString& encoding, |
| 96 int32_t& e) { | 96 int32_t& e) { |
| 97 for (int32_t i = 0; i < splitResult.GetSize(); i++) { | 97 for (int32_t i = 0; i < splitResult.GetSize(); i++) { |
| 98 tempMode = ((Make_Pair*)splitResult[i])->m_mode; | 98 tempMode = ((Make_Pair*)splitResult[i])->m_mode; |
| 99 if (tempMode == CBC_QRCoderMode::sGBK) { | 99 if (tempMode == CBC_QRCoderMode::sGBK) { |
| 100 AppendModeInfo(tempMode, &headerAndDataBits, e); | 100 AppendModeInfo(tempMode, &headerAndDataBits, e); |
| 101 BC_EXCEPTION_CHECK_ReturnVoid(e); | 101 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 AppendBytes(((Make_Pair*)splitResult[i])->m_string, tempMode, | 134 AppendBytes(((Make_Pair*)splitResult[i])->m_string, tempMode, |
| 135 &headerAndDataBits, encoding, e); | 135 &headerAndDataBits, encoding, e); |
| 136 BC_EXCEPTION_CHECK_ReturnVoid(e); | 136 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 137 } else { | 137 } else { |
| 138 e = BCExceptionUnknown; | 138 e = BCExceptionUnknown; |
| 139 BC_EXCEPTION_CHECK_ReturnVoid(e); | 139 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, | 143 void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, |
| 144 CFX_PtrArray& result) { | 144 CFX_ArrayTemplate<Make_Pair*>* result) { |
| 145 int32_t index = 0, flag = 0; | 145 int32_t index = 0, flag = 0; |
| 146 while ( | 146 while ( |
| 147 (((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || | 147 (((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || |
| 148 ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && | 148 ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && |
| 149 (index < content.GetLength())) { | 149 (index < content.GetLength())) { |
| 150 index += 2; | 150 index += 2; |
| 151 } | 151 } |
| 152 if (index != flag) { | 152 if (index != flag) { |
| 153 result.Add( | 153 result->Add( |
| 154 new Make_Pair(CBC_QRCoderMode::sGBK, content.Mid(flag, index - flag))); | 154 new Make_Pair(CBC_QRCoderMode::sGBK, content.Mid(flag, index - flag))); |
| 155 } | 155 } |
| 156 flag = index; | 156 flag = index; |
| 157 if (index >= content.GetLength()) { | 157 if (index >= content.GetLength()) { |
| 158 return; | 158 return; |
| 159 } | 159 } |
| 160 while ( | 160 while ( |
| 161 GetAlphaNumericCode((uint8_t)content[index]) == -1 && | 161 GetAlphaNumericCode((uint8_t)content[index]) == -1 && |
| 162 !(((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || | 162 !(((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || |
| 163 ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && | 163 ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && |
| 164 (index < content.GetLength())) { | 164 (index < content.GetLength())) { |
| 165 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 165 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 166 if (IsDBCSLeadByte((uint8_t)content[index])) | 166 if (IsDBCSLeadByte((uint8_t)content[index])) |
| 167 #else | 167 #else |
| 168 if ((uint8_t)content[index] > 127) | 168 if ((uint8_t)content[index] > 127) |
| 169 #endif | 169 #endif |
| 170 { | 170 { |
| 171 index += 2; | 171 index += 2; |
| 172 } else { | 172 } else { |
| 173 index++; | 173 index++; |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 if (index != flag) { | 176 if (index != flag) { |
| 177 result.Add( | 177 result->Add( |
| 178 new Make_Pair(CBC_QRCoderMode::sBYTE, content.Mid(flag, index - flag))); | 178 new Make_Pair(CBC_QRCoderMode::sBYTE, content.Mid(flag, index - flag))); |
| 179 } | 179 } |
| 180 flag = index; | 180 flag = index; |
| 181 if (index >= content.GetLength()) { | 181 if (index >= content.GetLength()) { |
| 182 return; | 182 return; |
| 183 } | 183 } |
| 184 while (FXSYS_Isdigit((uint8_t)content[index]) && | 184 while (FXSYS_Isdigit((uint8_t)content[index]) && |
| 185 (index < content.GetLength())) { | 185 (index < content.GetLength())) { |
| 186 index++; | 186 index++; |
| 187 } | 187 } |
| 188 if (index != flag) { | 188 if (index != flag) { |
| 189 result.Add(new Make_Pair(CBC_QRCoderMode::sNUMERIC, | 189 result->Add(new Make_Pair(CBC_QRCoderMode::sNUMERIC, |
| 190 content.Mid(flag, index - flag))); | 190 content.Mid(flag, index - flag))); |
| 191 } | 191 } |
| 192 flag = index; | 192 flag = index; |
| 193 if (index >= content.GetLength()) { | 193 if (index >= content.GetLength()) { |
| 194 return; | 194 return; |
| 195 } | 195 } |
| 196 while (GetAlphaNumericCode((uint8_t)content[index]) != -1 && | 196 while (GetAlphaNumericCode((uint8_t)content[index]) != -1 && |
| 197 (index < content.GetLength())) { | 197 (index < content.GetLength())) { |
| 198 index++; | 198 index++; |
| 199 } | 199 } |
| 200 if (index != flag) { | 200 if (index != flag) { |
| 201 result.Add(new Make_Pair(CBC_QRCoderMode::sALPHANUMERIC, | 201 result->Add(new Make_Pair(CBC_QRCoderMode::sALPHANUMERIC, |
| 202 content.Mid(flag, index - flag))); | 202 content.Mid(flag, index - flag))); |
| 203 } | 203 } |
| 204 flag = index; | 204 flag = index; |
| 205 if (index >= content.GetLength()) { | 205 if (index < content.GetLength()) |
| 206 return; | 206 SplitString(content.Mid(index, content.GetLength() - index), result); |
| 207 } | |
| 208 SplitString(content.Mid(index, content.GetLength() - index), result); | |
| 209 } | 207 } |
| 208 |
| 210 int32_t CBC_QRCoderEncoder::GetSpanByVersion(CBC_QRCoderMode* modeFirst, | 209 int32_t CBC_QRCoderEncoder::GetSpanByVersion(CBC_QRCoderMode* modeFirst, |
| 211 CBC_QRCoderMode* modeSecond, | 210 CBC_QRCoderMode* modeSecond, |
| 212 int32_t versionNum, | 211 int32_t versionNum, |
| 213 int32_t& e) { | 212 int32_t& e) { |
| 214 if (versionNum == 0) { | 213 if (versionNum == 0) { |
| 215 return 0; | 214 return 0; |
| 216 } | 215 } |
| 217 if ((modeFirst == CBC_QRCoderMode::sALPHANUMERIC) && | 216 if ((modeFirst == CBC_QRCoderMode::sALPHANUMERIC) && |
| 218 (modeSecond == CBC_QRCoderMode::sBYTE)) { | 217 (modeSecond == CBC_QRCoderMode::sBYTE)) { |
| 219 if (versionNum >= 1 && versionNum <= 9) { | 218 if (versionNum >= 1 && versionNum <= 9) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 246 return 8; | 245 return 8; |
| 247 } else if (versionNum >= 27 && versionNum <= 40) { | 246 } else if (versionNum >= 27 && versionNum <= 40) { |
| 248 return 9; | 247 return 9; |
| 249 } else { | 248 } else { |
| 250 e = BCExceptionNoSuchVersion; | 249 e = BCExceptionNoSuchVersion; |
| 251 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | 250 BC_EXCEPTION_CHECK_ReturnValue(e, 0); |
| 252 } | 251 } |
| 253 } | 252 } |
| 254 return -1; | 253 return -1; |
| 255 } | 254 } |
| 256 void CBC_QRCoderEncoder::MergeString(CFX_PtrArray& result, | 255 |
| 256 void CBC_QRCoderEncoder::MergeString(CFX_ArrayTemplate<Make_Pair*>* result, |
| 257 int32_t versionNum, | 257 int32_t versionNum, |
| 258 int32_t& e) { | 258 int32_t& e) { |
| 259 Make_Pair* first = NULL; | 259 Make_Pair* first = NULL; |
| 260 Make_Pair* second = NULL; | 260 Make_Pair* second = NULL; |
| 261 size_t mergeNum = 0; | 261 size_t mergeNum = 0; |
| 262 int32_t i; | 262 int32_t i; |
| 263 for (i = 0; ((i < result.GetSize()) && (i + 1 < result.GetSize())); i++) { | 263 for (i = 0; ((i < result->GetSize()) && (i + 1 < result->GetSize())); i++) { |
| 264 first = (Make_Pair*)result[i]; | 264 first = (*result)[i]; |
| 265 second = (Make_Pair*)result[i + 1]; | 265 second = (*result)[i + 1]; |
| 266 if (first->m_mode == CBC_QRCoderMode::sALPHANUMERIC) { | 266 if (first->m_mode == CBC_QRCoderMode::sALPHANUMERIC) { |
| 267 int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sALPHANUMERIC, | 267 int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sALPHANUMERIC, |
| 268 CBC_QRCoderMode::sBYTE, versionNum, e); | 268 CBC_QRCoderMode::sBYTE, versionNum, e); |
| 269 BC_EXCEPTION_CHECK_ReturnVoid(e); | 269 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 270 if ((second->m_mode == CBC_QRCoderMode::sBYTE) && | 270 if ((second->m_mode == CBC_QRCoderMode::sBYTE) && |
| 271 (first->m_string.GetLength() < tmp)) { | 271 (first->m_string.GetLength() < tmp)) { |
| 272 CFX_ByteString str = first->m_string + second->m_string; | 272 CFX_ByteString str = first->m_string + second->m_string; |
| 273 second->m_string = str; | 273 second->m_string = str; |
| 274 delete first; | 274 delete first; |
| 275 result.RemoveAt(i); | 275 result->RemoveAt(i); |
| 276 i--; | 276 i--; |
| 277 mergeNum++; | 277 mergeNum++; |
| 278 } | 278 } |
| 279 } else if (first->m_mode == CBC_QRCoderMode::sBYTE) { | 279 } else if (first->m_mode == CBC_QRCoderMode::sBYTE) { |
| 280 if (second->m_mode == CBC_QRCoderMode::sBYTE) { | 280 if (second->m_mode == CBC_QRCoderMode::sBYTE) { |
| 281 first->m_string += second->m_string; | 281 first->m_string += second->m_string; |
| 282 delete second; | 282 delete second; |
| 283 result.RemoveAt(i + 1); | 283 result->RemoveAt(i + 1); |
| 284 i--; | 284 i--; |
| 285 mergeNum++; | 285 mergeNum++; |
| 286 } | 286 } |
| 287 } else if (first->m_mode == CBC_QRCoderMode::sNUMERIC) { | 287 } else if (first->m_mode == CBC_QRCoderMode::sNUMERIC) { |
| 288 int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sNUMERIC, | 288 int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sNUMERIC, |
| 289 CBC_QRCoderMode::sBYTE, versionNum, e); | 289 CBC_QRCoderMode::sBYTE, versionNum, e); |
| 290 BC_EXCEPTION_CHECK_ReturnVoid(e); | 290 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 291 if ((second->m_mode == CBC_QRCoderMode::sBYTE) && | 291 if ((second->m_mode == CBC_QRCoderMode::sBYTE) && |
| 292 (first->m_string.GetLength() < tmp)) { | 292 (first->m_string.GetLength() < tmp)) { |
| 293 CFX_ByteString str = first->m_string + second->m_string; | 293 CFX_ByteString str = first->m_string + second->m_string; |
| 294 second->m_string = str; | 294 second->m_string = str; |
| 295 delete first; | 295 delete first; |
| 296 result.RemoveAt(i); | 296 result->RemoveAt(i); |
| 297 i--; | 297 i--; |
| 298 mergeNum++; | 298 mergeNum++; |
| 299 } | 299 } |
| 300 tmp = GetSpanByVersion(CBC_QRCoderMode::sNUMERIC, | 300 tmp = GetSpanByVersion(CBC_QRCoderMode::sNUMERIC, |
| 301 CBC_QRCoderMode::sALPHANUMERIC, versionNum, e); | 301 CBC_QRCoderMode::sALPHANUMERIC, versionNum, e); |
| 302 BC_EXCEPTION_CHECK_ReturnVoid(e); | 302 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 303 if ((second->m_mode == CBC_QRCoderMode::sALPHANUMERIC) && | 303 if ((second->m_mode == CBC_QRCoderMode::sALPHANUMERIC) && |
| 304 (first->m_string.GetLength() < tmp)) { | 304 (first->m_string.GetLength() < tmp)) { |
| 305 CFX_ByteString str = first->m_string + second->m_string; | 305 CFX_ByteString str = first->m_string + second->m_string; |
| 306 second->m_string = str; | 306 second->m_string = str; |
| 307 delete first; | 307 delete first; |
| 308 result.RemoveAt(i); | 308 result->RemoveAt(i); |
| 309 i--; | 309 i--; |
| 310 mergeNum++; | 310 mergeNum++; |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 if (mergeNum == 0) { | 314 if (mergeNum == 0) { |
| 315 return; | 315 return; |
| 316 } | 316 } |
| 317 MergeString(result, versionNum, e); | 317 MergeString(result, versionNum, e); |
| 318 BC_EXCEPTION_CHECK_ReturnVoid(e); | 318 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 346 BC_EXCEPTION_CHECK_ReturnVoid(e); | 346 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 347 } | 347 } |
| 348 void CBC_QRCoderEncoder::EncodeWithSpecifyVersion( | 348 void CBC_QRCoderEncoder::EncodeWithSpecifyVersion( |
| 349 const CFX_ByteString& content, | 349 const CFX_ByteString& content, |
| 350 CBC_QRCoderErrorCorrectionLevel* ecLevel, | 350 CBC_QRCoderErrorCorrectionLevel* ecLevel, |
| 351 CBC_QRCoder* qrCode, | 351 CBC_QRCoder* qrCode, |
| 352 int32_t versionSpecify, | 352 int32_t versionSpecify, |
| 353 int32_t& e) { | 353 int32_t& e) { |
| 354 CFX_ByteString encoding = "utf8"; | 354 CFX_ByteString encoding = "utf8"; |
| 355 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; | 355 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; |
| 356 CFX_PtrArray splitResult; | 356 CFX_ArrayTemplate<Make_Pair*> splitResult; |
| 357 CBC_QRCoderBitVector dataBits; | 357 CBC_QRCoderBitVector dataBits; |
| 358 dataBits.Init(); | 358 dataBits.Init(); |
| 359 SplitString(content, splitResult); | 359 SplitString(content, &splitResult); |
| 360 MergeString(splitResult, versionSpecify, e); | 360 MergeString(&splitResult, versionSpecify, e); |
| 361 BC_EXCEPTION_CHECK_ReturnVoid(e) CBC_QRCoderMode* tempMode = NULL; | 361 BC_EXCEPTION_CHECK_ReturnVoid(e) CBC_QRCoderMode* tempMode = NULL; |
| 362 for (int32_t i = 0; i < splitResult.GetSize(); i++) { | 362 for (int32_t i = 0; i < splitResult.GetSize(); i++) { |
| 363 AppendBytes(((Make_Pair*)splitResult[i])->m_string, | 363 AppendBytes(splitResult[i]->m_string, splitResult[i]->m_mode, &dataBits, |
| 364 ((Make_Pair*)splitResult[i])->m_mode, &dataBits, encoding, e); | 364 encoding, e); |
| 365 if (e != BCExceptionNO) { | 365 if (e != BCExceptionNO) { |
| 366 for (int32_t y = 0; y < splitResult.GetSize(); y++) { | 366 for (int32_t y = 0; y < splitResult.GetSize(); y++) |
| 367 delete (Make_Pair*)splitResult[y]; | 367 delete splitResult[y]; |
| 368 } | |
| 369 splitResult.RemoveAll(); | |
| 370 return; | 368 return; |
| 371 } | 369 } |
| 372 } | 370 } |
| 373 int32_t numInputBytes = dataBits.sizeInBytes(); | 371 int32_t numInputBytes = dataBits.sizeInBytes(); |
| 374 CBC_QRCoderBitVector headerAndDataBits; | 372 CBC_QRCoderBitVector headerAndDataBits; |
| 375 headerAndDataBits.Init(); | 373 headerAndDataBits.Init(); |
| 376 InitQRCode(numInputBytes, versionSpecify, ecLevel, mode, qrCode, e); | 374 InitQRCode(numInputBytes, versionSpecify, ecLevel, mode, qrCode, e); |
| 377 if (e != BCExceptionNO) { | 375 if (e != BCExceptionNO) { |
| 378 for (int32_t k = 0; k < splitResult.GetSize(); k++) { | 376 for (int32_t k = 0; k < splitResult.GetSize(); k++) |
| 379 delete (Make_Pair*)splitResult[k]; | 377 delete splitResult[k]; |
| 380 } | |
| 381 splitResult.RemoveAll(); | |
| 382 return; | 378 return; |
| 383 } | 379 } |
| 384 AppendDataModeLenghInfo(splitResult, headerAndDataBits, tempMode, qrCode, | 380 AppendDataModeLenghInfo(splitResult, headerAndDataBits, tempMode, qrCode, |
| 385 encoding, e); | 381 encoding, e); |
| 386 if (e != BCExceptionNO) { | 382 if (e != BCExceptionNO) { |
| 387 for (int32_t k = 0; k < splitResult.GetSize(); k++) { | 383 for (int32_t k = 0; k < splitResult.GetSize(); k++) |
| 388 delete (Make_Pair*)splitResult[k]; | 384 delete splitResult[k]; |
| 389 } | |
| 390 splitResult.RemoveAll(); | |
| 391 return; | 385 return; |
| 392 } | 386 } |
| 393 numInputBytes = headerAndDataBits.sizeInBytes(); | 387 numInputBytes = headerAndDataBits.sizeInBytes(); |
| 394 TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e); | 388 TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e); |
| 395 if (e != BCExceptionNO) { | 389 for (int32_t j = 0; j < splitResult.GetSize(); j++) { |
| 396 for (int32_t k = 0; k < splitResult.GetSize(); k++) { | 390 delete splitResult[j]; |
| 397 delete (Make_Pair*)splitResult[k]; | 391 } |
| 398 } | 392 if (e != BCExceptionNO) |
| 399 splitResult.RemoveAll(); | |
| 400 return; | 393 return; |
| 401 } | 394 |
| 402 for (int32_t j = 0; j < splitResult.GetSize(); j++) { | |
| 403 delete (Make_Pair*)splitResult[j]; | |
| 404 } | |
| 405 splitResult.RemoveAll(); | |
| 406 CBC_QRCoderBitVector finalBits; | 395 CBC_QRCoderBitVector finalBits; |
| 407 finalBits.Init(); | 396 finalBits.Init(); |
| 408 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), | 397 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), |
| 409 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), | 398 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), |
| 410 &finalBits, e); | 399 &finalBits, e); |
| 411 BC_EXCEPTION_CHECK_ReturnVoid(e); | 400 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 412 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( | 401 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( |
| 413 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); | 402 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); |
| 414 matrix->Init(); | 403 matrix->Init(); |
| 415 int32_t maskPattern = ChooseMaskPattern( | 404 int32_t maskPattern = ChooseMaskPattern( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 426 BC_EXCEPTION_CHECK_ReturnVoid(e); | 415 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 427 } | 416 } |
| 428 } | 417 } |
| 429 void CBC_QRCoderEncoder::EncodeWithAutoVersion( | 418 void CBC_QRCoderEncoder::EncodeWithAutoVersion( |
| 430 const CFX_ByteString& content, | 419 const CFX_ByteString& content, |
| 431 CBC_QRCoderErrorCorrectionLevel* ecLevel, | 420 CBC_QRCoderErrorCorrectionLevel* ecLevel, |
| 432 CBC_QRCoder* qrCode, | 421 CBC_QRCoder* qrCode, |
| 433 int32_t& e) { | 422 int32_t& e) { |
| 434 CFX_ByteString encoding = "utf8"; | 423 CFX_ByteString encoding = "utf8"; |
| 435 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; | 424 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; |
| 436 CFX_PtrArray splitResult; | 425 CFX_ArrayTemplate<Make_Pair*> splitResult; |
| 437 CBC_QRCoderBitVector dataBits; | 426 CBC_QRCoderBitVector dataBits; |
| 438 dataBits.Init(); | 427 dataBits.Init(); |
| 439 SplitString(content, splitResult); | 428 SplitString(content, &splitResult); |
| 440 MergeString(splitResult, 8, e); | 429 MergeString(&splitResult, 8, e); |
| 441 BC_EXCEPTION_CHECK_ReturnVoid(e); | 430 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 442 CBC_QRCoderMode* tempMode = NULL; | 431 CBC_QRCoderMode* tempMode = NULL; |
| 443 for (int32_t i = 0; i < splitResult.GetSize(); i++) { | 432 for (int32_t i = 0; i < splitResult.GetSize(); i++) { |
| 444 AppendBytes(((Make_Pair*)splitResult[i])->m_string, | 433 AppendBytes(splitResult[i]->m_string, splitResult[i]->m_mode, &dataBits, |
| 445 ((Make_Pair*)splitResult[i])->m_mode, &dataBits, encoding, e); | 434 encoding, e); |
| 446 if (e != BCExceptionNO) { | 435 if (e != BCExceptionNO) { |
| 447 for (int32_t l = 0; l < splitResult.GetSize(); l++) { | 436 for (int32_t l = 0; l < splitResult.GetSize(); l++) |
| 448 delete (Make_Pair*)splitResult[l]; | 437 delete splitResult[l]; |
| 449 } | |
| 450 splitResult.RemoveAll(); | |
| 451 return; | 438 return; |
| 452 } | 439 } |
| 453 } | 440 } |
| 454 int32_t numInputBytes = dataBits.sizeInBytes(); | 441 int32_t numInputBytes = dataBits.sizeInBytes(); |
| 455 InitQRCode(numInputBytes, ecLevel, mode, qrCode, e); | 442 InitQRCode(numInputBytes, ecLevel, mode, qrCode, e); |
| 456 BC_EXCEPTION_CHECK_ReturnVoid(e) CBC_QRCoderBitVector headerAndDataBits; | 443 BC_EXCEPTION_CHECK_ReturnVoid(e) CBC_QRCoderBitVector headerAndDataBits; |
| 457 headerAndDataBits.Init(); | 444 headerAndDataBits.Init(); |
| 458 tempMode = NULL; | 445 tempMode = NULL; |
| 459 int32_t versionNum = qrCode->GetVersion(); | 446 int32_t versionNum = qrCode->GetVersion(); |
| 460 sign: | 447 sign: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 475 if (e1 != BCExceptionNO) { | 462 if (e1 != BCExceptionNO) { |
| 476 e = e1; | 463 e = e1; |
| 477 return; | 464 return; |
| 478 } | 465 } |
| 479 versionNum++; | 466 versionNum++; |
| 480 if (versionNum <= 40) { | 467 if (versionNum <= 40) { |
| 481 headerAndDataBits.Clear(); | 468 headerAndDataBits.Clear(); |
| 482 e = BCExceptionNO; | 469 e = BCExceptionNO; |
| 483 goto sign; | 470 goto sign; |
| 484 } else { | 471 } else { |
| 485 for (int32_t j = 0; j < splitResult.GetSize(); j++) { | 472 for (int32_t j = 0; j < splitResult.GetSize(); j++) |
| 486 delete (Make_Pair*)splitResult[j]; | 473 delete splitResult[j]; |
| 487 } | |
| 488 splitResult.RemoveAll(); | |
| 489 return; | 474 return; |
| 490 } | 475 } |
| 491 } | 476 } |
| 492 for (int32_t k = 0; k < splitResult.GetSize(); k++) { | 477 for (int32_t k = 0; k < splitResult.GetSize(); k++) |
| 493 delete (Make_Pair*)splitResult[k]; | 478 delete splitResult[k]; |
| 494 } | 479 |
| 495 splitResult.RemoveAll(); | |
| 496 CBC_QRCoderBitVector finalBits; | 480 CBC_QRCoderBitVector finalBits; |
| 497 finalBits.Init(); | 481 finalBits.Init(); |
| 498 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), | 482 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), |
| 499 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), | 483 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), |
| 500 &finalBits, e); | 484 &finalBits, e); |
| 501 BC_EXCEPTION_CHECK_ReturnVoid(e); | 485 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 502 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( | 486 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( |
| 503 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); | 487 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); |
| 504 matrix->Init(); | 488 matrix->Init(); |
| 505 int32_t maskPattern = ChooseMaskPattern( | 489 int32_t maskPattern = ChooseMaskPattern( |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 int32_t numRSBlocks, | 840 int32_t numRSBlocks, |
| 857 CBC_QRCoderBitVector* result, | 841 CBC_QRCoderBitVector* result, |
| 858 int32_t& e) { | 842 int32_t& e) { |
| 859 if (bits->sizeInBytes() != numDataBytes) { | 843 if (bits->sizeInBytes() != numDataBytes) { |
| 860 e = BCExceptionBitsBytesNotMatch; | 844 e = BCExceptionBitsBytesNotMatch; |
| 861 BC_EXCEPTION_CHECK_ReturnVoid(e); | 845 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 862 } | 846 } |
| 863 int32_t dataBytesOffset = 0; | 847 int32_t dataBytesOffset = 0; |
| 864 int32_t maxNumDataBytes = 0; | 848 int32_t maxNumDataBytes = 0; |
| 865 int32_t maxNumEcBytes = 0; | 849 int32_t maxNumEcBytes = 0; |
| 866 CFX_PtrArray blocks; | 850 CFX_ArrayTemplate<CBC_QRCoderBlockPair*> blocks; |
| 867 int32_t i; | 851 int32_t i; |
| 868 for (i = 0; i < numRSBlocks; i++) { | 852 for (i = 0; i < numRSBlocks; i++) { |
| 869 int32_t numDataBytesInBlock; | 853 int32_t numDataBytesInBlock; |
| 870 int32_t numEcBytesInBlosk; | 854 int32_t numEcBytesInBlosk; |
| 871 GetNumDataBytesAndNumECBytesForBlockID(numTotalBytes, numDataBytes, | 855 GetNumDataBytesAndNumECBytesForBlockID(numTotalBytes, numDataBytes, |
| 872 numRSBlocks, i, numDataBytesInBlock, | 856 numRSBlocks, i, numDataBytesInBlock, |
| 873 numEcBytesInBlosk); | 857 numEcBytesInBlosk); |
| 874 CBC_CommonByteArray* dataBytes = new CBC_CommonByteArray; | 858 CBC_CommonByteArray* dataBytes = new CBC_CommonByteArray; |
| 875 dataBytes->Set(bits->GetArray(), dataBytesOffset, numDataBytesInBlock); | 859 dataBytes->Set(bits->GetArray(), dataBytesOffset, numDataBytesInBlock); |
| 876 CBC_CommonByteArray* ecBytes = | 860 CBC_CommonByteArray* ecBytes = |
| 877 GenerateECBytes(dataBytes, numEcBytesInBlosk, e); | 861 GenerateECBytes(dataBytes, numEcBytesInBlosk, e); |
| 878 BC_EXCEPTION_CHECK_ReturnVoid(e); | 862 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 879 blocks.Add(new CBC_QRCoderBlockPair(dataBytes, ecBytes)); | 863 blocks.Add(new CBC_QRCoderBlockPair(dataBytes, ecBytes)); |
| 880 maxNumDataBytes = std::max(maxNumDataBytes, dataBytes->Size()); | 864 maxNumDataBytes = std::max(maxNumDataBytes, dataBytes->Size()); |
| 881 maxNumEcBytes = std::max(maxNumEcBytes, ecBytes->Size()); | 865 maxNumEcBytes = std::max(maxNumEcBytes, ecBytes->Size()); |
| 882 dataBytesOffset += numDataBytesInBlock; | 866 dataBytesOffset += numDataBytesInBlock; |
| 883 } | 867 } |
| 884 if (numDataBytes != dataBytesOffset) { | 868 if (numDataBytes != dataBytesOffset) { |
| 885 e = BCExceptionBytesNotMatchOffset; | 869 e = BCExceptionBytesNotMatchOffset; |
| 886 BC_EXCEPTION_CHECK_ReturnVoid(e); | 870 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 887 } | 871 } |
| 888 for (int32_t x = 0; x < maxNumDataBytes; x++) { | 872 for (int32_t x = 0; x < maxNumDataBytes; x++) { |
| 889 for (int32_t j = 0; j < blocks.GetSize(); j++) { | 873 for (int32_t j = 0; j < blocks.GetSize(); j++) { |
| 890 CBC_CommonByteArray* dataBytes = | 874 CBC_CommonByteArray* dataBytes = blocks[j]->GetDataBytes(); |
| 891 ((CBC_QRCoderBlockPair*)blocks[j])->GetDataBytes(); | |
| 892 if (x < dataBytes->Size()) { | 875 if (x < dataBytes->Size()) { |
| 893 result->AppendBits(dataBytes->At(x), 8, e); | 876 result->AppendBits(dataBytes->At(x), 8, e); |
| 894 BC_EXCEPTION_CHECK_ReturnVoid(e); | 877 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 895 } | 878 } |
| 896 } | 879 } |
| 897 } | 880 } |
| 898 for (int32_t y = 0; y < maxNumEcBytes; y++) { | 881 for (int32_t y = 0; y < maxNumEcBytes; y++) { |
| 899 for (int32_t l = 0; l < blocks.GetSize(); l++) { | 882 for (int32_t l = 0; l < blocks.GetSize(); l++) { |
| 900 CBC_CommonByteArray* ecBytes = | 883 CBC_CommonByteArray* ecBytes = blocks[l]->GetErrorCorrectionBytes(); |
| 901 ((CBC_QRCoderBlockPair*)blocks[l])->GetErrorCorrectionBytes(); | |
| 902 if (y < ecBytes->Size()) { | 884 if (y < ecBytes->Size()) { |
| 903 result->AppendBits(ecBytes->At(y), 8, e); | 885 result->AppendBits(ecBytes->At(y), 8, e); |
| 904 BC_EXCEPTION_CHECK_ReturnVoid(e); | 886 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 905 } | 887 } |
| 906 } | 888 } |
| 907 } | 889 } |
| 908 for (int32_t k = 0; k < blocks.GetSize(); k++) { | 890 for (int32_t k = 0; k < blocks.GetSize(); k++) { |
| 909 delete (CBC_QRCoderBlockPair*)blocks[k]; | 891 delete blocks[k]; |
| 910 } | 892 } |
| 911 if (numTotalBytes != result->sizeInBytes()) { | 893 if (numTotalBytes != result->sizeInBytes()) { |
| 912 e = BCExceptionSizeInBytesDiffer; | 894 e = BCExceptionSizeInBytesDiffer; |
| 913 BC_EXCEPTION_CHECK_ReturnVoid(e); | 895 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 914 } | 896 } |
| 915 } | 897 } |
| 916 void CBC_QRCoderEncoder::GetNumDataBytesAndNumECBytesForBlockID( | 898 void CBC_QRCoderEncoder::GetNumDataBytesAndNumECBytesForBlockID( |
| 917 int32_t numTotalBytes, | 899 int32_t numTotalBytes, |
| 918 int32_t numDataBytes, | 900 int32_t numDataBytes, |
| 919 int32_t numRSBlocks, | 901 int32_t numRSBlocks, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeFild); | 934 CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeFild); |
| 953 encode.Init(); | 935 encode.Init(); |
| 954 encode.Encode(&toEncode, numEcBytesInBlock, e); | 936 encode.Encode(&toEncode, numEcBytesInBlock, e); |
| 955 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 937 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 956 CBC_CommonByteArray* ecBytes = new CBC_CommonByteArray(numEcBytesInBlock); | 938 CBC_CommonByteArray* ecBytes = new CBC_CommonByteArray(numEcBytesInBlock); |
| 957 for (int32_t j = 0; j < numEcBytesInBlock; j++) { | 939 for (int32_t j = 0; j < numEcBytesInBlock; j++) { |
| 958 ecBytes->Set(j, toEncode[numDataBytes + j]); | 940 ecBytes->Set(j, toEncode[numDataBytes + j]); |
| 959 } | 941 } |
| 960 return ecBytes; | 942 return ecBytes; |
| 961 } | 943 } |
| OLD | NEW |