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);
        }