ArrayRef<char> CameraImageWrapper::getMatrix() const
{
    int width = getWidth();
    int height =  getHeight();
    char* matrix = new char[width*height];
    char* m = matrix;

    for(int y=0; y<height; y++)
    {
        ArrayRef<char> tmpRow;
        tmpRow = getRow(y, ArrayRef<char>(width));
#if __cplusplus > 199711L
        memcpy(m, tmpRow->values().data(), width);
#else
		memcpy(m, &tmpRow->values()[0], width);
#endif
        m += width * sizeof(unsigned char);

        //delete tmpRow;
    }

    //pMatrix = matrix;
	ArrayRef<char> arr = ArrayRef<char>(matrix, width*height);

	if(matrix)
		delete matrix;


    return arr;
}
/**
 * Byte Compaction mode (see 5.4.3) permits all 256 possible 8-bit byte values to be encoded.
 * This includes all ASCII characters value 0 to 127 inclusive and provides for international
 * character set support.
 *
 * @param mode      The byte compaction mode i.e. 901 or 924
 * @param codewords The array of codewords (data + error)
 * @param codeIndex The current index into the codeword array.
 * @param result    The decoded data is appended to the result.
 * @return The next index into the codeword array.
 */
int DecodedBitStreamParser::byteCompaction(int mode,
                                           ArrayRef<int> codewords,
                                           int codeIndex, Ref<String> result) {
  if (mode == BYTE_COMPACTION_MODE_LATCH) {
    // Total number of Byte Compaction characters to be encoded
    // is not a multiple of 6
    int count = 0;
    int64_t value = 0;
    ArrayRef<char> decodedData = new Array<char>(6);
    ArrayRef<int> byteCompactedCodewords = new Array<int>(6);
    bool end = false;
    int nextCode = codewords[codeIndex++];
    while ((codeIndex < codewords[0]) && !end) {
      byteCompactedCodewords[count++] = nextCode;
      // Base 900
      value = 900 * value + nextCode;
      nextCode = codewords[codeIndex++];
      // perhaps it should be ok to check only nextCode >= TEXT_COMPACTION_MODE_LATCH
      if (nextCode == TEXT_COMPACTION_MODE_LATCH ||
          nextCode == BYTE_COMPACTION_MODE_LATCH ||
          nextCode == NUMERIC_COMPACTION_MODE_LATCH ||
          nextCode == BYTE_COMPACTION_MODE_LATCH_6 ||
          nextCode == BEGIN_MACRO_PDF417_CONTROL_BLOCK ||
          nextCode == BEGIN_MACRO_PDF417_OPTIONAL_FIELD ||
          nextCode == MACRO_PDF417_TERMINATOR)
      {
        end = true;
      }
      else
      {
        if ((count%5 == 0) && (count > 0))
        {
          // Decode every 5 codewords
          // Convert to Base 256
          for (int j = 0; j < 6; ++j)
          {
            decodedData[5 - j] = (char) (value%256);
            value >>= 8;
          }
          result->append(string(&(decodedData->values()[0]), decodedData->values().size()));
          count = 0;
        }
      }
    }

    // if the end of all codewords is reached the last codeword needs to be added
    if (codeIndex == codewords[0] && nextCode < TEXT_COMPACTION_MODE_LATCH)
      byteCompactedCodewords[count++] = nextCode;

    // If Byte Compaction mode is invoked with codeword 901,
    // the last group of codewords is interpreted directly
    // as one byte per codeword, without compaction.
    for (int i = 0; i < count; i++)
    {
      result->append((char)byteCompactedCodewords[i]);
    }

  } else if (mode == BYTE_COMPACTION_MODE_LATCH_6) {
Esempio n. 3
0
Ref<Result> GenericMultipleBarcodeReader::translateResultPoints(Ref<Result> result, int xOffset, int yOffset){
    ArrayRef< Ref<ResultPoint> > oldResultPoints = result->getResultPoints();
  if (oldResultPoints->empty()) {
    return result;
  }
  ArrayRef< Ref<ResultPoint> > newResultPoints;
  for (int i = 0; i < oldResultPoints->size(); i++) {
    Ref<ResultPoint> oldPoint = oldResultPoints[i];
    newResultPoints->values().push_back(Ref<ResultPoint>(new ResultPoint(oldPoint->getX() + xOffset, oldPoint->getY() + yOffset)));
  }
  return Ref<Result>(new Result(result->getText(), result->getRawBytes(), newResultPoints, result->getBarcodeFormat()));
}
/**
 * @param matrix row of black/white values to search
 * @param column x position to start search
 * @param row y position to start search
 * @param width the number of pixels to search on this row
 * @param pattern pattern of counts of number of black and white pixels that are
 *                 being searched for as a pattern
 * @param counters array of counters, as long as pattern, to re-use
 * @return start/end horizontal offset of guard pattern, as an array of two ints.
 */
ArrayRef<int> Detector::findGuardPattern(Ref<BitMatrix> matrix,
        int column,
        int row,
        int width,
        bool whiteFirst,
        const int pattern[],
        int patternSize,
        ArrayRef<int>& counters) {
    counters->values().assign(counters->size(), 0);
    int patternLength = patternSize;
    bool isWhite = whiteFirst;

    int counterPosition = 0;
    int patternStart = column;
    for (int x = column; x < column + width; x++) {
        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) {
                    ArrayRef<int> result = new Array<int>(2);
                    result[0] = patternStart;
                    result[1] = x;
                    return result;
                }
                patternStart += counters[0] + counters[1];
                for(int i = 0; i < patternLength - 2; ++i)
                    counters[i] = counters[ i + 2];
                counters[patternLength - 2] = 0;
                counters[patternLength - 1] = 0;
                counterPosition--;
            } else {
                counterPosition++;
            }
            counters[counterPosition] = 1;
            isWhite = !isWhite;
        }
    }
    return ArrayRef<int>();
}