| 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 2007 ZXing authors | 8 * Copyright 2007 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 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 #include "../barcode.h" | 23 #include "../barcode.h" |
| 24 #include "../utils.h" | 24 #include "../utils.h" |
| 25 #include "../common/BC_CommonBitMatrix.h" | 25 #include "../common/BC_CommonBitMatrix.h" |
| 26 #include "BC_QRCoderECB.h" | 26 #include "BC_QRCoderECB.h" |
| 27 #include "BC_QRCoderFormatInformation.h" | 27 #include "BC_QRCoderFormatInformation.h" |
| 28 #include "BC_QRCoderErrorCorrectionLevel.h" | 28 #include "BC_QRCoderErrorCorrectionLevel.h" |
| 29 #include "BC_QRCoderBitVector.h" | 29 #include "BC_QRCoderBitVector.h" |
| 30 #include "BC_QRCoderECBlocks.h" | 30 #include "BC_QRCoderECBlocks.h" |
| 31 #include "BC_QRCoderVersion.h" | 31 #include "BC_QRCoderVersion.h" |
| 32 const FX_INT32 CBC_QRCoderVersion::VERSION_DECODE_INFO[] = { | 32 const int32_t CBC_QRCoderVersion::VERSION_DECODE_INFO[] = { |
| 33 0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, | 33 0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, |
| 34 0x0C762, 0x0D847, 0x0E60D, 0x0F928, 0x10B78, | 34 0x0C762, 0x0D847, 0x0E60D, 0x0F928, 0x10B78, |
| 35 0x1145D, 0x12A17, 0x13532, 0x149A6, 0x15683, | 35 0x1145D, 0x12A17, 0x13532, 0x149A6, 0x15683, |
| 36 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, | 36 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, |
| 37 0x1B08E, 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, | 37 0x1B08E, 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, |
| 38 0x209D5, 0x216F0, 0x228BA, 0x2379F, 0x24B0B, | 38 0x209D5, 0x216F0, 0x228BA, 0x2379F, 0x24B0B, |
| 39 0x2542E, 0x26A64, 0x27541, 0x28C69 | 39 0x2542E, 0x26A64, 0x27541, 0x28C69 |
| 40 }; | 40 }; |
| 41 CFX_PtrArray *CBC_QRCoderVersion::VERSION = NULL; | 41 CFX_PtrArray *CBC_QRCoderVersion::VERSION = NULL; |
| 42 void CBC_QRCoderVersion::Initialize() | 42 void CBC_QRCoderVersion::Initialize() |
| 43 { | 43 { |
| 44 VERSION = FX_NEW CFX_PtrArray(); | 44 VERSION = FX_NEW CFX_PtrArray(); |
| 45 } | 45 } |
| 46 void CBC_QRCoderVersion::Finalize() | 46 void CBC_QRCoderVersion::Finalize() |
| 47 { | 47 { |
| 48 for(FX_INT32 i = 0 ; i < VERSION->GetSize(); i++) { | 48 for(int32_t i = 0 ; i < VERSION->GetSize(); i++) { |
| 49 CBC_QRCoderVersion* v = (CBC_QRCoderVersion*)(VERSION->GetAt(i)); | 49 CBC_QRCoderVersion* v = (CBC_QRCoderVersion*)(VERSION->GetAt(i)); |
| 50 delete v; | 50 delete v; |
| 51 } | 51 } |
| 52 delete VERSION; | 52 delete VERSION; |
| 53 } | 53 } |
| 54 CBC_QRCoderVersion::CBC_QRCoderVersion(FX_INT32 versionNumber, | 54 CBC_QRCoderVersion::CBC_QRCoderVersion(int32_t versionNumber, |
| 55 CBC_QRCoderECBlocks* ecBlocks1, | 55 CBC_QRCoderECBlocks* ecBlocks1, |
| 56 CBC_QRCoderECBlocks* ecBlocks2, | 56 CBC_QRCoderECBlocks* ecBlocks2, |
| 57 CBC_QRCoderECBlocks* ecBlocks3, | 57 CBC_QRCoderECBlocks* ecBlocks3, |
| 58 CBC_QRCoderECBlocks* ecBlocks4) | 58 CBC_QRCoderECBlocks* ecBlocks4) |
| 59 { | 59 { |
| 60 m_versionNumber = versionNumber; | 60 m_versionNumber = versionNumber; |
| 61 m_ecBlocks.Add(ecBlocks1); | 61 m_ecBlocks.Add(ecBlocks1); |
| 62 m_ecBlocks.Add(ecBlocks2); | 62 m_ecBlocks.Add(ecBlocks2); |
| 63 m_ecBlocks.Add(ecBlocks3); | 63 m_ecBlocks.Add(ecBlocks3); |
| 64 m_ecBlocks.Add(ecBlocks4); | 64 m_ecBlocks.Add(ecBlocks4); |
| 65 FX_INT32 total = 0; | 65 int32_t total = 0; |
| 66 FX_INT32 ecCodeWords = ecBlocks1->GetECCodeWordsPerBlock(); | 66 int32_t ecCodeWords = ecBlocks1->GetECCodeWordsPerBlock(); |
| 67 CFX_PtrArray* ecbArray = ecBlocks1->GetECBlocks(); | 67 CFX_PtrArray* ecbArray = ecBlocks1->GetECBlocks(); |
| 68 for(FX_INT32 i = 0; i < ecbArray->GetSize(); i++) { | 68 for(int32_t i = 0; i < ecbArray->GetSize(); i++) { |
| 69 CBC_QRCoderECB* ecBlock = (CBC_QRCoderECB*)((*ecbArray)[i]); | 69 CBC_QRCoderECB* ecBlock = (CBC_QRCoderECB*)((*ecbArray)[i]); |
| 70 total += ecBlock->GetCount() * (ecBlock->GetDataCodeWords() + ecCodeWord
s); | 70 total += ecBlock->GetCount() * (ecBlock->GetDataCodeWords() + ecCodeWord
s); |
| 71 } | 71 } |
| 72 m_totalCodeWords = total; | 72 m_totalCodeWords = total; |
| 73 switch(versionNumber) { | 73 switch(versionNumber) { |
| 74 case 1: | 74 case 1: |
| 75 break; | 75 break; |
| 76 case 2: | 76 case 2: |
| 77 m_alignmentPatternCenters.Add(6); | 77 m_alignmentPatternCenters.Add(6); |
| 78 m_alignmentPatternCenters.Add(18); | 78 m_alignmentPatternCenters.Add(18); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 m_alignmentPatternCenters.Add(86); | 327 m_alignmentPatternCenters.Add(86); |
| 328 m_alignmentPatternCenters.Add(114); | 328 m_alignmentPatternCenters.Add(114); |
| 329 m_alignmentPatternCenters.Add(142); | 329 m_alignmentPatternCenters.Add(142); |
| 330 m_alignmentPatternCenters.Add(170); | 330 m_alignmentPatternCenters.Add(170); |
| 331 break; | 331 break; |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 CBC_QRCoderVersion::~CBC_QRCoderVersion() | 334 CBC_QRCoderVersion::~CBC_QRCoderVersion() |
| 335 { | 335 { |
| 336 if(m_ecBlocks.GetSize() != 0) { | 336 if(m_ecBlocks.GetSize() != 0) { |
| 337 FX_INT32 itBeg = 0; | 337 int32_t itBeg = 0; |
| 338 FX_INT32 itEnd = m_ecBlocks.GetSize(); | 338 int32_t itEnd = m_ecBlocks.GetSize(); |
| 339 while(itBeg != itEnd) { | 339 while(itBeg != itEnd) { |
| 340 delete ( (CBC_QRCoderECBlocks*)(m_ecBlocks[itBeg]) ); | 340 delete ( (CBC_QRCoderECBlocks*)(m_ecBlocks[itBeg]) ); |
| 341 itBeg++; | 341 itBeg++; |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 FX_INT32 CBC_QRCoderVersion::GetVersionNumber() | 345 int32_t CBC_QRCoderVersion::GetVersionNumber() |
| 346 { | 346 { |
| 347 return m_versionNumber; | 347 return m_versionNumber; |
| 348 } | 348 } |
| 349 CFX_Int32Array* CBC_QRCoderVersion::GetAlignmentPatternCenters() | 349 CFX_Int32Array* CBC_QRCoderVersion::GetAlignmentPatternCenters() |
| 350 { | 350 { |
| 351 return &m_alignmentPatternCenters; | 351 return &m_alignmentPatternCenters; |
| 352 } | 352 } |
| 353 FX_INT32 CBC_QRCoderVersion::GetTotalCodeWords() | 353 int32_t CBC_QRCoderVersion::GetTotalCodeWords() |
| 354 { | 354 { |
| 355 return m_totalCodeWords; | 355 return m_totalCodeWords; |
| 356 } | 356 } |
| 357 FX_INT32 CBC_QRCoderVersion::GetDimensionForVersion() | 357 int32_t CBC_QRCoderVersion::GetDimensionForVersion() |
| 358 { | 358 { |
| 359 return 17 + 4 * m_versionNumber; | 359 return 17 + 4 * m_versionNumber; |
| 360 } | 360 } |
| 361 CBC_QRCoderECBlocks* CBC_QRCoderVersion::GetECBlocksForLevel(CBC_QRCoderErrorCor
rectionLevel *ecLevel) | 361 CBC_QRCoderECBlocks* CBC_QRCoderVersion::GetECBlocksForLevel(CBC_QRCoderErrorCor
rectionLevel *ecLevel) |
| 362 { | 362 { |
| 363 return (CBC_QRCoderECBlocks*)m_ecBlocks[ecLevel->Ordinal()]; | 363 return (CBC_QRCoderECBlocks*)m_ecBlocks[ecLevel->Ordinal()]; |
| 364 } | 364 } |
| 365 CBC_QRCoderVersion* CBC_QRCoderVersion::GetProvisionalVersionForDimension(FX_INT
32 dimension, FX_INT32 &e) | 365 CBC_QRCoderVersion* CBC_QRCoderVersion::GetProvisionalVersionForDimension(int32_
t dimension, int32_t &e) |
| 366 { | 366 { |
| 367 if((dimension % 4) != 1) { | 367 if((dimension % 4) != 1) { |
| 368 e = BCExceptionRead; | 368 e = BCExceptionRead; |
| 369 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 369 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 370 } | 370 } |
| 371 CBC_QRCoderVersion* qcv = GetVersionForNumber((dimension - 17) >> 2, e); | 371 CBC_QRCoderVersion* qcv = GetVersionForNumber((dimension - 17) >> 2, e); |
| 372 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 372 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 373 return qcv; | 373 return qcv; |
| 374 } | 374 } |
| 375 CBC_QRCoderVersion* CBC_QRCoderVersion::DecodeVersionInformation(FX_INT32 versio
nBits, FX_INT32 &e) | 375 CBC_QRCoderVersion* CBC_QRCoderVersion::DecodeVersionInformation(int32_t version
Bits, int32_t &e) |
| 376 { | 376 { |
| 377 FX_INT32 bestDifference = FXSYS_IntMax; | 377 int32_t bestDifference = FXSYS_IntMax; |
| 378 FX_INT32 bestVersion = 0; | 378 int32_t bestVersion = 0; |
| 379 for (FX_INT32 i = 0; i < 34; i++) { | 379 for (int32_t i = 0; i < 34; i++) { |
| 380 FX_INT32 targetVersion = VERSION_DECODE_INFO[i]; | 380 int32_t targetVersion = VERSION_DECODE_INFO[i]; |
| 381 if(targetVersion == versionBits) { | 381 if(targetVersion == versionBits) { |
| 382 CBC_QRCoderVersion* qcv = GetVersionForNumber(i + 7, e); | 382 CBC_QRCoderVersion* qcv = GetVersionForNumber(i + 7, e); |
| 383 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 383 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 384 return qcv; | 384 return qcv; |
| 385 } | 385 } |
| 386 FX_INT32 bitsDifference = CBC_QRCoderFormatInformation::NumBitsDiffering
(versionBits, targetVersion); | 386 int32_t bitsDifference = CBC_QRCoderFormatInformation::NumBitsDiffering(
versionBits, targetVersion); |
| 387 if(bitsDifference < bestDifference) { | 387 if(bitsDifference < bestDifference) { |
| 388 bestVersion = i + 7; | 388 bestVersion = i + 7; |
| 389 bestDifference = bitsDifference; | 389 bestDifference = bitsDifference; |
| 390 } | 390 } |
| 391 } | 391 } |
| 392 if(bestDifference <= 3) { | 392 if(bestDifference <= 3) { |
| 393 CBC_QRCoderVersion* qcv = GetVersionForNumber(bestVersion, e); | 393 CBC_QRCoderVersion* qcv = GetVersionForNumber(bestVersion, e); |
| 394 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 394 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 395 return qcv; | 395 return qcv; |
| 396 } | 396 } |
| 397 return NULL; | 397 return NULL; |
| 398 } | 398 } |
| 399 CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(FX_INT32 &e) | 399 CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(int32_t &e) |
| 400 { | 400 { |
| 401 FX_INT32 dimension = GetDimensionForVersion(); | 401 int32_t dimension = GetDimensionForVersion(); |
| 402 CBC_CommonBitMatrix* bitMatrix = FX_NEW CBC_CommonBitMatrix(); | 402 CBC_CommonBitMatrix* bitMatrix = FX_NEW CBC_CommonBitMatrix(); |
| 403 bitMatrix->Init(dimension); | 403 bitMatrix->Init(dimension); |
| 404 bitMatrix->SetRegion(0, 0 , 9, 9, e); | 404 bitMatrix->SetRegion(0, 0 , 9, 9, e); |
| 405 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 405 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 406 bitMatrix->SetRegion(dimension - 8, 0, 8, 9, e); | 406 bitMatrix->SetRegion(dimension - 8, 0, 8, 9, e); |
| 407 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 407 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 408 bitMatrix->SetRegion(0, dimension - 8, 9, 8, e); | 408 bitMatrix->SetRegion(0, dimension - 8, 9, 8, e); |
| 409 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 409 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 410 FX_INT32 max = m_alignmentPatternCenters.GetSize(); | 410 int32_t max = m_alignmentPatternCenters.GetSize(); |
| 411 for (FX_INT32 x = 0; x < max; x++) { | 411 for (int32_t x = 0; x < max; x++) { |
| 412 FX_INT32 i = m_alignmentPatternCenters[x] - 2; | 412 int32_t i = m_alignmentPatternCenters[x] - 2; |
| 413 for (FX_INT32 y = 0; y < max; y++) { | 413 for (int32_t y = 0; y < max; y++) { |
| 414 if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)
) { | 414 if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)
) { |
| 415 continue; | 415 continue; |
| 416 } | 416 } |
| 417 bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5, e); | 417 bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5, e); |
| 418 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 418 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 bitMatrix->SetRegion(6, 9, 1, dimension - 17, e); | 421 bitMatrix->SetRegion(6, 9, 1, dimension - 17, e); |
| 422 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 422 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 423 bitMatrix->SetRegion(9, 6, dimension - 17, 1, e); | 423 bitMatrix->SetRegion(9, 6, dimension - 17, 1, e); |
| 424 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 424 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 425 if (m_versionNumber > 6) { | 425 if (m_versionNumber > 6) { |
| 426 bitMatrix->SetRegion(dimension - 11, 0, 3, 6, e); | 426 bitMatrix->SetRegion(dimension - 11, 0, 3, 6, e); |
| 427 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 427 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 428 bitMatrix->SetRegion(0, dimension - 11, 6, 3, e); | 428 bitMatrix->SetRegion(0, dimension - 11, 6, 3, e); |
| 429 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 429 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 430 } | 430 } |
| 431 return bitMatrix; | 431 return bitMatrix; |
| 432 } | 432 } |
| 433 CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber(FX_INT32 versionNumb
er, FX_INT32 &e) | 433 CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber(int32_t versionNumbe
r, int32_t &e) |
| 434 { | 434 { |
| 435 if(VERSION->GetSize() == 0) { | 435 if(VERSION->GetSize() == 0) { |
| 436 VERSION->Add(FX_NEW CBC_QRCoderVersion(1, | 436 VERSION->Add(FX_NEW CBC_QRCoderVersion(1, |
| 437 FX_NEW CBC_QRCoderECBlocks(7, FX_
NEW CBC_QRCoderECB(1, 19)), | 437 FX_NEW CBC_QRCoderECBlocks(7, FX_
NEW CBC_QRCoderECB(1, 19)), |
| 438 FX_NEW CBC_QRCoderECBlocks(10, FX
_NEW CBC_QRCoderECB(1, 16)), | 438 FX_NEW CBC_QRCoderECBlocks(10, FX
_NEW CBC_QRCoderECB(1, 16)), |
| 439 FX_NEW CBC_QRCoderECBlocks(13, FX
_NEW CBC_QRCoderECB(1, 13)), | 439 FX_NEW CBC_QRCoderECBlocks(13, FX
_NEW CBC_QRCoderECB(1, 13)), |
| 440 FX_NEW CBC_QRCoderECBlocks(17, FX
_NEW CBC_QRCoderECB(1, 9)))); | 440 FX_NEW CBC_QRCoderECBlocks(17, FX
_NEW CBC_QRCoderECB(1, 9)))); |
| 441 VERSION->Add(FX_NEW CBC_QRCoderVersion(2, | 441 VERSION->Add(FX_NEW CBC_QRCoderVersion(2, |
| 442 FX_NEW CBC_QRCoderECBlocks(10, FX
_NEW CBC_QRCoderECB(1, 34)), | 442 FX_NEW CBC_QRCoderECBlocks(10, FX
_NEW CBC_QRCoderECB(1, 34)), |
| 443 FX_NEW CBC_QRCoderECBlocks(16, FX
_NEW CBC_QRCoderECB(1, 28)), | 443 FX_NEW CBC_QRCoderECBlocks(16, FX
_NEW CBC_QRCoderECB(1, 28)), |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 FX_NEW CBC_QRCoderECB(61,
16)))); | 763 FX_NEW CBC_QRCoderECB(61,
16)))); |
| 764 } | 764 } |
| 765 if(versionNumber < 1 || versionNumber > 40) { | 765 if(versionNumber < 1 || versionNumber > 40) { |
| 766 e = BCExceptionIllegalArgument; | 766 e = BCExceptionIllegalArgument; |
| 767 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 767 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 768 } | 768 } |
| 769 return (CBC_QRCoderVersion*)(*VERSION)[versionNumber - 1]; | 769 return (CBC_QRCoderVersion*)(*VERSION)[versionNumber - 1]; |
| 770 } | 770 } |
| 771 void CBC_QRCoderVersion::Destroy() | 771 void CBC_QRCoderVersion::Destroy() |
| 772 { | 772 { |
| 773 FX_INT32 i; | 773 int32_t i; |
| 774 for(i = 0; i < VERSION->GetSize(); i++) { | 774 for(i = 0; i < VERSION->GetSize(); i++) { |
| 775 delete ( (CBC_QRCoderVersion*)(*VERSION)[i] ); | 775 delete ( (CBC_QRCoderVersion*)(*VERSION)[i] ); |
| 776 } | 776 } |
| 777 } | 777 } |
| OLD | NEW |