Exemple #1
0
        internal virtual SamplingGrid getSamplingGrid(FinderPattern finderPattern, AlignmentPattern alignmentPattern)
        {
            Point[][] center  = alignmentPattern.getCenter();
            int       version = finderPattern.Version;
            int       num     = version / 7 + 2;

            center[0][0]       = finderPattern.getCenter(0);
            center[num - 1][0] = finderPattern.getCenter(1);
            center[0][num - 1] = finderPattern.getCenter(2);
            int          sqrtNumArea  = num - 1;
            SamplingGrid samplingGrid = new SamplingGrid(sqrtNumArea);
            Axis         axis         = new Axis(finderPattern.getAngle(), finderPattern.getModuleSize());

            for (int ay = 0; ay < sqrtNumArea; ++ay)
            {
                for (int ax = 0; ax < sqrtNumArea; ++ax)
                {
                    QRCodeImageReader.ModulePitch modulePitch = new QRCodeImageReader.ModulePitch(this);
                    Line line1 = new Line();
                    Line line2 = new Line();
                    axis.ModulePitch = finderPattern.getModuleSize();
                    Point[][] logicalCenter = AlignmentPattern.getLogicalCenter(finderPattern);
                    Point     point1        = center[ax][ay];
                    Point     point2        = center[ax + 1][ay];
                    Point     point3        = center[ax][ay + 1];
                    Point     point4        = center[ax + 1][ay + 1];
                    Point     point5        = logicalCenter[ax][ay];
                    Point     point6        = logicalCenter[ax + 1][ay];
                    Point     point7        = logicalCenter[ax][ay + 1];
                    Point     point8        = logicalCenter[ax + 1][ay + 1];
                    if (ax == 0 && ay == 0)
                    {
                        if (sqrtNumArea == 1)
                        {
                            point1 = axis.translate(point1, -3, -3);
                            point2 = axis.translate(point2, 3, -3);
                            point3 = axis.translate(point3, -3, 3);
                            point4 = axis.translate(point4, 6, 6);
                            point5.translate(-6, -6);
                            point6.translate(3, -3);
                            point7.translate(-3, 3);
                            point8.translate(6, 6);
                        }
                        else
                        {
                            point1 = axis.translate(point1, -3, -3);
                            point2 = axis.translate(point2, 0, -6);
                            point3 = axis.translate(point3, -6, 0);
                            point5.translate(-6, -6);
                            point6.translate(0, -6);
                            point7.translate(-6, 0);
                        }
                    }
                    else if (ax == 0 && ay == sqrtNumArea - 1)
                    {
                        point1 = axis.translate(point1, -6, 0);
                        point3 = axis.translate(point3, -3, 3);
                        point4 = axis.translate(point4, 0, 6);
                        point5.translate(-6, 0);
                        point7.translate(-6, 6);
                        point8.translate(0, 6);
                    }
                    else if (ax == sqrtNumArea - 1 && ay == 0)
                    {
                        point1 = axis.translate(point1, 0, -6);
                        point2 = axis.translate(point2, 3, -3);
                        point4 = axis.translate(point4, 6, 0);
                        point5.translate(0, -6);
                        point6.translate(6, -6);
                        point8.translate(6, 0);
                    }
                    else if (ax == sqrtNumArea - 1 && ay == sqrtNumArea - 1)
                    {
                        point3 = axis.translate(point3, 0, 6);
                        point2 = axis.translate(point2, 6, 0);
                        point4 = axis.translate(point4, 6, 6);
                        point7.translate(0, 6);
                        point6.translate(6, 0);
                        point8.translate(6, 6);
                    }
                    else if (ax == 0)
                    {
                        point1 = axis.translate(point1, -6, 0);
                        point3 = axis.translate(point3, -6, 0);
                        point5.translate(-6, 0);
                        point7.translate(-6, 0);
                    }
                    else if (ax == sqrtNumArea - 1)
                    {
                        point2 = axis.translate(point2, 6, 0);
                        point4 = axis.translate(point4, 6, 0);
                        point6.translate(6, 0);
                        point8.translate(6, 0);
                    }
                    else if (ay == 0)
                    {
                        point1 = axis.translate(point1, 0, -6);
                        point2 = axis.translate(point2, 0, -6);
                        point5.translate(0, -6);
                        point6.translate(0, -6);
                    }
                    else if (ay == sqrtNumArea - 1)
                    {
                        point3 = axis.translate(point3, 0, 6);
                        point4 = axis.translate(point4, 0, 6);
                        point7.translate(0, 6);
                        point8.translate(0, 6);
                    }
                    if (ax == 0)
                    {
                        point6.translate(1, 0);
                        point8.translate(1, 0);
                    }
                    else
                    {
                        point5.translate(-1, 0);
                        point7.translate(-1, 0);
                    }
                    if (ay == 0)
                    {
                        point7.translate(0, 1);
                        point8.translate(0, 1);
                    }
                    else
                    {
                        point5.translate(0, -1);
                        point6.translate(0, -1);
                    }
                    int width  = point6.X - point5.X;
                    int height = point7.Y - point5.Y;
                    if (version < 7)
                    {
                        width  += 3;
                        height += 3;
                    }
                    modulePitch.top    = this.getAreaModulePitch(point1, point2, width - 1);
                    modulePitch.left   = this.getAreaModulePitch(point1, point3, height - 1);
                    modulePitch.bottom = this.getAreaModulePitch(point3, point4, width - 1);
                    modulePitch.right  = this.getAreaModulePitch(point2, point4, height - 1);
                    line1.setP1(point1);
                    line2.setP1(point1);
                    line1.setP2(point3);
                    line2.setP2(point2);
                    samplingGrid.initGrid(ax, ay, width, height);
                    for (int index = 0; index < width; ++index)
                    {
                        Line line3 = new Line(line1.getP1(), line1.getP2());
                        axis.Origin      = line3.getP1();
                        axis.ModulePitch = modulePitch.top;
                        line3.setP1(axis.translate(index, 0));
                        axis.Origin      = line3.getP2();
                        axis.ModulePitch = modulePitch.bottom;
                        line3.setP2(axis.translate(index, 0));
                        samplingGrid.setXLine(ax, ay, index, line3);
                    }
                    for (int index = 0; index < height; ++index)
                    {
                        Line line3 = new Line(line2.getP1(), line2.getP2());
                        axis.Origin      = line3.getP1();
                        axis.ModulePitch = modulePitch.left;
                        line3.setP1(axis.translate(0, index));
                        axis.Origin      = line3.getP2();
                        axis.ModulePitch = modulePitch.right;
                        line3.setP2(axis.translate(0, index));
                        samplingGrid.setYLine(ax, ay, index, line3);
                    }
                }
            }
            return(samplingGrid);
        }
