CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(int32_t& e) { int32_t dimension = GetDimensionForVersion(); CBC_CommonBitMatrix* bitMatrix = new CBC_CommonBitMatrix(); bitMatrix->Init(dimension); bitMatrix->SetRegion(0, 0, 9, 9, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); bitMatrix->SetRegion(dimension - 8, 0, 8, 9, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); bitMatrix->SetRegion(0, dimension - 8, 9, 8, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); int32_t max = m_alignmentPatternCenters.GetSize(); for (int32_t x = 0; x < max; x++) { int32_t i = m_alignmentPatternCenters[x] - 2; for (int32_t y = 0; y < max; y++) { if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) { continue; } bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); } } bitMatrix->SetRegion(6, 9, 1, dimension - 17, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); bitMatrix->SetRegion(9, 6, dimension - 17, 1, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); if (m_versionNumber > 6) { bitMatrix->SetRegion(dimension - 11, 0, 3, 6, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); bitMatrix->SetRegion(0, dimension - 11, 6, 3, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); } return bitMatrix; }
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; }
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); } } }
CBC_CommonBitMatrix* CBC_DataMatrixBitMatrixParser::ExtractDataRegion( CBC_CommonBitMatrix* bitMatrix, int32_t& e) { int32_t symbolSizeRows = m_version->GetSymbolSizeRows(); int32_t symbolSizeColumns = m_version->GetSymbolSizeColumns(); if (bitMatrix->GetHeight() != symbolSizeRows) { e = BCExceptionCanNotCallGetDimensionOnNonSquareMatrix; return NULL; } int32_t dataRegionSizeRows = m_version->GetDataRegionSizeRows(); int32_t dataRegionSizeColumns = m_version->GetDataRegionSizeColumns(); int32_t numDataRegionsRow = symbolSizeRows / dataRegionSizeRows; int32_t numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns; int32_t sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows; int32_t sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns; CBC_CommonBitMatrix* bitMatrixWithoutAlignment = new CBC_CommonBitMatrix(); bitMatrixWithoutAlignment->Init(sizeDataRegionColumn, sizeDataRegionRow); int32_t dataRegionRow; for (dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) { int32_t dataRegionRowOffset = dataRegionRow * dataRegionSizeRows; int32_t dataRegionColumn; for (dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) { int32_t dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns; int32_t i; for (i = 0; i < dataRegionSizeRows; ++i) { int32_t readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i; int32_t writeRowOffset = dataRegionRowOffset + i; int32_t j; for (j = 0; j < dataRegionSizeColumns; ++j) { int32_t readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j; if (bitMatrix->Get(readColumnOffset, readRowOffset)) { int32_t writeColumnOffset = dataRegionColumnOffset + j; bitMatrixWithoutAlignment->Set(writeColumnOffset, writeRowOffset); } } } } } return bitMatrixWithoutAlignment; }