Exemplo n.º 1
0
CFX_Int32Array* CBC_Detector::findGuardPattern(CBC_CommonBitMatrix* matrix,
                                               int32_t column,
                                               int32_t row,
                                               int32_t width,
                                               FX_BOOL whiteFirst,
                                               int32_t* pattern,
                                               int32_t patternLength,
                                               CFX_Int32Array& counters) {
  for (int32_t i = 0; i < counters.GetSize(); i++) {
    counters.SetAt(i, 0);
  }
  FX_BOOL isWhite = whiteFirst;
  int32_t patternStart = column;
  int32_t pixelDrift = 0;
  CFX_Int32Array* intarray = new CFX_Int32Array;
  while (matrix->Get(patternStart, row) && patternStart > 0 &&
         pixelDrift++ < MAX_PIXEL_DRIFT) {
    patternStart--;
  }
  int32_t x = patternStart;
  int32_t counterPosition = 0;
  for (; x < width; x++) {
    FX_BOOL pixel = matrix->Get(x, row);
    if (pixel ^ isWhite) {
      counters[counterPosition]++;
    } else {
      if (counterPosition == patternLength - 1) {
        if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) <
            MAX_AVG_VARIANCE) {
          intarray->Add(patternStart);
          intarray->Add(x);
          return intarray;
        }
        patternStart += counters[0] + counters[1];
        for (int32_t l = 2, k = 0; l < patternLength; l++, k++) {
          counters.SetAt(k, counters.GetAt(l));
        }
        counters.SetAt(patternLength - 2, 0);
        counters.SetAt(patternLength - 1, 0);
        counterPosition--;
      } else {
        counterPosition++;
      }
      counters[counterPosition] = 1;
      isWhite = !isWhite;
    }
  }
  if (counterPosition == patternLength - 1) {
    if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) <
        MAX_AVG_VARIANCE) {
      intarray->Add(patternStart);
      intarray->Add(x - 1);
      return intarray;
    }
  }
  delete intarray;
  return NULL;
}
Exemplo n.º 2
0
int32_t CBC_OnedEAN8Reader::DecodeMiddle(CBC_CommonBitArray* row,
                                         CFX_Int32Array* startRange,
                                         CFX_ByteString& resultResult,
                                         int32_t& e) {
  CFX_Int32Array counters;
  counters.Add(0);
  counters.Add(0);
  counters.Add(0);
  counters.Add(0);
  int32_t end = row->GetSize();
  int32_t rowOffset = (*startRange)[1];
  int32_t rowOffsetLeft = rowOffset;
  for (int32_t x = 0; x < 4 && rowOffset < end; x++) {
    int32_t bestMatch =
        DecodeDigit(row, &counters, rowOffset,
                    &(CBC_OneDimReader::L_PATTERNS[0][0]), 10, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, 0);
    resultResult += (FX_CHAR)('0' + bestMatch);
    for (int32_t i = 0; i < counters.GetSize(); i++) {
      rowOffset += counters[i];
    }
  }
  int32_t RowOffsetLen = (rowOffset - rowOffsetLeft) / 4;
  CFX_Int32Array result;
  result.Add(CBC_OneDimReader::MIDDLE_PATTERN[0]);
  result.Add(CBC_OneDimReader::MIDDLE_PATTERN[1]);
  result.Add(CBC_OneDimReader::MIDDLE_PATTERN[2]);
  result.Add(CBC_OneDimReader::MIDDLE_PATTERN[3]);
  result.Add(CBC_OneDimReader::MIDDLE_PATTERN[4]);
  CFX_Int32Array* middleRange =
      FindGuardPattern(row, rowOffset, TRUE, &result, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, 0);
  int32_t rowOffsetMid = rowOffset;
  rowOffset = (*middleRange)[1];
  if ((rowOffset - rowOffsetMid) > RowOffsetLen) {
    e = BCExceptionNotFound;
    BC_EXCEPTION_CHECK_ReturnValue(e, 0);
  }
  if (middleRange != NULL) {
    delete middleRange;
    middleRange = NULL;
  }
  for (int32_t y = 0; y < 4 && rowOffset < end; y++) {
    int32_t bestMatch =
        DecodeDigit(row, &counters, rowOffset,
                    &(CBC_OneDimReader::L_PATTERNS[0][0]), 10, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, 0);
    resultResult += (FX_CHAR)('0' + bestMatch);
    for (int32_t i = 0; i < counters.GetSize(); i++) {
      rowOffset += counters[i];
    }
  }
  return rowOffset;
}
Exemplo n.º 3
0
CFX_Int32Array* CBC_PDF417::determineDimensions(
    int32_t sourceCodeWords,
    int32_t errorCorrectionCodeWords,
    int32_t& e) {
  FX_FLOAT ratio = 0.0f;
  CFX_Int32Array* dimension = nullptr;
  for (int32_t cols = m_minCols; cols <= m_maxCols; cols++) {
    int32_t rows =
        calculateNumberOfRows(sourceCodeWords, errorCorrectionCodeWords, cols);
    if (rows < m_minRows) {
      break;
    }
    if (rows > m_maxRows) {
      continue;
    }
    FX_FLOAT newRatio =
        ((17 * cols + 69) * DEFAULT_MODULE_WIDTH) / (rows * HEIGHT);
    if (dimension &&
        fabsf(newRatio - PREFERRED_RATIO) > fabsf(ratio - PREFERRED_RATIO)) {
      continue;
    }
    ratio = newRatio;
    delete dimension;
    dimension = new CFX_Int32Array;
    dimension->Add(cols);
    dimension->Add(rows);
  }
  if (!dimension) {
    int32_t rows = calculateNumberOfRows(sourceCodeWords,
                                         errorCorrectionCodeWords, m_minCols);
    if (rows < m_minRows) {
      dimension = new CFX_Int32Array;
      dimension->Add(m_minCols);
      dimension->Add(m_minRows);
    } else if (rows >= 3 && rows <= 90) {
      dimension = new CFX_Int32Array;
      dimension->Add(m_minCols);
      dimension->Add(rows);
    }
  }
  if (!dimension) {
    e = BCExceptionUnableToFitMessageInColumns;
    return nullptr;
  }
  return dimension;
}
Exemplo n.º 4
0
bool CXFA_FFListBox::CommitData() {
  CFWL_ListBox* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget);
  int32_t iSels = pListBox->CountSelItems();
  CFX_Int32Array iSelArray;
  for (int32_t i = 0; i < iSels; ++i)
    iSelArray.Add(pListBox->GetSelIndex(i));
  m_pDataAcc->SetSelectedItems(iSelArray, true, false, true);
  return true;
}
Exemplo n.º 5
0
FX_BOOL CXFA_FFListBox::CommitData() {
  CFWL_ListBox* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget);
  int32_t iSels = pListBox->CountSelItems();
  CFX_Int32Array iSelArray;
  for (int32_t i = 0; i < iSels; i++) {
    iSelArray.Add(pListBox->GetSelIndex(i));
  }
  m_pDataAcc->SetSelectdItems(iSelArray, TRUE);
  return TRUE;
}
Exemplo n.º 6
0
CBC_PDF417ECModulusGF::CBC_PDF417ECModulusGF(int32_t modulus,
                                             int32_t generator,
                                             int32_t& e) {
  m_modulus = modulus;
  m_expTable.SetSize(modulus);
  m_logTable.SetSize(modulus);
  int32_t x = 1;
  for (int32_t i = 0; i < modulus; i++) {
    m_expTable[i] = x;
    x = (x * generator) % modulus;
  }
  for (int32_t j = 0; j < modulus - 1; j++) {
    m_logTable[m_expTable[j]] = j;
  }
  CFX_Int32Array zero;
  zero.Add(0);
  m_zero = new CBC_PDF417ECModulusPoly(this, zero, e);
  CFX_Int32Array one;
  one.Add(1);
  m_one = new CBC_PDF417ECModulusPoly(this, one, e);
}
Exemplo n.º 7
0
int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_GetFilter(
    const CFX_WideStringC& wsExpression,
    int32_t nStart,
    CXFA_ResolveNodesData& rnd) {
  FXSYS_assert(nStart > -1);
  int32_t iLength = wsExpression.GetLength();
  if (nStart >= iLength) {
    return 0;
  }
  CFX_WideString& wsName = rnd.m_wsName;
  CFX_WideString& wsCondition = rnd.m_wsCondition;
  FX_WCHAR* pNameBuf = wsName.GetBuffer(iLength - nStart);
  FX_WCHAR* pConditionBuf = wsCondition.GetBuffer(iLength - nStart);
  int32_t nNameCount = 0;
  int32_t nConditionCount = 0;
  CFX_Int32Array stack;
  int32_t nType = -1;
  const FX_WCHAR* pSrc = wsExpression.GetPtr();
  FX_WCHAR wPrev = 0, wCur;
  FX_BOOL bIsCondition = FALSE;
  while (nStart < iLength) {
    wCur = pSrc[nStart++];
    if (wCur == '.') {
      if (wPrev == '\\') {
        pNameBuf[nNameCount - 1] = wPrev = '.';
        continue;
      }
      if (nNameCount == 0) {
        pNameBuf[nNameCount++] = wCur;
        continue;
      }
      FX_WCHAR wLookahead = nStart < iLength ? pSrc[nStart] : 0;
      if (wLookahead != '[' && wLookahead != '(') {
        if (nType < 0) {
          break;
        }
      }
    }
    if (wCur == '[' || wCur == '(') {
      bIsCondition = TRUE;
    } else if (wCur == '.' && nStart < iLength &&
               (pSrc[nStart] == '[' || pSrc[nStart] == '(')) {
      bIsCondition = TRUE;
    }
    if (bIsCondition) {
      pConditionBuf[nConditionCount++] = wCur;
    } else {
      pNameBuf[nNameCount++] = wCur;
    }
    FX_BOOL bRecursive = TRUE;
    switch (nType) {
      case 0:
        if (wCur == ']') {
          nType = XFA_ResolveNodes_PopStack(stack);
          bRecursive = FALSE;
        }
        break;
      case 1:
        if (wCur == ')') {
          nType = XFA_ResolveNodes_PopStack(stack);
          bRecursive = FALSE;
        }
        break;
      case 2:
        if (wCur == '"') {
          nType = XFA_ResolveNodes_PopStack(stack);
          bRecursive = FALSE;
        }
        break;
    }
    if (bRecursive) {
      switch (wCur) {
        case '[':
          stack.Add(nType);
          nType = 0;
          break;
        case '(':
          stack.Add(nType);
          nType = 1;
          break;
        case '"':
          stack.Add(nType);
          nType = 2;
          break;
      }
    }
    wPrev = wCur;
  }
  if (stack.GetSize() > 0) {
    return -1;
  }
  wsName.ReleaseBuffer(nNameCount);
  wsName.TrimLeft();
  wsName.TrimRight();
  wsCondition.ReleaseBuffer(nConditionCount);
  wsCondition.TrimLeft();
  wsCondition.TrimRight();
  rnd.m_uHashName = FX_HashCode_String_GetW(wsName, wsName.GetLength());
  return nStart;
}
Exemplo n.º 8
0
CFX_PtrArray* CBC_Detector::findRowsWithPattern(CBC_CommonBitMatrix* matrix,
                                                int32_t height,
                                                int32_t width,
                                                int32_t startRow,
                                                int32_t startColumn,
                                                int32_t* pattern,
                                                int32_t patternLength) {
  CFX_PtrArray* result = new CFX_PtrArray;
  result->SetSize(4);
  FX_BOOL found = FALSE;
  CFX_Int32Array counters;
  counters.SetSize(patternLength);
  for (; startRow < height; startRow += ROW_STEP) {
    CFX_Int32Array* loc =
        findGuardPattern(matrix, startColumn, startRow, width, FALSE, pattern,
                         patternLength, counters);
    if (loc != NULL) {
      while (startRow > 0) {
        CFX_Int32Array* previousRowLoc =
            findGuardPattern(matrix, startColumn, --startRow, width, FALSE,
                             pattern, patternLength, counters);
        if (previousRowLoc != NULL) {
          delete loc;
          loc = previousRowLoc;
        } else {
          startRow++;
          break;
        }
      }
      result->SetAt(
          0, new CBC_ResultPoint((FX_FLOAT)loc->GetAt(0), (FX_FLOAT)startRow));
      result->SetAt(
          1, new CBC_ResultPoint((FX_FLOAT)loc->GetAt(1), (FX_FLOAT)startRow));
      found = TRUE;
      delete loc;
      break;
    }
  }
  int32_t stopRow = startRow + 1;
  if (found) {
    int32_t skippedRowCount = 0;
    CFX_Int32Array previousRowLoc;
    previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(0))->GetX());
    previousRowLoc.Add((int32_t)((CBC_ResultPoint*)result->GetAt(1))->GetX());
    for (; stopRow < height; stopRow++) {
      CFX_Int32Array* loc =
          findGuardPattern(matrix, previousRowLoc[0], stopRow, width, FALSE,
                           pattern, patternLength, counters);
      if (loc != NULL &&
          abs(previousRowLoc[0] - loc->GetAt(0)) < MAX_PATTERN_DRIFT &&
          abs(previousRowLoc[1] - loc->GetAt(1)) < MAX_PATTERN_DRIFT) {
        previousRowLoc.Copy(*loc);
        skippedRowCount = 0;
      } else {
        if (skippedRowCount > SKIPPED_ROW_COUNT_MAX) {
          delete loc;
          break;
        } else {
          skippedRowCount++;
        }
      }
      delete loc;
    }
    stopRow -= skippedRowCount + 1;
    result->SetAt(2, new CBC_ResultPoint((FX_FLOAT)previousRowLoc.GetAt(0),
                                         (FX_FLOAT)stopRow));
    result->SetAt(3, new CBC_ResultPoint((FX_FLOAT)previousRowLoc.GetAt(1),
                                         (FX_FLOAT)stopRow));
  }
  if (stopRow - startRow < BARCODE_MIN_HEIGHT) {
    for (int32_t i = 0; i < result->GetSize(); i++) {
      result->SetAt(i, NULL);
    }
  }
  return result;
}