Exemple #2
0
        internal virtual SamplingGrid getSamplingGrid(FinderPattern finderPattern, AlignmentPattern alignmentPattern)
        {
            Point[][] centers     = alignmentPattern.getCenter();
            int       version     = finderPattern.Version;
            int       sqrtCenters = version / 7 + 2;

            centers[0][0] = finderPattern.getCenter(0);
            centers[sqrtCenters - 1][0] = finderPattern.getCenter(1);
            centers[0][sqrtCenters - 1] = finderPattern.getCenter(2);
            int          sqrtNumArea  = sqrtCenters - 1;
            SamplingGrid samplingGrid = new SamplingGrid(sqrtNumArea);
            Axis         axis         = new Axis(finderPattern.getAngle(), finderPattern.getModuleSize());

            for (int ay = 0; ay < sqrtNumArea; ay++)
            {
                for (int ax = 0; ax < sqrtNumArea; ax++)
                {
                    QRCodeImageReader.ModulePitch modulePitch = new QRCodeImageReader.ModulePitch(this);
                    Line baseLineX = new Line();
                    Line baseLineY = new Line();
                    axis.ModulePitch = finderPattern.getModuleSize();
                    Point[][] logicalCenters         = AlignmentPattern.getLogicalCenter(finderPattern);
                    Point     upperLeftPoint         = centers[ax][ay];
                    Point     upperRightPoint        = centers[ax + 1][ay];
                    Point     lowerLeftPoint         = centers[ax][ay + 1];
                    Point     lowerRightPoint        = centers[ax + 1][ay + 1];
                    Point     logicalUpperLeftPoint  = logicalCenters[ax][ay];
                    Point     logicalUpperRightPoint = logicalCenters[ax + 1][ay];
                    Point     logicalLowerLeftPoint  = logicalCenters[ax][ay + 1];
                    Point     logicalLowerRightPoint = logicalCenters[ax + 1][ay + 1];
                    if (ax == 0 && ay == 0)
                    {
                        if (sqrtNumArea == 1)
                        {
                            upperLeftPoint  = axis.translate(upperLeftPoint, -3, -3);
                            upperRightPoint = axis.translate(upperRightPoint, 3, -3);
                            lowerLeftPoint  = axis.translate(lowerLeftPoint, -3, 3);
                            lowerRightPoint = axis.translate(lowerRightPoint, 6, 6);
                            logicalUpperLeftPoint.translate(-6, -6);
                            logicalUpperRightPoint.translate(3, -3);
                            logicalLowerLeftPoint.translate(-3, 3);
                            logicalLowerRightPoint.translate(6, 6);
                        }
                        else
                        {
                            upperLeftPoint  = axis.translate(upperLeftPoint, -3, -3);
                            upperRightPoint = axis.translate(upperRightPoint, 0, -6);
                            lowerLeftPoint  = axis.translate(lowerLeftPoint, -6, 0);
                            logicalUpperLeftPoint.translate(-6, -6);
                            logicalUpperRightPoint.translate(0, -6);
                            logicalLowerLeftPoint.translate(-6, 0);
                        }
                    }
                    else
                    {
                        if (ax == 0 && ay == sqrtNumArea - 1)
                        {
                            upperLeftPoint  = axis.translate(upperLeftPoint, -6, 0);
                            lowerLeftPoint  = axis.translate(lowerLeftPoint, -3, 3);
                            lowerRightPoint = axis.translate(lowerRightPoint, 0, 6);
                            logicalUpperLeftPoint.translate(-6, 0);
                            logicalLowerLeftPoint.translate(-6, 6);
                            logicalLowerRightPoint.translate(0, 6);
                        }
                        else
                        {
                            if (ax == sqrtNumArea - 1 && ay == 0)
                            {
                                upperLeftPoint  = axis.translate(upperLeftPoint, 0, -6);
                                upperRightPoint = axis.translate(upperRightPoint, 3, -3);
                                lowerRightPoint = axis.translate(lowerRightPoint, 6, 0);
                                logicalUpperLeftPoint.translate(0, -6);
                                logicalUpperRightPoint.translate(6, -6);
                                logicalLowerRightPoint.translate(6, 0);
                            }
                            else
                            {
                                if (ax == sqrtNumArea - 1 && ay == sqrtNumArea - 1)
                                {
                                    lowerLeftPoint  = axis.translate(lowerLeftPoint, 0, 6);
                                    upperRightPoint = axis.translate(upperRightPoint, 6, 0);
                                    lowerRightPoint = axis.translate(lowerRightPoint, 6, 6);
                                    logicalLowerLeftPoint.translate(0, 6);
                                    logicalUpperRightPoint.translate(6, 0);
                                    logicalLowerRightPoint.translate(6, 6);
                                }
                                else
                                {
                                    if (ax == 0)
                                    {
                                        upperLeftPoint = axis.translate(upperLeftPoint, -6, 0);
                                        lowerLeftPoint = axis.translate(lowerLeftPoint, -6, 0);
                                        logicalUpperLeftPoint.translate(-6, 0);
                                        logicalLowerLeftPoint.translate(-6, 0);
                                    }
                                    else
                                    {
                                        if (ax == sqrtNumArea - 1)
                                        {
                                            upperRightPoint = axis.translate(upperRightPoint, 6, 0);
                                            lowerRightPoint = axis.translate(lowerRightPoint, 6, 0);
                                            logicalUpperRightPoint.translate(6, 0);
                                            logicalLowerRightPoint.translate(6, 0);
                                        }
                                        else
                                        {
                                            if (ay == 0)
                                            {
                                                upperLeftPoint  = axis.translate(upperLeftPoint, 0, -6);
                                                upperRightPoint = axis.translate(upperRightPoint, 0, -6);
                                                logicalUpperLeftPoint.translate(0, -6);
                                                logicalUpperRightPoint.translate(0, -6);
                                            }
                                            else
                                            {
                                                if (ay == sqrtNumArea - 1)
                                                {
                                                    lowerLeftPoint  = axis.translate(lowerLeftPoint, 0, 6);
                                                    lowerRightPoint = axis.translate(lowerRightPoint, 0, 6);
                                                    logicalLowerLeftPoint.translate(0, 6);
                                                    logicalLowerRightPoint.translate(0, 6);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (ax == 0)
                    {
                        logicalUpperRightPoint.translate(1, 0);
                        logicalLowerRightPoint.translate(1, 0);
                    }
                    else
                    {
                        logicalUpperLeftPoint.translate(-1, 0);
                        logicalLowerLeftPoint.translate(-1, 0);
                    }
                    if (ay == 0)
                    {
                        logicalLowerLeftPoint.translate(0, 1);
                        logicalLowerRightPoint.translate(0, 1);
                    }
                    else
                    {
                        logicalUpperLeftPoint.translate(0, -1);
                        logicalUpperRightPoint.translate(0, -1);
                    }
                    int logicalWidth  = logicalUpperRightPoint.X - logicalUpperLeftPoint.X;
                    int logicalHeight = logicalLowerLeftPoint.Y - logicalUpperLeftPoint.Y;
                    if (version < 7)
                    {
                        logicalWidth  += 3;
                        logicalHeight += 3;
                    }
                    modulePitch.top    = this.getAreaModulePitch(upperLeftPoint, upperRightPoint, logicalWidth - 1);
                    modulePitch.left   = this.getAreaModulePitch(upperLeftPoint, lowerLeftPoint, logicalHeight - 1);
                    modulePitch.bottom = this.getAreaModulePitch(lowerLeftPoint, lowerRightPoint, logicalWidth - 1);
                    modulePitch.right  = this.getAreaModulePitch(upperRightPoint, lowerRightPoint, logicalHeight - 1);
                    baseLineX.setP1(upperLeftPoint);
                    baseLineY.setP1(upperLeftPoint);
                    baseLineX.setP2(lowerLeftPoint);
                    baseLineY.setP2(upperRightPoint);
                    samplingGrid.initGrid(ax, ay, logicalWidth, logicalHeight);
                    for (int i = 0; i < logicalWidth; i++)
                    {
                        Line gridLineX = new Line(baseLineX.getP1(), baseLineX.getP2());
                        axis.Origin      = gridLineX.getP1();
                        axis.ModulePitch = modulePitch.top;
                        gridLineX.setP1(axis.translate(i, 0));
                        axis.Origin      = gridLineX.getP2();
                        axis.ModulePitch = modulePitch.bottom;
                        gridLineX.setP2(axis.translate(i, 0));
                        samplingGrid.setXLine(ax, ay, i, gridLineX);
                    }
                    for (int i = 0; i < logicalHeight; i++)
                    {
                        Line gridLineY = new Line(baseLineY.getP1(), baseLineY.getP2());
                        axis.Origin      = gridLineY.getP1();
                        axis.ModulePitch = modulePitch.left;
                        gridLineY.setP1(axis.translate(0, i));
                        axis.Origin      = gridLineY.getP2();
                        axis.ModulePitch = modulePitch.right;
                        gridLineY.setP2(axis.translate(0, i));
                        samplingGrid.setYLine(ax, ay, i, gridLineY);
                    }
                }
            }
            return(samplingGrid);
        }