Beispiel #1
0
CFX_PtrArray* CBC_QRDataBlock::GetDataBlocks(
    CFX_ByteArray* rawCodewords,
    CBC_QRCoderVersion* version,
    CBC_QRCoderErrorCorrectionLevel* ecLevel,
    int32_t& e) {
  if (rawCodewords->GetSize() != version->GetTotalCodeWords()) {
    e = BCExceptionIllegalArgument;
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  }
  CBC_QRCoderECBlocks* ecBlocks = version->GetECBlocksForLevel(ecLevel);
  int32_t totalBlocks = 0;
  CFX_PtrArray* ecBlockArray = ecBlocks->GetECBlocks();
  int32_t i = 0;
  for (i = 0; i < ecBlockArray->GetSize(); i++) {
    totalBlocks += ((CBC_QRCoderECB*)(*ecBlockArray)[i])->GetCount();
  }
  CFX_PtrArray* datablock = new CFX_PtrArray();
  datablock->SetSize(totalBlocks);
  CBC_AutoPtr<CFX_PtrArray> result(datablock);
  int32_t numResultBlocks = 0;
  for (int32_t j = 0; j < ecBlockArray->GetSize(); j++) {
    CBC_QRCoderECB* ecBlock = (CBC_QRCoderECB*)(*ecBlockArray)[j];
    for (int32_t k = 0; k < ecBlock->GetCount(); k++) {
      int32_t numDataCodewords = ecBlock->GetDataCodeWords();
      int32_t numBlockCodewords =
          ecBlocks->GetECCodeWordsPerBlock() + numDataCodewords;
      CFX_ByteArray* bytearray = new CFX_ByteArray();
      bytearray->SetSize(numBlockCodewords);
      (*result)[numResultBlocks++] =
          new CBC_QRDataBlock(numDataCodewords, bytearray);
    }
  }
  int32_t shorterBlocksTotalCodewords =
      ((CBC_QRDataBlock*)(*result)[0])->m_codewords->GetSize();
  int32_t longerBlocksStartAt = result->GetSize() - 1;
  while (longerBlocksStartAt >= 0) {
    int32_t numCodewords = ((CBC_QRDataBlock*)(*result)[longerBlocksStartAt])
                               ->m_codewords->GetSize();
    if (numCodewords == shorterBlocksTotalCodewords) {
      break;
    }
    longerBlocksStartAt--;
  }
  longerBlocksStartAt++;
  int32_t shorterBlocksNumDataCodewords =
      shorterBlocksTotalCodewords - ecBlocks->GetECCodeWordsPerBlock();
  int32_t rawCodewordsOffset = 0;
  int32_t x = 0;
  for (int32_t k = 0; k < shorterBlocksNumDataCodewords; k++) {
    for (x = 0; x < numResultBlocks; x++) {
      (*(((CBC_QRDataBlock*)(*result)[x])->m_codewords))[k] =
          (*rawCodewords)[rawCodewordsOffset++];
    }
  }
  for (x = longerBlocksStartAt; x < numResultBlocks; x++) {
    (*(((CBC_QRDataBlock*)(*result)[x])
           ->m_codewords))[shorterBlocksNumDataCodewords] =
        (*rawCodewords)[rawCodewordsOffset++];
  }
  int32_t max = ((CBC_QRDataBlock*)(*result)[0])->m_codewords->GetSize();
  for (i = shorterBlocksNumDataCodewords; i < max; i++) {
    for (int32_t y = 0; y < numResultBlocks; y++) {
      int32_t iOffset = y < longerBlocksStartAt ? i : i + 1;
      (*(((CBC_QRDataBlock*)(*result)[y])->m_codewords))[iOffset] =
          (*rawCodewords)[rawCodewordsOffset++];
    }
  }
  return result.release();
}
CBC_QRCoderVersion::CBC_QRCoderVersion(int32_t versionNumber,
                                       CBC_QRCoderECBlocks* ecBlocks1,
                                       CBC_QRCoderECBlocks* ecBlocks2,
                                       CBC_QRCoderECBlocks* ecBlocks3,
                                       CBC_QRCoderECBlocks* ecBlocks4) {
  m_versionNumber = versionNumber;
  m_ecBlocks.Add(ecBlocks1);
  m_ecBlocks.Add(ecBlocks2);
  m_ecBlocks.Add(ecBlocks3);
  m_ecBlocks.Add(ecBlocks4);
  int32_t total = 0;
  int32_t ecCodeWords = ecBlocks1->GetECCodeWordsPerBlock();
  CFX_PtrArray* ecbArray = ecBlocks1->GetECBlocks();
  for (int32_t i = 0; i < ecbArray->GetSize(); i++) {
    CBC_QRCoderECB* ecBlock = (CBC_QRCoderECB*)((*ecbArray)[i]);
    total += ecBlock->GetCount() * (ecBlock->GetDataCodeWords() + ecCodeWords);
  }
  m_totalCodeWords = total;
  switch (versionNumber) {
    case 1:
      break;
    case 2:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(18);
      break;
    case 3:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(22);
      break;
    case 4:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(26);
      break;
    case 5:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      break;
    case 6:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(34);
      break;
    case 7:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(22);
      m_alignmentPatternCenters.Add(38);
      break;
    case 8:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(24);
      m_alignmentPatternCenters.Add(42);
      break;
    case 9:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(26);
      m_alignmentPatternCenters.Add(46);
      break;
    case 10:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(28);
      m_alignmentPatternCenters.Add(50);
      break;
    case 11:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      m_alignmentPatternCenters.Add(54);
      break;
    case 12:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(32);
      m_alignmentPatternCenters.Add(58);
      break;
    case 13:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(34);
      m_alignmentPatternCenters.Add(62);
      break;
    case 14:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(26);
      m_alignmentPatternCenters.Add(46);
      m_alignmentPatternCenters.Add(66);
      break;
    case 15:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(26);
      m_alignmentPatternCenters.Add(48);
      m_alignmentPatternCenters.Add(70);
      break;
    case 16:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(26);
      m_alignmentPatternCenters.Add(50);
      m_alignmentPatternCenters.Add(74);
      break;
    case 17:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      m_alignmentPatternCenters.Add(54);
      m_alignmentPatternCenters.Add(78);
      break;
    case 18:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      m_alignmentPatternCenters.Add(56);
      m_alignmentPatternCenters.Add(82);
      break;
    case 19:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      m_alignmentPatternCenters.Add(58);
      m_alignmentPatternCenters.Add(86);
      break;
    case 20:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(34);
      m_alignmentPatternCenters.Add(62);
      m_alignmentPatternCenters.Add(90);
      break;
    case 21:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(28);
      m_alignmentPatternCenters.Add(50);
      m_alignmentPatternCenters.Add(72);
      m_alignmentPatternCenters.Add(94);
      break;
    case 22:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(26);
      m_alignmentPatternCenters.Add(50);
      m_alignmentPatternCenters.Add(74);
      m_alignmentPatternCenters.Add(98);
      break;
    case 23:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      m_alignmentPatternCenters.Add(54);
      m_alignmentPatternCenters.Add(74);
      m_alignmentPatternCenters.Add(102);
      break;
    case 24:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(28);
      m_alignmentPatternCenters.Add(54);
      m_alignmentPatternCenters.Add(80);
      m_alignmentPatternCenters.Add(106);
      break;
    case 25:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(32);
      m_alignmentPatternCenters.Add(58);
      m_alignmentPatternCenters.Add(84);
      m_alignmentPatternCenters.Add(110);
      break;
    case 26:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      m_alignmentPatternCenters.Add(58);
      m_alignmentPatternCenters.Add(86);
      m_alignmentPatternCenters.Add(114);
      break;
    case 27:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(34);
      m_alignmentPatternCenters.Add(62);
      m_alignmentPatternCenters.Add(90);
      m_alignmentPatternCenters.Add(118);
      break;
    case 28:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(26);
      m_alignmentPatternCenters.Add(50);
      m_alignmentPatternCenters.Add(74);
      m_alignmentPatternCenters.Add(98);
      m_alignmentPatternCenters.Add(122);
      break;
    case 29:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      m_alignmentPatternCenters.Add(54);
      m_alignmentPatternCenters.Add(78);
      m_alignmentPatternCenters.Add(102);
      m_alignmentPatternCenters.Add(126);
      break;
    case 30:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(26);
      m_alignmentPatternCenters.Add(52);
      m_alignmentPatternCenters.Add(78);
      m_alignmentPatternCenters.Add(104);
      m_alignmentPatternCenters.Add(130);
      break;
    case 31:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      m_alignmentPatternCenters.Add(56);
      m_alignmentPatternCenters.Add(82);
      m_alignmentPatternCenters.Add(108);
      m_alignmentPatternCenters.Add(134);
      break;
    case 32:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(34);
      m_alignmentPatternCenters.Add(60);
      m_alignmentPatternCenters.Add(86);
      m_alignmentPatternCenters.Add(112);
      m_alignmentPatternCenters.Add(138);
      break;
    case 33:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      m_alignmentPatternCenters.Add(58);
      m_alignmentPatternCenters.Add(86);
      m_alignmentPatternCenters.Add(114);
      m_alignmentPatternCenters.Add(142);
      break;
    case 34:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(34);
      m_alignmentPatternCenters.Add(62);
      m_alignmentPatternCenters.Add(90);
      m_alignmentPatternCenters.Add(118);
      m_alignmentPatternCenters.Add(146);
      break;
    case 35:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      m_alignmentPatternCenters.Add(54);
      m_alignmentPatternCenters.Add(78);
      m_alignmentPatternCenters.Add(102);
      m_alignmentPatternCenters.Add(126);
      m_alignmentPatternCenters.Add(150);
      break;
    case 36:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(24);
      m_alignmentPatternCenters.Add(50);
      m_alignmentPatternCenters.Add(76);
      m_alignmentPatternCenters.Add(102);
      m_alignmentPatternCenters.Add(128);
      m_alignmentPatternCenters.Add(154);
      break;
    case 37:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(28);
      m_alignmentPatternCenters.Add(54);
      m_alignmentPatternCenters.Add(80);
      m_alignmentPatternCenters.Add(106);
      m_alignmentPatternCenters.Add(132);
      m_alignmentPatternCenters.Add(158);
      break;
    case 38:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(32);
      m_alignmentPatternCenters.Add(58);
      m_alignmentPatternCenters.Add(84);
      m_alignmentPatternCenters.Add(110);
      m_alignmentPatternCenters.Add(136);
      m_alignmentPatternCenters.Add(162);
      break;
    case 39:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(26);
      m_alignmentPatternCenters.Add(54);
      m_alignmentPatternCenters.Add(82);
      m_alignmentPatternCenters.Add(110);
      m_alignmentPatternCenters.Add(138);
      m_alignmentPatternCenters.Add(166);
      break;
    case 40:
      m_alignmentPatternCenters.Add(6);
      m_alignmentPatternCenters.Add(30);
      m_alignmentPatternCenters.Add(58);
      m_alignmentPatternCenters.Add(86);
      m_alignmentPatternCenters.Add(114);
      m_alignmentPatternCenters.Add(142);
      m_alignmentPatternCenters.Add(170);
      break;
  }
}