예제 #1
0
        internal static Line[] findLineAcross(bool[][] image)
        {
            int READ_HORIZONTAL = 0;
            int READ_VERTICAL   = 1;

            int imageWidth  = image.Length;
            int imageHeight = image[0].Length;

            Point current = new Point();

            System.Collections.ArrayList lineAcross = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));

            int[] lengthBuffer  = new int[5];
            int   bufferPointer = 0;

            int  direction   = READ_HORIZONTAL;
            bool lastElement = QRCodeImageReader.POINT_LIGHT;

            while (true)
            {
                bool currentElement = image[current.X][current.Y];
                if (currentElement == lastElement)
                {
                    lengthBuffer[bufferPointer]++;
                }
                else
                {
                    if (currentElement == QRCodeImageReader.POINT_LIGHT)
                    {
                        if (checkPattern(lengthBuffer, bufferPointer))
                        {
                            int x1, y1, x2, y2;
                            if (direction == READ_HORIZONTAL)
                            {
                                x1 = current.X;
                                for (int j = 0; j < 5; j++)
                                {
                                    x1 -= lengthBuffer[j];
                                }
                                x2 = current.X - 1;
                                y1 = y2 = current.Y;
                            }
                            else
                            {
                                x1 = x2 = current.X;
                                y1 = current.Y;
                                for (int j = 0; j < 5; j++)
                                {
                                    y1 -= lengthBuffer[j];
                                }
                                y2 = current.Y - 1;
                            }
                            lineAcross.Add(new Line(x1, y1, x2, y2));
                        }
                    }
                    bufferPointer = (bufferPointer + 1) % 5;
                    lengthBuffer[bufferPointer] = 1;
                    lastElement = !lastElement;
                }

                if (direction == READ_HORIZONTAL)
                {
                    if (current.X < imageWidth - 1)
                    {
                        current.translate(1, 0);
                    }
                    else if (current.Y < imageHeight - 1)
                    {
                        current.set_Renamed(0, current.Y + 1);
                        lengthBuffer = new int[5];
                    }
                    else
                    {
                        current.set_Renamed(0, 0);
                        lengthBuffer = new int[5];
                        direction    = READ_VERTICAL;
                    }
                }
                else
                {
                    if (current.Y < imageHeight - 1)
                    {
                        current.translate(0, 1);
                    }
                    else if (current.X < imageWidth - 1)
                    {
                        current.set_Renamed(current.X + 1, 0);
                        lengthBuffer = new int[5];
                    }
                    else
                    {
                        break;
                    }
                }
            }


            Line[] foundLines = new Line[lineAcross.Count];

            for (int i = 0; i < foundLines.Length; i++)
            {
                foundLines[i] = (Line)lineAcross[i];
            }

            canvas.drawLines(foundLines, QRStudio.Engine.Codec.Util.Color_Fields.LIGHTGREEN);
            return(foundLines);
        }
예제 #2
0
        internal static Line[] findLineAcross(bool[][] image)
        {
            int       num    = 0;
            int       num2   = 1;
            int       length = image.Length;
            int       num4   = image[0].Length;
            Point     point  = new Point();
            ArrayList list   = ArrayList.Synchronized(new ArrayList(10));

            int[] buffer = new int[5];
            int   index  = 0;
            int   num6   = num;
            bool  flag   = false;

            while (true)
            {
                bool flag2 = image[point.X][point.Y];
                if (flag2 == flag)
                {
                    buffer[index]++;
                }
                else
                {
                    if (!flag2 && checkPattern(buffer, index))
                    {
                        int x;
                        int y;
                        int num9;
                        int num10;
                        int num11;
                        if (num6 == num)
                        {
                            x = point.X;
                            for (num11 = 0; num11 < 5; num11++)
                            {
                                x -= buffer[num11];
                            }
                            num9 = point.X - 1;
                            y    = num10 = point.Y;
                        }
                        else
                        {
                            x = num9 = point.X;
                            y = point.Y;
                            for (num11 = 0; num11 < 5; num11++)
                            {
                                y -= buffer[num11];
                            }
                            num10 = point.Y - 1;
                        }
                        list.Add(new Line(x, y, num9, num10));
                    }
                    index         = (index + 1) % 5;
                    buffer[index] = 1;
                    flag          = !flag;
                }
                if (num6 == num)
                {
                    if (point.X < (length - 1))
                    {
                        point.translate(1, 0);
                    }
                    else if (point.Y < (num4 - 1))
                    {
                        point.set_Renamed(0, point.Y + 1);
                        buffer = new int[5];
                    }
                    else
                    {
                        point.set_Renamed(0, 0);
                        buffer = new int[5];
                        num6   = num2;
                    }
                }
                else if (point.Y < (num4 - 1))
                {
                    point.translate(0, 1);
                }
                else if (point.X < (length - 1))
                {
                    point.set_Renamed(point.X + 1, 0);
                    buffer = new int[5];
                }
                else
                {
                    Line[] lines = new Line[list.Count];
                    for (int i = 0; i < lines.Length; i++)
                    {
                        lines[i] = (Line)list[i];
                    }
                    canvas.drawLines(lines, Color_Fields.LIGHTGREEN);
                    return(lines);
                }
            }
        }
