Exemplo n.º 1
0
CFX_PtrArray* CBC_Detector::findVertices(CBC_CommonBitMatrix* matrix,
                                         int32_t startRow,
                                         int32_t startColumn) {
  int32_t height = matrix->GetHeight();
  int32_t width = matrix->GetWidth();
  CFX_PtrArray* result = new CFX_PtrArray;
  result->SetSize(8);
  CFX_PtrArray* startptr = findRowsWithPattern(
      matrix, height, width, startRow, startColumn, START_PATTERN,
      sizeof(START_PATTERN) / sizeof(START_PATTERN[0]));
  copyToResult(
      result, startptr, INDEXES_START_PATTERN,
      sizeof(INDEXES_START_PATTERN) / sizeof(INDEXES_START_PATTERN[0]));
  startptr->RemoveAll();
  delete startptr;
  if (result->GetAt(4) != NULL) {
    startColumn = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetX();
    startRow = (int32_t)((CBC_ResultPoint*)result->GetAt(4))->GetY();
  }
  CFX_PtrArray* stopptr = findRowsWithPattern(
      matrix, height, width, startRow, startColumn, STOP_PATTERN,
      sizeof(STOP_PATTERN) / sizeof(STOP_PATTERN[0]));
  copyToResult(result, stopptr, INDEXES_STOP_PATTERN,
               sizeof(INDEXES_STOP_PATTERN) / sizeof(INDEXES_STOP_PATTERN[0]));
  stopptr->RemoveAll();
  delete stopptr;
  return result;
}
Exemplo n.º 2
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;
}
CBC_PDF417DetectorResult::~CBC_PDF417DetectorResult() {
  for (int32_t i = 0; i < m_points->GetSize(); i++) {
    CFX_PtrArray* temp = (CFX_PtrArray*)m_points->GetAt(i);
    for (int32_t j = 0; j < temp->GetSize(); j++) {
      delete (CBC_ResultPoint*)temp->GetAt(j);
    }
    temp->RemoveAll();
    delete temp;
  }
  m_points->RemoveAll();
  delete m_points;
}
Exemplo n.º 4
0
FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document,
                         FPDF_FILEWRITE* pFileWrite,
                         FPDF_DWORD flags,
                         FPDF_BOOL bSetVersion,
                         int fileVerion) {
  CPDF_Document* pPDFDoc = CPDFDocumentFromFPDFDocument(document);
  if (!pPDFDoc)
    return 0;

#ifdef PDF_ENABLE_XFA
  CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
  CFX_PtrArray fileList;
  _SendPreSaveToXFADoc(pDoc, fileList);
#endif  // PDF_ENABLE_XFA

  if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) {
    flags = 0;
  }

  CPDF_Creator FileMaker(pPDFDoc);
  if (bSetVersion)
    FileMaker.SetFileVersion(fileVerion);
  if (flags == FPDF_REMOVE_SECURITY) {
    flags = 0;
    FileMaker.RemoveSecurity();
  }

  CFX_IFileWrite* pStreamWrite = NULL;
  FX_BOOL bRet;
  pStreamWrite = new CFX_IFileWrite;
  pStreamWrite->Init(pFileWrite);
  bRet = FileMaker.Create(pStreamWrite, flags);
#ifdef PDF_ENABLE_XFA
  _SendPostSaveToXFADoc(pDoc);
  for (int i = 0; i < fileList.GetSize(); i++) {
    IFX_FileStream* pFile = (IFX_FileStream*)fileList.GetAt(i);
    pFile->Release();
  }
  fileList.RemoveAll();
#endif  // PDF_ENABLE_XFA
  pStreamWrite->Release();
  return bRet;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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);
}