Ejemplo n.º 1
0
uint8_t* CBC_OnedEAN8Writer::Encode(const CFX_ByteString& contents,
                                    BCFORMAT format,
                                    int32_t& outWidth,
                                    int32_t& outHeight,
                                    int32_t hints,
                                    int32_t& e) {
  if (format != BCFORMAT_EAN_8) {
    e = BCExceptionOnlyEncodeEAN_8;
    return nullptr;
  }
  uint8_t* ret =
      CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
  return ret;
}
Ejemplo n.º 2
0
CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial(
    int32_t degree,
    int32_t coefficient,
    int32_t& e) {
  if (degree < 0) {
    e = BCExceptionDegreeIsNegative;
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  }
  if (coefficient == 0) {
    CBC_ReedSolomonGF256Poly* temp = m_field->GetZero()->Clone(e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    return temp;
  }
  int32_t size = m_coefficients.GetSize();
  CFX_Int32Array product;
  product.SetSize(size + degree);
  for (int32_t i = 0; i < size; i++) {
    product[i] = (m_field->Multiply(m_coefficients[i], coefficient));
  }
  CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly();
  temp->Init(m_field, &product, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  return temp;
}
Ejemplo n.º 3
0
uint8_t* CBC_OneDimWriter::Encode(const CFX_ByteString& contents,
                                  BCFORMAT format,
                                  int32_t& outWidth,
                                  int32_t& outHeight,
                                  int32_t hints,
                                  int32_t& e) {
  uint8_t* ret = nullptr;
  outHeight = 1;
  if (m_Width >= 20) {
    ret = Encode(contents, outWidth, e);
  } else {
    ret = Encode(contents, outWidth, e);
  }
  BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
  return ret;
}
Ejemplo n.º 4
0
CFX_PtrArray* CBC_ReedSolomonGF256Poly::Divide(CBC_ReedSolomonGF256Poly* other,
                                               int32_t& e) {
  if (other->IsZero()) {
    e = BCExceptionDivideByZero;
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  }
  CBC_ReedSolomonGF256Poly* rsg1 = m_field->GetZero()->Clone(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_AutoPtr<CBC_ReedSolomonGF256Poly> quotient(rsg1);
  CBC_ReedSolomonGF256Poly* rsg2 = this->Clone(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_AutoPtr<CBC_ReedSolomonGF256Poly> remainder(rsg2);
  int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree());
  int32_t inverseDenominatorLeadingTeam =
      m_field->Inverse(denominatorLeadingTerm, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  while (remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) {
    int32_t degreeDifference = remainder->GetDegree() - other->GetDegree();
    int32_t scale =
        m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())),
                          inverseDenominatorLeadingTeam);
    CBC_ReedSolomonGF256Poly* rsg3 =
        other->MultiplyByMonomial(degreeDifference, scale, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> term(rsg3);
    CBC_ReedSolomonGF256Poly* rsg4 =
        m_field->BuildMonomial(degreeDifference, scale, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> iteratorQuotient(rsg4);
    CBC_ReedSolomonGF256Poly* rsg5 =
        quotient->AddOrSubtract(iteratorQuotient.get(), e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp(rsg5);
    quotient = temp;
    CBC_ReedSolomonGF256Poly* rsg6 = remainder->AddOrSubtract(term.get(), e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp1(rsg6);
    remainder = temp1;
  }
  CFX_PtrArray* tempPtrA = new CFX_PtrArray;
  tempPtrA->Add(quotient.release());
  tempPtrA->Add(remainder.release());
  return tempPtrA;
}
Ejemplo n.º 5
0
CBC_CommonBitMatrix* CBC_QRGridSampler::SampleGrid(CBC_CommonBitMatrix* image,
                                                   int32_t dimensionX,
                                                   int32_t dimensionY,
                                                   FX_FLOAT p1ToX,
                                                   FX_FLOAT p1ToY,
                                                   FX_FLOAT p2ToX,
                                                   FX_FLOAT p2ToY,
                                                   FX_FLOAT p3ToX,
                                                   FX_FLOAT p3ToY,
                                                   FX_FLOAT p4ToX,
                                                   FX_FLOAT p4ToY,
                                                   FX_FLOAT p1FromX,
                                                   FX_FLOAT p1FromY,
                                                   FX_FLOAT p2FromX,
                                                   FX_FLOAT p2FromY,
                                                   FX_FLOAT p3FromX,
                                                   FX_FLOAT p3FromY,
                                                   FX_FLOAT p4FromX,
                                                   FX_FLOAT p4FromY,
                                                   int32_t& e) {
  CBC_AutoPtr<CBC_CommonPerspectiveTransform> transform(
      CBC_CommonPerspectiveTransform::QuadrilateralToQuadrilateral(
          p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX,
          p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY));
  CBC_CommonBitMatrix* tempBitM = new CBC_CommonBitMatrix();
  tempBitM->Init(dimensionX, dimensionY);
  CBC_AutoPtr<CBC_CommonBitMatrix> bits(tempBitM);
  CFX_FloatArray points;
  points.SetSize(dimensionX << 1);
  for (int32_t y = 0; y < dimensionY; y++) {
    int32_t max = points.GetSize();
    FX_FLOAT iValue = (FX_FLOAT)(y + 0.5f);
    int32_t x;
    for (x = 0; x < max; x += 2) {
      points[x] = (FX_FLOAT)((x >> 1) + 0.5f);
      points[x + 1] = iValue;
    }
    transform->TransformPoints(&points);
    CheckAndNudgePoints(image, &points, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    for (x = 0; x < max; x += 2) {
      if (image->Get((int32_t)points[x], (int32_t)points[x + 1])) {
        bits->Set(x >> 1, y);
      }
    }
  }
uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents,
                                    BCFORMAT format,
                                    int32_t& outWidth,
                                    int32_t& outHeight,
                                    int32_t hints,
                                    int32_t& e) {
  if (format != BCFORMAT_UPC_A) {
    e = BCExceptionOnlyEncodeUPC_A;
    return nullptr;
  }
  CFX_ByteString toEAN13String = '0' + contents;
  m_iDataLenth = 13;
  uint8_t* ret = m_subWriter->Encode(toEAN13String, BCFORMAT_EAN_13, outWidth,
                                     outHeight, hints, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
  return ret;
}
Ejemplo n.º 7
0
CBC_CommonDecoderResult* CBC_QRCoderDecoder::Decode(FX_BOOL* image,
                                                    int32_t width,
                                                    int32_t height,
                                                    int32_t& e) {
  CBC_CommonBitMatrix bits;
  bits.Init(width);
  for (int32_t i = 0; i < width; i++) {
    for (int32_t j = 0; j < height; j++) {
      if (image[i * width + j]) {
        bits.Set(j, i);
      }
    }
  }
  CBC_CommonDecoderResult* cdr = Decode(&bits, height, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  return cdr;
}
Ejemplo n.º 8
0
CBC_BoundingBox* CBC_BoundingBox::addMissingRows(int32_t missingStartRows,
                                                 int32_t missingEndRows,
                                                 FX_BOOL isLeft,
                                                 int32_t& e) {
  CBC_ResultPoint* newTopLeft = m_topLeft;
  CBC_ResultPoint* newBottomLeft = m_bottomLeft;
  CBC_ResultPoint* newTopRight = m_topRight;
  CBC_ResultPoint* newBottomRight = m_bottomRight;
  CBC_ResultPoint* newTop = NULL;
  CBC_ResultPoint* newBottom = NULL;
  if (missingStartRows > 0) {
    CBC_ResultPoint* top = isLeft ? m_topLeft : m_topRight;
    int32_t newMinY = (int32_t)top->GetY() - missingStartRows;
    if (newMinY < 0) {
      newMinY = 0;
    }
    newTop = new CBC_ResultPoint((FX_FLOAT)top->GetX(), (FX_FLOAT)newMinY);
    if (isLeft) {
      newTopLeft = newTop;
    } else {
      newTopRight = newTop;
    }
  }
  if (missingEndRows > 0) {
    CBC_ResultPoint* bottom = isLeft ? m_bottomLeft : m_bottomRight;
    int32_t newMaxY = (int32_t)bottom->GetY() + missingEndRows;
    if (newMaxY >= m_image->GetHeight()) {
      newMaxY = m_image->GetHeight() - 1;
    }
    newBottom =
        new CBC_ResultPoint((FX_FLOAT)bottom->GetX(), (FX_FLOAT)newMaxY);
    if (isLeft) {
      newBottomLeft = newBottom;
    } else {
      newBottomRight = newBottom;
    }
  }
  calculateMinMaxValues();
  CBC_BoundingBox* boundingBox = new CBC_BoundingBox(
      m_image, newTopLeft, newBottomLeft, newTopRight, newBottomRight, e);
  delete newTop;
  delete newBottom;
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  return boundingBox;
}
Ejemplo n.º 9
0
CBC_BoundingBox* CBC_BoundingBox::merge(CBC_BoundingBox* leftBox,
                                        CBC_BoundingBox* rightBox,
                                        int32_t& e) {
  CBC_BoundingBox* boundingBox = NULL;
  if (leftBox == NULL) {
    boundingBox = new CBC_BoundingBox(rightBox);
    return boundingBox;
  }
  if (rightBox == NULL) {
    boundingBox = new CBC_BoundingBox(leftBox);
    return boundingBox;
  }
  boundingBox = new CBC_BoundingBox(leftBox->m_image, leftBox->m_topLeft,
                                    leftBox->m_bottomLeft, rightBox->m_topRight,
                                    rightBox->m_bottomRight, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  return boundingBox;
}
Ejemplo n.º 10
0
CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar,
                                                             int32_t& e) {
  if (scalar == 0)
    return m_field->GetZero()->Clone(e);
  if (scalar == 1)
    return Clone(e);

  int32_t size = m_coefficients.GetSize();
  CFX_Int32Array product;
  product.SetSize(size);
  for (int32_t i = 0; i < size; i++) {
    product[i] = m_field->Multiply(m_coefficients[i], scalar);
  }
  CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly();
  temp->Init(m_field, &product, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
  return temp;
}
Ejemplo n.º 11
0
CBC_CommonDecoderResult* CBC_QRCoderDecoder::Decode(CBC_CommonBitMatrix* bits,
                                                    int32_t byteModeDecode,
                                                    int32_t& e) {
  CBC_QRBitMatrixParser parser;
  parser.Init(bits, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_QRCoderVersion* version = parser.ReadVersion(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_QRCoderFormatInformation* temp = parser.ReadFormatInformation(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_QRCoderErrorCorrectionLevel* ecLevel = temp->GetErrorCorrectionLevel();
  CFX_ByteArray* ba = parser.ReadCodewords(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_AutoPtr<CFX_ByteArray> codewords(ba);
  CFX_PtrArray* dataBlocks =
      CBC_QRDataBlock::GetDataBlocks(codewords.get(), version, ecLevel, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  int32_t totalBytes = 0;
  for (int32_t i = 0; i < dataBlocks->GetSize(); i++) {
    totalBytes += ((CBC_QRDataBlock*)((*dataBlocks)[i]))->GetNumDataCodewords();
  }
  CFX_ByteArray resultBytes;
  for (int32_t j = 0; j < dataBlocks->GetSize(); j++) {
    CBC_QRDataBlock* dataBlock = (CBC_QRDataBlock*)((*dataBlocks)[j]);
    CFX_ByteArray* codewordBytes = dataBlock->GetCodewords();
    int32_t numDataCodewords = dataBlock->GetNumDataCodewords();
    CorrectErrors(codewordBytes, numDataCodewords, e);
    if (e != BCExceptionNO) {
      for (int32_t k = 0; k < dataBlocks->GetSize(); k++) {
        delete (CBC_QRDataBlock*)(*dataBlocks)[k];
      }
      dataBlocks->RemoveAll();
      delete dataBlocks;
      dataBlocks = NULL;
      return NULL;
    }
    for (int32_t i = 0; i < numDataCodewords; i++) {
      resultBytes.Add((*codewordBytes)[i]);
    }
  }
  for (int32_t k = 0; k < dataBlocks->GetSize(); k++) {
    delete (CBC_QRDataBlock*)(*dataBlocks)[k];
  }
  dataBlocks->RemoveAll();
  delete dataBlocks;
  dataBlocks = NULL;
  CBC_CommonDecoderResult* cdr = CBC_QRDecodedBitStreamParser::Decode(
      &resultBytes, version, ecLevel, byteModeDecode, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  return cdr;
}
Ejemplo n.º 12
0
int32_t CBC_X12Encoder::encodeChar(FX_WCHAR c, CFX_WideString& sb, int32_t& e) {
  if (c == '\r') {
    sb += (FX_WCHAR)'\0';
  } else if (c == '*') {
    sb += (FX_WCHAR)'\1';
  } else if (c == '>') {
    sb += (FX_WCHAR)'\2';
  } else if (c == ' ') {
    sb += (FX_WCHAR)'\3';
  } else if (c >= '0' && c <= '9') {
    sb += (FX_WCHAR)(c - 48 + 4);
  } else if (c >= 'A' && c <= 'Z') {
    sb += (FX_WCHAR)(c - 65 + 14);
  } else {
    CBC_HighLevelEncoder::illegalCharacter(c, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, -1);
  }
  return 1;
}
Ejemplo n.º 13
0
CBC_CommonBitMatrix* CBC_DataMatrixDetector::SampleGrid(
    CBC_CommonBitMatrix* image,
    CBC_ResultPoint* topLeft,
    CBC_ResultPoint* bottomLeft,
    CBC_ResultPoint* bottomRight,
    CBC_ResultPoint* topRight,
    int32_t dimensionX,
    int32_t dimensionY,
    int32_t& e) {
  CBC_QRGridSampler& sampler = CBC_QRGridSampler::GetInstance();
  CBC_CommonBitMatrix* cbm = sampler.SampleGrid(
      image, dimensionX, dimensionY, 0.5f, 0.5f, dimensionX - 0.5f, 0.5f,
      dimensionX - 0.5f, dimensionY - 0.5f, 0.5f, dimensionY - 0.5f,
      topLeft->GetX(), topLeft->GetY(), topRight->GetX(), topRight->GetY(),
      bottomRight->GetX(), bottomRight->GetY(), bottomLeft->GetX(),
      bottomLeft->GetY(), e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  return cbm;
}
Ejemplo n.º 14
0
int32_t CBC_C40Encoder::encodeChar(FX_WCHAR c, CFX_WideString& sb, int32_t& e) {
  if (c == ' ') {
    sb += (FX_WCHAR)'\3';
    return 1;
  } else if ((c >= '0') && (c <= '9')) {
    sb += (FX_WCHAR)(c - 48 + 4);
    return 1;
  } else if ((c >= 'A') && (c <= 'Z')) {
    sb += (FX_WCHAR)(c - 65 + 14);
    return 1;
  } else if ((c >= '\0') && (c <= 0x1f)) {
    sb += (FX_WCHAR)'\0';
    sb += c;
    return 2;
  } else if ((c >= '!') && (c <= '/')) {
    sb += (FX_WCHAR)'\1';
    sb += (FX_WCHAR)(c - 33);
    return 2;
  } else if ((c >= ':') && (c <= '@')) {
    sb += (FX_WCHAR)'\1';
    sb += (FX_WCHAR)(c - 58 + 15);
    return 2;
  } else if ((c >= '[') && (c <= '_')) {
    sb += (FX_WCHAR)'\1';
    sb += (FX_WCHAR)(c - 91 + 22);
    return 2;
  } else if ((c >= 60) && (c <= 0x7f)) {
    sb += (FX_WCHAR)'\2';
    sb += (FX_WCHAR)(c - 96);
    return 2;
  } else if (c >= 80) {
    sb += (FX_WCHAR)'\1';
    sb += (FX_WCHAR)0x001e;
    int32_t len = 2;
    len += encodeChar((c - 128), sb, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, 0);
    return len;
  } else {
    e = BCExceptionIllegalArgument;
    return 0;
  }
}
Ejemplo n.º 15
0
CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* CBC_ReedSolomonGF256Poly::Divide(
    CBC_ReedSolomonGF256Poly* other,
    int32_t& e) {
  if (other->IsZero()) {
    e = BCExceptionDivideByZero;
    return nullptr;
  }
  std::unique_ptr<CBC_ReedSolomonGF256Poly> quotient(
      m_field->GetZero()->Clone(e));
  BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
  std::unique_ptr<CBC_ReedSolomonGF256Poly> remainder(Clone(e));
  BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
  int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree());
  int32_t inverseDenominatorLeadingTeam =
      m_field->Inverse(denominatorLeadingTerm, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
  while (remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) {
    int32_t degreeDifference = remainder->GetDegree() - other->GetDegree();
    int32_t scale =
        m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())),
                          inverseDenominatorLeadingTeam);
    std::unique_ptr<CBC_ReedSolomonGF256Poly> term(
        other->MultiplyByMonomial(degreeDifference, scale, e));
    BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
    std::unique_ptr<CBC_ReedSolomonGF256Poly> iteratorQuotient(
        m_field->BuildMonomial(degreeDifference, scale, e));
    BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
    quotient.reset(quotient->AddOrSubtract(iteratorQuotient.get(), e));
    BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
    remainder.reset(remainder->AddOrSubtract(term.get(), e));
    BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
  }
  CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* tempPtrA =
      new CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>();
  tempPtrA->Add(quotient.release());
  tempPtrA->Add(remainder.release());
  return tempPtrA;
}
Ejemplo n.º 16
0
uint8_t* CBC_DataMatrixWriter::Encode(const CFX_WideString& contents,
                                      int32_t& outWidth,
                                      int32_t& outHeight,
                                      int32_t& e) {
    if (outWidth < 0 || outHeight < 0) {
        e = BCExceptionHeightAndWidthMustBeAtLeast1;
        BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
    }
    CBC_SymbolShapeHint::SymbolShapeHint shape =
        CBC_SymbolShapeHint::FORCE_SQUARE;
    CBC_Dimension* minSize = nullptr;
    CBC_Dimension* maxSize = nullptr;
    CFX_WideString ecLevel;
    CFX_WideString encoded = CBC_HighLevelEncoder::encodeHighLevel(
                                 contents, ecLevel, shape, minSize, maxSize, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
    CBC_SymbolInfo* symbolInfo = CBC_SymbolInfo::lookup(
                                     encoded.GetLength(), shape, minSize, maxSize, TRUE, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
    CFX_WideString codewords =
        CBC_ErrorCorrection::encodeECC200(encoded, symbolInfo, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
    CBC_DefaultPlacement* placement =
        new CBC_DefaultPlacement(codewords, symbolInfo->getSymbolDataWidth(e),
                                 symbolInfo->getSymbolDataHeight(e));
    BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
    placement->place();
    CBC_CommonByteMatrix* bytematrix = encodeLowLevel(placement, symbolInfo, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
    outWidth = bytematrix->GetWidth();
    outHeight = bytematrix->GetHeight();
    uint8_t* result = FX_Alloc2D(uint8_t, outWidth, outHeight);
    FXSYS_memcpy(result, bytematrix->GetArray(), outWidth * outHeight);
    delete bytematrix;
    delete placement;
    return result;
}
Ejemplo n.º 17
0
FX_BOOL CBC_PDF417I::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
  static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
      ->RenderBitmapResult(pOutBitmap, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
  return TRUE;
}
CBC_CommonDecoderResult* CBC_DecodedBitStreamPaser::decode(
    CFX_Int32Array& codewords,
    CFX_ByteString ecLevel,
    int32_t& e) {
  CFX_ByteString result;
  int32_t codeIndex = 1;
  int32_t code = codewords.GetAt(codeIndex);
  codeIndex++;
  CBC_PDF417ResultMetadata* resultMetadata = new CBC_PDF417ResultMetadata;
  while (codeIndex < codewords[0]) {
    switch (code) {
      case TEXT_COMPACTION_MODE_LATCH:
        codeIndex = textCompaction(codewords, codeIndex, result);
        break;
      case BYTE_COMPACTION_MODE_LATCH:
        codeIndex = byteCompaction(code, codewords, codeIndex, result);
        break;
      case NUMERIC_COMPACTION_MODE_LATCH:
        codeIndex = numericCompaction(codewords, codeIndex, result, e);
        BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
        break;
      case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
        codeIndex = byteCompaction(code, codewords, codeIndex, result);
        break;
      case BYTE_COMPACTION_MODE_LATCH_6:
        codeIndex = byteCompaction(code, codewords, codeIndex, result);
        break;
      case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
        codeIndex = decodeMacroBlock(codewords, codeIndex, resultMetadata, e);
        if (e != BCExceptionNO) {
          delete resultMetadata;
          return NULL;
        }
        break;
      default:
        codeIndex--;
        codeIndex = textCompaction(codewords, codeIndex, result);
        break;
    }
    if (codeIndex < codewords.GetSize()) {
      code = codewords[codeIndex++];
    } else {
      e = BCExceptionFormatInstance;
      delete resultMetadata;
      return NULL;
    }
  }
  if (result.GetLength() == 0) {
    e = BCExceptionFormatInstance;
    delete resultMetadata;
    return NULL;
  }
  CFX_ByteArray rawBytes;
  CFX_PtrArray byteSegments;
  CBC_CommonDecoderResult* tempCd = new CBC_CommonDecoderResult();
  tempCd->Init(rawBytes, result, byteSegments, ecLevel, e);
  if (e != BCExceptionNO) {
    delete resultMetadata;
    return NULL;
  }
  tempCd->setOther(resultMetadata);
  return tempCd;
}
Ejemplo n.º 19
0
CBC_CommonDecoderResult* CBC_QRDecodedBitStreamParser::Decode(
    CFX_ByteArray* bytes,
    CBC_QRCoderVersion* version,
    CBC_QRCoderErrorCorrectionLevel* ecLevel,
    int32_t byteModeDecode,
    int32_t& e) {
  CBC_CommonBitSource bits(bytes);
  CFX_ByteString result;
  CBC_CommonCharacterSetECI* currentCharacterSetECI = NULL;
  FX_BOOL fc1Infact = FALSE;
  CFX_Int32Array byteSegments;
  CBC_QRCoderMode* mode = NULL;
  do {
    if (bits.Available() < 4) {
      mode = CBC_QRCoderMode::sTERMINATOR;
    } else {
      int32_t iTemp1 = bits.ReadBits(4, e);
      BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
      mode = CBC_QRCoderMode::ForBits(iTemp1, e);
      BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
      if (mode == NULL) {
        e = BCExceptionUnSupportMode;
        BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
      }
    }
    if (!(mode == CBC_QRCoderMode::sTERMINATOR)) {
      if (mode == CBC_QRCoderMode::sFNC1_FIRST_POSITION ||
          mode == CBC_QRCoderMode::sFNC1_SECOND_POSITION) {
        fc1Infact = TRUE;
      } else if (mode == CBC_QRCoderMode::sSTRUCTURED_APPEND) {
        bits.ReadBits(16, e);
        BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
      } else if (mode == CBC_QRCoderMode::sECI) {
        int32_t value = ParseECIValue(&bits, e);
        BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
        currentCharacterSetECI =
            CBC_CommonCharacterSetECI::GetCharacterSetECIByValue(value);
      } else {
        if (mode == CBC_QRCoderMode::sGBK) {
          bits.ReadBits(4, e);
          BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
        }
        int32_t numBits = mode->GetCharacterCountBits(version, e);
        BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
        int32_t count = bits.ReadBits(numBits, e);
        BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
        if (mode == CBC_QRCoderMode::sNUMERIC) {
          DecodeNumericSegment(&bits, result, count, e);
          BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
        } else if (mode == CBC_QRCoderMode::sALPHANUMERIC) {
          DecodeAlphanumericSegment(&bits, result, count, fc1Infact, e);
          BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
        } else if (mode == CBC_QRCoderMode::sBYTE) {
          DecodeByteSegment(&bits, result, count, currentCharacterSetECI,
                            &byteSegments, byteModeDecode, e);
          BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
        } else if (mode == CBC_QRCoderMode::sGBK) {
          DecodeGBKSegment(&bits, result, count, e);
          BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
        } else if (mode == CBC_QRCoderMode::sKANJI) {
          DecodeKanjiSegment(&bits, result, count, e);
          BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
        } else {
          e = BCExceptionUnSupportMode;
          BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
        }
      }
    }
  } while (!(mode == CBC_QRCoderMode::sTERMINATOR));
  CBC_CommonDecoderResult* tempCd = new CBC_CommonDecoderResult();
  tempCd->Init(*bytes, result, byteSegments, ecLevel, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  return tempCd;
}
Ejemplo n.º 20
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();
}
Ejemplo n.º 21
0
CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber(
    int32_t versionNumber,
    int32_t& e) {
  if (VERSION->GetSize() == 0) {
    VERSION->Add(new CBC_QRCoderVersion(
        1, new CBC_QRCoderECBlocks(7, new CBC_QRCoderECB(1, 19)),
        new CBC_QRCoderECBlocks(10, new CBC_QRCoderECB(1, 16)),
        new CBC_QRCoderECBlocks(13, new CBC_QRCoderECB(1, 13)),
        new CBC_QRCoderECBlocks(17, new CBC_QRCoderECB(1, 9))));
    VERSION->Add(new CBC_QRCoderVersion(
        2, new CBC_QRCoderECBlocks(10, new CBC_QRCoderECB(1, 34)),
        new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(1, 28)),
        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(1, 22)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        3, new CBC_QRCoderECBlocks(15, new CBC_QRCoderECB(1, 55)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(1, 44)),
        new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 17)),
        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 13))));
    VERSION->Add(new CBC_QRCoderVersion(
        4, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(1, 80)),
        new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 32)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(2, 24)),
        new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(4, 9))));
    VERSION->Add(new CBC_QRCoderVersion(
        5, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(1, 108)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 43)),
        new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 15),
                                new CBC_QRCoderECB(2, 16)),
        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 11),
                                new CBC_QRCoderECB(2, 12))));
    VERSION->Add(new CBC_QRCoderVersion(
        6, new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 68)),
        new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(4, 27)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 19)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 15))));
    VERSION->Add(new CBC_QRCoderVersion(
        7, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(2, 78)),
        new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(4, 31)),
        new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 14),
                                new CBC_QRCoderECB(4, 15)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 13),
                                new CBC_QRCoderECB(1, 14))));
    VERSION->Add(new CBC_QRCoderVersion(
        8, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 97)),
        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 38),
                                new CBC_QRCoderECB(2, 39)),
        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(4, 18),
                                new CBC_QRCoderECB(2, 19)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 14),
                                new CBC_QRCoderECB(2, 15))));
    VERSION->Add(new CBC_QRCoderVersion(
        9, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(2, 116)),
        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(3, 36),
                                new CBC_QRCoderECB(2, 37)),
        new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(4, 16),
                                new CBC_QRCoderECB(4, 17)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 12),
                                new CBC_QRCoderECB(4, 13))));
    VERSION->Add(new CBC_QRCoderVersion(
        10, new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 68),
                                    new CBC_QRCoderECB(2, 69)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 43),
                                new CBC_QRCoderECB(1, 44)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(6, 19),
                                new CBC_QRCoderECB(2, 20)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 15),
                                new CBC_QRCoderECB(2, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        11, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(4, 81)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(1, 50),
                                new CBC_QRCoderECB(4, 51)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 22),
                                new CBC_QRCoderECB(4, 23)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(3, 12),
                                new CBC_QRCoderECB(8, 13))));
    VERSION->Add(new CBC_QRCoderVersion(
        12, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 92),
                                    new CBC_QRCoderECB(2, 93)),
        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(6, 36),
                                new CBC_QRCoderECB(2, 37)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 20),
                                new CBC_QRCoderECB(6, 21)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(7, 14),
                                new CBC_QRCoderECB(4, 15))));
    VERSION->Add(new CBC_QRCoderVersion(
        13, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 107)),
        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(8, 37),
                                new CBC_QRCoderECB(1, 38)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(8, 20),
                                new CBC_QRCoderECB(4, 21)),
        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(12, 11),
                                new CBC_QRCoderECB(4, 12))));
    VERSION->Add(new CBC_QRCoderVersion(
        14, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 115),
                                    new CBC_QRCoderECB(1, 116)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 40),
                                new CBC_QRCoderECB(5, 41)),
        new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(11, 16),
                                new CBC_QRCoderECB(5, 17)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(11, 12),
                                new CBC_QRCoderECB(5, 13))));
    VERSION->Add(new CBC_QRCoderVersion(
        15, new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(5, 87),
                                    new CBC_QRCoderECB(1, 88)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(5, 41),
                                new CBC_QRCoderECB(5, 42)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 24),
                                new CBC_QRCoderECB(7, 25)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(11, 12),
                                new CBC_QRCoderECB(7, 13))));
    VERSION->Add(new CBC_QRCoderVersion(
        16, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(5, 98),
                                    new CBC_QRCoderECB(1, 99)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(7, 45),
                                new CBC_QRCoderECB(3, 46)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(15, 19),
                                new CBC_QRCoderECB(2, 20)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 15),
                                new CBC_QRCoderECB(13, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        17, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 107),
                                    new CBC_QRCoderECB(5, 108)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 46),
                                new CBC_QRCoderECB(1, 47)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 22),
                                new CBC_QRCoderECB(15, 23)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 14),
                                new CBC_QRCoderECB(17, 15))));
    VERSION->Add(new CBC_QRCoderVersion(
        18, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 120),
                                    new CBC_QRCoderECB(1, 121)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(9, 43),
                                new CBC_QRCoderECB(4, 44)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 22),
                                new CBC_QRCoderECB(1, 23)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 14),
                                new CBC_QRCoderECB(19, 15))));
    VERSION->Add(new CBC_QRCoderVersion(
        19, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 113),
                                    new CBC_QRCoderECB(4, 114)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(3, 44),
                                new CBC_QRCoderECB(11, 45)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(17, 21),
                                new CBC_QRCoderECB(4, 22)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(9, 13),
                                new CBC_QRCoderECB(16, 14))));
    VERSION->Add(new CBC_QRCoderVersion(
        20, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 107),
                                    new CBC_QRCoderECB(5, 108)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(3, 41),
                                new CBC_QRCoderECB(13, 42)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(15, 24),
                                new CBC_QRCoderECB(5, 25)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(15, 15),
                                new CBC_QRCoderECB(10, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        21, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 116),
                                    new CBC_QRCoderECB(4, 117)),
        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(17, 42)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 22),
                                new CBC_QRCoderECB(6, 23)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 16),
                                new CBC_QRCoderECB(6, 17))));
    VERSION->Add(new CBC_QRCoderVersion(
        22, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 111),
                                    new CBC_QRCoderECB(7, 112)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 46)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 24),
                                new CBC_QRCoderECB(16, 25)),
        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(34, 13))));
    VERSION->Add(new CBC_QRCoderVersion(
        23, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 121),
                                    new CBC_QRCoderECB(5, 122)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 47),
                                new CBC_QRCoderECB(14, 48)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 24),
                                new CBC_QRCoderECB(14, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(16, 15),
                                new CBC_QRCoderECB(14, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        24, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(6, 117),
                                    new CBC_QRCoderECB(4, 118)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 45),
                                new CBC_QRCoderECB(14, 46)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 24),
                                new CBC_QRCoderECB(16, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(30, 16),
                                new CBC_QRCoderECB(2, 17))));
    VERSION->Add(new CBC_QRCoderVersion(
        25, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(8, 106),
                                    new CBC_QRCoderECB(4, 107)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(8, 47),
                                new CBC_QRCoderECB(13, 48)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 24),
                                new CBC_QRCoderECB(22, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(22, 15),
                                new CBC_QRCoderECB(13, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        26, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 114),
                                    new CBC_QRCoderECB(2, 115)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(19, 46),
                                new CBC_QRCoderECB(4, 47)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(28, 22),
                                new CBC_QRCoderECB(6, 23)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(33, 16),
                                new CBC_QRCoderECB(4, 17))));
    VERSION->Add(new CBC_QRCoderVersion(
        27, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(8, 122),
                                    new CBC_QRCoderECB(4, 123)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(22, 45),
                                new CBC_QRCoderECB(3, 46)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(8, 23),
                                new CBC_QRCoderECB(26, 24)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(12, 15),
                                new CBC_QRCoderECB(28, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        28, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 117),
                                    new CBC_QRCoderECB(10, 118)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 45),
                                new CBC_QRCoderECB(23, 46)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 24),
                                new CBC_QRCoderECB(31, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 15),
                                new CBC_QRCoderECB(31, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        29, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 116),
                                    new CBC_QRCoderECB(7, 117)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(21, 45),
                                new CBC_QRCoderECB(7, 46)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(1, 23),
                                new CBC_QRCoderECB(37, 24)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 15),
                                new CBC_QRCoderECB(26, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        30, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 115),
                                    new CBC_QRCoderECB(10, 116)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(19, 47),
                                new CBC_QRCoderECB(10, 48)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(15, 24),
                                new CBC_QRCoderECB(25, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(23, 15),
                                new CBC_QRCoderECB(25, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        31, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(13, 115),
                                    new CBC_QRCoderECB(3, 116)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 46),
                                new CBC_QRCoderECB(29, 47)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(42, 24),
                                new CBC_QRCoderECB(1, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(23, 15),
                                new CBC_QRCoderECB(28, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        32, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 115)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 46),
                                new CBC_QRCoderECB(23, 47)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(10, 24),
                                new CBC_QRCoderECB(35, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 15),
                                new CBC_QRCoderECB(35, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        33, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 115),
                                    new CBC_QRCoderECB(1, 116)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(14, 46),
                                new CBC_QRCoderECB(21, 47)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(29, 24),
                                new CBC_QRCoderECB(19, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 15),
                                new CBC_QRCoderECB(46, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        34, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(13, 115),
                                    new CBC_QRCoderECB(6, 116)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(14, 46),
                                new CBC_QRCoderECB(23, 47)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(44, 24),
                                new CBC_QRCoderECB(7, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(59, 16),
                                new CBC_QRCoderECB(1, 17))));
    VERSION->Add(new CBC_QRCoderVersion(
        35, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(12, 121),
                                    new CBC_QRCoderECB(7, 122)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(12, 47),
                                new CBC_QRCoderECB(26, 48)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(39, 24),
                                new CBC_QRCoderECB(14, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(22, 15),
                                new CBC_QRCoderECB(41, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        36, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(6, 121),
                                    new CBC_QRCoderECB(14, 122)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 47),
                                new CBC_QRCoderECB(34, 48)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(46, 24),
                                new CBC_QRCoderECB(10, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(2, 15),
                                new CBC_QRCoderECB(64, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        37, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 122),
                                    new CBC_QRCoderECB(4, 123)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(29, 46),
                                new CBC_QRCoderECB(14, 47)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(49, 24),
                                new CBC_QRCoderECB(10, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(24, 15),
                                new CBC_QRCoderECB(46, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        38, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 122),
                                    new CBC_QRCoderECB(18, 123)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(13, 46),
                                new CBC_QRCoderECB(32, 47)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(48, 24),
                                new CBC_QRCoderECB(14, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(42, 15),
                                new CBC_QRCoderECB(32, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        39, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 117),
                                    new CBC_QRCoderECB(4, 118)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(40, 47),
                                new CBC_QRCoderECB(7, 48)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(43, 24),
                                new CBC_QRCoderECB(22, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(10, 15),
                                new CBC_QRCoderECB(67, 16))));
    VERSION->Add(new CBC_QRCoderVersion(
        40, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 118),
                                    new CBC_QRCoderECB(6, 119)),
        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(18, 47),
                                new CBC_QRCoderECB(31, 48)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(34, 24),
                                new CBC_QRCoderECB(34, 25)),
        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 15),
                                new CBC_QRCoderECB(61, 16))));
  }
  if (versionNumber < 1 || versionNumber > 40) {
    e = BCExceptionIllegalArgument;
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  }
  return (CBC_QRCoderVersion*)(*VERSION)[versionNumber - 1];
}
Ejemplo n.º 22
0
CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap* image, int32_t& e) {
  CFX_ByteString strtemp = Decode(image, 0, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, "");
  return strtemp;
}
Ejemplo n.º 23
0
CFX_ByteString CBC_QRCodeReader::Decode(CBC_BinaryBitmap* image, int32_t& e) {
  CFX_ByteString bs = Decode(image, 0, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, "");
  return bs;
}
CFX_WideString CBC_PDF417HighLevelEncoder::encodeHighLevel(
    CFX_WideString wideMsg,
    Compaction compaction,
    int32_t& e) {
  CFX_ByteString bytes;
  CBC_UtilCodingConvert::UnicodeToUTF8(wideMsg, bytes);
  CFX_WideString msg;
  int32_t len = bytes.GetLength();
  for (int32_t i = 0; i < len; i++) {
    FX_WCHAR ch = (FX_WCHAR)(bytes.GetAt(i) & 0xff);
    if (ch == '?' && bytes.GetAt(i) != '?') {
      e = BCExceptionCharactersOutsideISO88591Encoding;
      return CFX_WideString();
    }
    msg += ch;
  }
  CFX_ByteArray byteArr;
  for (int32_t k = 0; k < bytes.GetLength(); k++) {
    byteArr.Add(bytes.GetAt(k));
  }
  CFX_WideString sb;
  len = msg.GetLength();
  int32_t p = 0;
  int32_t textSubMode = SUBMODE_ALPHA;
  if (compaction == TEXT) {
    encodeText(msg, p, len, sb, textSubMode);
  } else if (compaction == BYTES) {
    encodeBinary(&byteArr, p, byteArr.GetSize(), BYTE_COMPACTION, sb);
  } else if (compaction == NUMERIC) {
    sb += (FX_WCHAR)LATCH_TO_NUMERIC;
    encodeNumeric(msg, p, len, sb);
  } else {
    int32_t encodingMode = LATCH_TO_TEXT;
    while (p < len) {
      int32_t n = determineConsecutiveDigitCount(msg, p);
      if (n >= 13) {
        sb += (FX_WCHAR)LATCH_TO_NUMERIC;
        encodingMode = NUMERIC_COMPACTION;
        textSubMode = SUBMODE_ALPHA;
        encodeNumeric(msg, p, n, sb);
        p += n;
      } else {
        int32_t t = determineConsecutiveTextCount(msg, p);
        if (t >= 5 || n == len) {
          if (encodingMode != TEXT_COMPACTION) {
            sb += (FX_WCHAR)LATCH_TO_TEXT;
            encodingMode = TEXT_COMPACTION;
            textSubMode = SUBMODE_ALPHA;
          }
          textSubMode = encodeText(msg, p, t, sb, textSubMode);
          p += t;
        } else {
          int32_t b = determineConsecutiveBinaryCount(msg, &byteArr, p, e);
          BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR)' ');
          if (b == 0) {
            b = 1;
          }
          if (b == 1 && encodingMode == TEXT_COMPACTION) {
            encodeBinary(&byteArr, p, 1, TEXT_COMPACTION, sb);
          } else {
            encodeBinary(&byteArr, p, b, encodingMode, sb);
            encodingMode = BYTE_COMPACTION;
            textSubMode = SUBMODE_ALPHA;
          }
          p += b;
        }
      }
    }
  }
  return sb;
}
Ejemplo n.º 25
0
CFX_PtrArray* CBC_ReedSolomonDecoder::RunEuclideanAlgorithm(
    CBC_ReedSolomonGF256Poly* a,
    CBC_ReedSolomonGF256Poly* b,
    int32_t R,
    int32_t& e) {
  if (a->GetDegree() < b->GetDegree()) {
    CBC_ReedSolomonGF256Poly* temp = a;
    a = b;
    b = temp;
  }
  CBC_ReedSolomonGF256Poly* rsg1 = a->Clone(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_AutoPtr<CBC_ReedSolomonGF256Poly> rLast(rsg1);
  CBC_ReedSolomonGF256Poly* rsg2 = b->Clone(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_AutoPtr<CBC_ReedSolomonGF256Poly> r(rsg2);
  CBC_ReedSolomonGF256Poly* rsg3 = m_field->GetOne()->Clone(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_AutoPtr<CBC_ReedSolomonGF256Poly> sLast(rsg3);
  CBC_ReedSolomonGF256Poly* rsg4 = m_field->GetZero()->Clone(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_AutoPtr<CBC_ReedSolomonGF256Poly> s(rsg4);
  CBC_ReedSolomonGF256Poly* rsg5 = m_field->GetZero()->Clone(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_AutoPtr<CBC_ReedSolomonGF256Poly> tLast(rsg5);
  CBC_ReedSolomonGF256Poly* rsg6 = m_field->GetOne()->Clone(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_AutoPtr<CBC_ReedSolomonGF256Poly> t(rsg6);
  while (r->GetDegree() >= R / 2) {
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> rLastLast = rLast;
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> sLastLast = sLast;
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> tLastlast = tLast;
    rLast = r;
    sLast = s;
    tLast = t;
    if (rLast->IsZero()) {
      e = BCExceptionR_I_1IsZero;
      BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    }
    CBC_ReedSolomonGF256Poly* rsg7 = rLastLast->Clone(e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> rTemp(rsg7);
    r = rTemp;
    CBC_ReedSolomonGF256Poly* rsg8 = m_field->GetZero()->Clone(e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> q(rsg8);
    int32_t denominatorLeadingTerm = rLast->GetCoefficients(rLast->GetDegree());
    int32_t dltInverse = m_field->Inverse(denominatorLeadingTerm, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    while (r->GetDegree() >= rLast->GetDegree() && !(r->IsZero())) {
      int32_t degreeDiff = r->GetDegree() - rLast->GetDegree();
      int32_t scale =
          m_field->Multiply(r->GetCoefficients(r->GetDegree()), dltInverse);
      CBC_ReedSolomonGF256Poly* rsgp1 =
          m_field->BuildMonomial(degreeDiff, scale, e);
      BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
      CBC_AutoPtr<CBC_ReedSolomonGF256Poly> build(rsgp1);
      CBC_ReedSolomonGF256Poly* rsgp2 = q->AddOrSubtract(build.get(), e);
      BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
      CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp(rsgp2);
      q = temp;
      CBC_ReedSolomonGF256Poly* rsgp3 =
          rLast->MultiplyByMonomial(degreeDiff, scale, e);
      BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
      CBC_AutoPtr<CBC_ReedSolomonGF256Poly> multiply(rsgp3);
      CBC_ReedSolomonGF256Poly* rsgp4 = r->AddOrSubtract(multiply.get(), e);
      BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
      CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp3(rsgp4);
      r = temp3;
    }
    CBC_ReedSolomonGF256Poly* rsg9 = q->Multiply(sLast.get(), e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp1(rsg9);
    CBC_ReedSolomonGF256Poly* rsg10 = temp1->AddOrSubtract(sLastLast.get(), e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp2(rsg10);
    s = temp2;
    CBC_ReedSolomonGF256Poly* rsg11 = q->Multiply(tLast.get(), e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp5(rsg11);
    CBC_ReedSolomonGF256Poly* rsg12 = temp5->AddOrSubtract(tLastlast.get(), e);
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
    CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp6(rsg12);
    t = temp6;
  }
  int32_t sigmaTildeAtZero = t->GetCoefficients(0);
  if (sigmaTildeAtZero == 0) {
    e = BCExceptionIsZero;
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  }
  int32_t inverse = m_field->Inverse(sigmaTildeAtZero, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_ReedSolomonGF256Poly* rsg13 = t->Multiply(inverse, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_AutoPtr<CBC_ReedSolomonGF256Poly> sigma(rsg13);
  CBC_ReedSolomonGF256Poly* rsg14 = r->Multiply(inverse, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_AutoPtr<CBC_ReedSolomonGF256Poly> omega(rsg14);
  CFX_PtrArray* temp = new CFX_PtrArray;
  temp->Add(sigma.release());
  temp->Add(omega.release());
  return temp;
}
Ejemplo n.º 26
0
CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Clone(int32_t& e) {
  CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly();
  temp->Init(m_field, &m_coefficients, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  return temp;
}
int32_t CBC_DataMatrixDecodedBitStreamParser::DecodeAsciiSegment(
    CBC_CommonBitSource* bits,
    CFX_ByteString& result,
    CFX_ByteString& resultTrailer,
    int32_t& e) {
  FX_CHAR buffer[128];
  FX_BOOL upperShift = FALSE;
  do {
    int32_t oneByte = bits->ReadBits(8, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, 0);
    if (oneByte == 0) {
      e = BCExceptionFormatException;
      return 0;
    } else if (oneByte <= 128) {
      oneByte = upperShift ? oneByte + 128 : oneByte;
      upperShift = FALSE;
      result += ((FX_CHAR)(oneByte - 1));
      return ASCII_ENCODE;
    } else if (oneByte == 129) {
      return PAD_ENCODE;
    } else if (oneByte <= 229) {
      int32_t value = oneByte - 130;
#if defined(_FX_WINAPI_PARTITION_APP_)
      memset(buffer, 0, sizeof(FX_CHAR) * 128);
      _itoa_s(value, buffer, 128, 10);
#else
      FXSYS_itoa(value, buffer, 10);
#endif
      if (value < 10) {
        result += '0';
        buffer[1] = '\0';
      } else {
        buffer[2] = '\0';
      }
      result += buffer;
    } else if (oneByte == 230) {
      return C40_ENCODE;
    } else if (oneByte == 231) {
      return BASE256_ENCODE;
    } else if (oneByte == 232 || oneByte == 233 || oneByte == 234) {
    } else if (oneByte == 235) {
      upperShift = TRUE;
    } else if (oneByte == 236) {
      result += "[)>";
      result += 0x1E;
      result += "05";
      result += 0x1D;
      resultTrailer.Insert(0, 0x1E);
      resultTrailer.Insert(0 + 1, 0x04);
    } else if (oneByte == 237) {
      result += "[)>";
      result += 0x1E;
      result += "06";
      result += 0x1D;
      resultTrailer.Insert(0, 0x1E);
      resultTrailer.Insert(0 + 1, 0x04);
    } else if (oneByte == 238) {
      return ANSIX12_ENCODE;
    } else if (oneByte == 239) {
      return TEXT_ENCODE;
    } else if (oneByte == 240) {
      return EDIFACT_ENCODE;
    } else if (oneByte == 241) {
    } else if (oneByte >= 242) {
      if (oneByte == 254 && bits->Available() == 0) {
      } else {
        e = BCExceptionFormatException;
        return 0;
      }
    }
  } while (bits->Available() > 0);
  return ASCII_ENCODE;
}
Ejemplo n.º 28
0
CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg,
                                                     CFX_WideString ecLevel,
                                                     SymbolShapeHint shape,
                                                     CBC_Dimension* minSize,
                                                     CBC_Dimension* maxSize,
                                                     int32_t& e) {
  CBC_EncoderContext context(msg, ecLevel, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
  context.setSymbolShape(shape);
  context.setSizeConstraints(minSize, maxSize);
  if ((msg.Mid(0, 6) == MACRO_05_HEADER) &&
      (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) {
    context.writeCodeword(MACRO_05);
    context.setSkipAtEnd(2);
    context.m_pos += 6;
  } else if ((msg.Mid(0, 6) == MACRO_06_HEADER) &&
             (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) {
    context.writeCodeword(MACRO_06);
    context.setSkipAtEnd(2);
    context.m_pos += 6;
  }
  CFX_PtrArray encoders;
  encoders.Add(new CBC_ASCIIEncoder());
  encoders.Add(new CBC_C40Encoder());
  encoders.Add(new CBC_TextEncoder());
  encoders.Add(new CBC_X12Encoder());
  encoders.Add(new CBC_EdifactEncoder());
  encoders.Add(new CBC_Base256Encoder());
  int32_t encodingMode = ASCII_ENCODATION;
  while (context.hasMoreCharacters()) {
    ((CBC_Encoder*)encoders.GetAt(encodingMode))->Encode(context, e);
    if (e != BCExceptionNO) {
      for (int32_t i = 0; i < encoders.GetSize(); i++) {
        delete (CBC_Encoder*)encoders.GetAt(i);
      }
      encoders.RemoveAll();
      return (FX_WCHAR*)"";
    }
    if (context.m_newEncoding >= 0) {
      encodingMode = context.m_newEncoding;
      context.resetEncoderSignal();
    }
  }
  int32_t len = context.m_codewords.GetLength();
  context.updateSymbolInfo(e);
  if (e != BCExceptionNO) {
    for (int32_t i = 0; i < encoders.GetSize(); i++) {
      delete (CBC_Encoder*)encoders.GetAt(i);
    }
    encoders.RemoveAll();
    return (FX_WCHAR*)"";
  }
  int32_t capacity = context.m_symbolInfo->m_dataCapacity;
  if (len < capacity) {
    if (encodingMode != ASCII_ENCODATION &&
        encodingMode != BASE256_ENCODATION) {
      context.writeCodeword(0x00fe);
    }
  }
  CFX_WideString codewords = context.m_codewords;
  if (codewords.GetLength() < capacity) {
    codewords += PAD;
  }
  while (codewords.GetLength() < capacity) {
    codewords += (randomize253State(PAD, codewords.GetLength() + 1));
  }
  for (int32_t i = 0; i < encoders.GetSize(); i++) {
    delete (CBC_Encoder*)encoders.GetAt(i);
  }
  encoders.RemoveAll();
  return codewords;
}
Ejemplo n.º 29
0
bool CBC_EAN8::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
  static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
      ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
  BC_EXCEPTION_CHECK_ReturnValue(e, false);
  return true;
}
Ejemplo n.º 30
0
CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) {
  CFX_PtrArray* cornerPoints = m_rectangleDetector->Detect(e);
  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  CBC_ResultPoint* pointA = (CBC_ResultPoint*)(*cornerPoints)[0];
  CBC_ResultPoint* pointB = (CBC_ResultPoint*)(*cornerPoints)[1];
  CBC_ResultPoint* pointC = (CBC_ResultPoint*)(*cornerPoints)[2];
  CBC_ResultPoint* pointD = (CBC_ResultPoint*)(*cornerPoints)[3];
  delete cornerPoints;
  cornerPoints = NULL;
  CFX_PtrArray transitions;
  transitions.Add(TransitionsBetween(pointA, pointB));
  transitions.Add(TransitionsBetween(pointA, pointC));
  transitions.Add(TransitionsBetween(pointB, pointD));
  transitions.Add(TransitionsBetween(pointC, pointD));
  BC_FX_PtrArray_Sort(transitions, &ResultPointsAndTransitionsComparator);
  delete ((CBC_ResultPointsAndTransitions*)transitions[2]);
  delete ((CBC_ResultPointsAndTransitions*)transitions[3]);
  CBC_ResultPointsAndTransitions* lSideOne =
      (CBC_ResultPointsAndTransitions*)transitions[0];
  CBC_ResultPointsAndTransitions* lSideTwo =
      (CBC_ResultPointsAndTransitions*)transitions[1];
  CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t> pointCount;
  Increment(pointCount, lSideOne->GetFrom());
  Increment(pointCount, lSideOne->GetTo());
  Increment(pointCount, lSideTwo->GetFrom());
  Increment(pointCount, lSideTwo->GetTo());
  delete ((CBC_ResultPointsAndTransitions*)transitions[1]);
  delete ((CBC_ResultPointsAndTransitions*)transitions[0]);
  transitions.RemoveAll();
  CBC_ResultPoint* maybeTopLeft = NULL;
  CBC_ResultPoint* bottomLeft = NULL;
  CBC_ResultPoint* maybeBottomRight = NULL;
  FX_POSITION itBegin = pointCount.GetStartPosition();
  while (itBegin != NULL) {
    CBC_ResultPoint* key = 0;
    int32_t value = 0;
    pointCount.GetNextAssoc(itBegin, key, value);
    if (value == 2) {
      bottomLeft = key;
    } else {
      if (maybeBottomRight == NULL) {
        maybeBottomRight = key;
      } else {
        maybeTopLeft = key;
      }
    }
  }
  if (maybeTopLeft == NULL || bottomLeft == NULL || maybeBottomRight == NULL) {
    delete pointA;
    delete pointB;
    delete pointC;
    delete pointD;
    e = BCExceptionNotFound;
    return NULL;
  }
  CFX_PtrArray corners;
  corners.SetSize(3);
  corners[0] = maybeTopLeft;
  corners[1] = bottomLeft;
  corners[2] = maybeBottomRight;
  OrderBestPatterns(&corners);
  CBC_ResultPoint* bottomRight = (CBC_ResultPoint*)corners[0];
  bottomLeft = (CBC_ResultPoint*)corners[1];
  CBC_ResultPoint* topLeft = (CBC_ResultPoint*)corners[2];
  CBC_ResultPoint* topRight = NULL;
  int32_t value;
  if (!pointCount.Lookup(pointA, value)) {
    topRight = pointA;
  } else if (!pointCount.Lookup(pointB, value)) {
    topRight = pointB;
  } else if (!pointCount.Lookup(pointC, value)) {
    topRight = pointC;
  } else {
    topRight = pointD;
  }
  int32_t dimensionTop = CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
                             TransitionsBetween(topLeft, topRight))
                             ->GetTransitions();
  int32_t dimensionRight = CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
                               TransitionsBetween(bottomRight, topRight))
                               ->GetTransitions();
  if ((dimensionTop & 0x01) == 1) {
    dimensionTop++;
  }
  dimensionTop += 2;
  if ((dimensionRight & 0x01) == 1) {
    dimensionRight++;
  }
  dimensionRight += 2;
  CBC_AutoPtr<CBC_CommonBitMatrix> bits(NULL);
  CBC_AutoPtr<CBC_ResultPoint> correctedTopRight(NULL);
  if (4 * dimensionTop >= 7 * dimensionRight ||
      4 * dimensionRight >= 7 * dimensionTop) {
    correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(
        CorrectTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight,
                                   dimensionTop, dimensionRight));
    if (correctedTopRight.get() == NULL) {
      correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(topRight);
    } else {
      delete topRight;
      topRight = NULL;
    }
    dimensionTop = CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
                       TransitionsBetween(topLeft, correctedTopRight.get()))
                       ->GetTransitions();
    dimensionRight =
        CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
            TransitionsBetween(bottomRight, correctedTopRight.get()))
            ->GetTransitions();
    if ((dimensionTop & 0x01) == 1) {
      dimensionTop++;
    }
    if ((dimensionRight & 0x01) == 1) {
      dimensionRight++;
    }
    bits = CBC_AutoPtr<CBC_CommonBitMatrix>(
        SampleGrid(m_image, topLeft, bottomLeft, bottomRight,
                   correctedTopRight.get(), dimensionTop, dimensionRight, e));
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  } else {
    int32_t dimension = std::min(dimensionRight, dimensionTop);
    correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(
        CorrectTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension));
    if (correctedTopRight.get() == NULL) {
      correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(topRight);
    } else {
      delete topRight;
      topRight = NULL;
    }
    int32_t dimensionCorrected =
        std::max(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
                     TransitionsBetween(topLeft, correctedTopRight.get()))
                     ->GetTransitions(),
                 CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
                     TransitionsBetween(bottomRight, correctedTopRight.get()))
                     ->GetTransitions());
    dimensionCorrected++;
    if ((dimensionCorrected & 0x01) == 1) {
      dimensionCorrected++;
    }
    bits = CBC_AutoPtr<CBC_CommonBitMatrix>(SampleGrid(
        m_image, topLeft, bottomLeft, bottomRight, correctedTopRight.get(),
        dimensionCorrected, dimensionCorrected, e));
    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
  }
  CFX_PtrArray* result = new CFX_PtrArray;
  result->SetSize(4);
  result->Add(topLeft);
  result->Add(bottomLeft);
  result->Add(bottomRight);
  result->Add(correctedTopRight.release());
  return new CBC_QRDetectorResult(bits.release(), result);
}