예제 #3
0
        internal static Line[] findLineAcross(bool[][] image)
        {
            int READ_HORIZONTAL = 0;
            int READ_VERTICAL   = 1;

            int imageWidth  = image.Length;
            int imageHeight = image[0].Length;

            //int currentX = 0, currentY = 0;
            Point current = new Point();

            System.Collections.ArrayList lineAcross = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));

            //buffer contains recent length of modules which has same brightness
            int[] lengthBuffer  = new int[5];
            int   bufferPointer = 0;

            int  direction   = READ_HORIZONTAL;          //start to read horizontally
            bool lastElement = QRCodeImageReader.POINT_LIGHT;

            while (true)
            {
                //check points in image
                bool currentElement = image[current.X][current.Y];
                if (currentElement == lastElement)
                {
                    //target point has same brightness with last point
                    lengthBuffer[bufferPointer]++;
                }
                else
                {
                    //target point has different brightness with last point
                    if (currentElement == QRCodeImageReader.POINT_LIGHT)
                    {
                        if (checkPattern(lengthBuffer, bufferPointer))
                        {
                            //detected pattern
                            int x1, y1, x2, y2;
                            if (direction == READ_HORIZONTAL)
                            {
                                //obtain X coordinates of both side of the detected horizontal pattern
                                x1 = current.X;
                                for (int j = 0; j < 5; j++)
                                {
                                    x1 -= lengthBuffer[j];
                                }
                                x2 = current.X - 1;                                 //right side is last X coordinate
                                y1 = y2 = current.Y;
                            }
                            else
                            {
                                x1 = x2 = current.X;
                                //obtain Y coordinates of both side of the detected vertical pattern
                                // upper side is sum of length of buffer
                                y1 = current.Y;
                                for (int j = 0; j < 5; j++)
                                {
                                    y1 -= lengthBuffer[j];
                                }
                                y2 = current.Y - 1;                                 // bottom side is last Y coordinate
                            }
                            lineAcross.Add(new Line(x1, y1, x2, y2));
                        }
                    }
                    bufferPointer = (bufferPointer + 1) % 5;
                    lengthBuffer[bufferPointer] = 1;
                    lastElement = !lastElement;
                }

                // determine if read next, change read direction or terminate this loop
                if (direction == READ_HORIZONTAL)
                {
                    if (current.X < imageWidth - 1)
                    {
                        current.translate(1, 0);
                    }
                    else if (current.Y < imageHeight - 1)
                    {
                        current.set_Renamed(0, current.Y + 1);
                        lengthBuffer = new int[5];
                    }
                    else
                    {
                        current.set_Renamed(0, 0);                         //reset target point
                        lengthBuffer = new int[5];
                        direction    = READ_VERTICAL;                      //start to read vertically
                    }
                }
                else
                {
                    //reading vertically
                    if (current.Y < imageHeight - 1)
                    {
                        current.translate(0, 1);
                    }
                    else if (current.X < imageWidth - 1)
                    {
                        current.set_Renamed(current.X + 1, 0);
                        lengthBuffer = new int[5];
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Line[] foundLines = new Line[lineAcross.Count];

            for (int i = 0; i < foundLines.Length; i++)
            {
                foundLines[i] = (Line)lineAcross[i];
            }

            canvas.drawLines(foundLines, ThoughtWorks.QRCode.Codec.Util.Color_Fields.LIGHTGREEN);
            return(foundLines);
        }
예제 #4
0
        internal static Line[] findLineAcross(bool[][] image)
        {
            int       num       = 0;
            int       num2      = 1;
            int       num3      = image.Length;
            int       num4      = image[0].Length;
            Point     point     = new Point();
            ArrayList arrayList = ArrayList.Synchronized(new ArrayList(10));

            int[] array = new int[5];
            int   num5  = 0;
            int   num6  = num;
            bool  flag  = false;

            while (true)
            {
                bool flag2 = true;
                bool flag3 = image[point.X][point.Y];
                if (flag3 == flag)
                {
                    array[num5]++;
                }
                else
                {
                    if (!flag3 && checkPattern(array, num5))
                    {
                        int num7;
                        int x;
                        int num8;
                        int y;
                        if (num6 == num)
                        {
                            num7 = point.X;
                            for (int i = 0; i < 5; i++)
                            {
                                num7 -= array[i];
                            }
                            x    = point.X - 1;
                            num8 = (y = point.Y);
                        }
                        else
                        {
                            num7 = (x = point.X);
                            num8 = point.Y;
                            for (int i = 0; i < 5; i++)
                            {
                                num8 -= array[i];
                            }
                            y = point.Y - 1;
                        }
                        arrayList.Add(new Line(num7, num8, x, y));
                    }
                    num5        = (num5 + 1) % 5;
                    array[num5] = 1;
                    flag        = !flag;
                }
                if (num6 == num)
                {
                    if (point.X < num3 - 1)
                    {
                        point.translate(1, 0);
                    }
                    else if (point.Y < num4 - 1)
                    {
                        point.set_Renamed(0, point.Y + 1);
                        array = new int[5];
                    }
                    else
                    {
                        point.set_Renamed(0, 0);
                        array = new int[5];
                        num6  = num2;
                    }
                }
                else if (point.Y < num4 - 1)
                {
                    point.translate(0, 1);
                }
                else
                {
                    if (point.X >= num3 - 1)
                    {
                        break;
                    }
                    point.set_Renamed(point.X + 1, 0);
                    array = new int[5];
                }
            }
            Line[] array2 = new Line[arrayList.Count];
            for (int j = 0; j < array2.Length; j++)
            {
                array2[j] = (Line)arrayList[j];
            }
            canvas.drawLines(array2, Color_Fields.LIGHTGREEN);
            return(array2);
        }