set_Renamed() public method

Sets the given bit to true.

public set_Renamed ( int x, int y ) : void
x int The horizontal component (i.e. which column) ///
y int The vertical component (i.e. which row) ///
return void
Esempio n. 1
0
        //private final ReedSolomonDecoder rsDecoder;

        /// <summary> <p>Convenience method that can decode a PDF417 Code represented as a 2D array of booleans.
        /// "true" is taken to mean a black module.</p>
        /// 
        /// </summary>
        /// <param name="image">booleans representing white/black PDF417 modules
        /// </param>
        /// <returns> text and bytes encoded within the PDF417 Code
        /// </returns>
        /// <throws>  ReaderException if the PDF417 Code cannot be decoded </throws>
        public DecoderResult decode(bool[][] image)
        {
            int dimension = image.Length;
            var bits = new BitMatrix(dimension);
            for (int i = 0; i < dimension; i++)
            {
                for (int j = 0; j < dimension; j++)
                {
                    if (image[j][i])
                    {
                        bits.set_Renamed(j, i);
                    }
                }
            }
            return decode(bits);
        }
        public override BitMatrix sampleGrid(BitMatrix image, int dimension, PerspectiveTransform transform)
        {
            var bits = new BitMatrix(dimension);
            var points = new float[dimension << 1];
            for (int y = 0; y < dimension; y++)
            {
                int max = points.Length;

                float iValue = y + 0.5f;
                for (int x = 0; x < max; x += 2)
                {

                    points[x] = (x >> 1) + 0.5f;
                    points[x + 1] = iValue;
                }
                transform.transformPoints(points);
                // Quick check to see if points transformed to something inside the image;
                // sufficient to check the endpoints
                checkAndNudgePoints(image, points);
                try
                {
                    for (int x = 0; x < max; x += 2)
                    {

                        if (image.get_Renamed((int) points[x], (int) points[x + 1]))
                        {
                            // Black(-ish) pixel
                            bits.set_Renamed(x >> 1, y);
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    // This feels wrong, but, sometimes if the finder patterns are misidentified, the resulting
                    // transform gets "twisted" such that it maps a straight line of points to a set of points
                    // whose endpoints are in bounds, but others are not. There is probably some mathematical
                    // way to detect this about the transformation that I don't know yet.
                    // This results in an ugly runtime exception despite our clever checks above -- can't have
                    // that. We could check each point's coordinates but that feels duplicative. We settle for
                    // catching and wrapping ArrayIndexOutOfBoundsException.
                    throw ReaderException.Instance;
                }
            }
            return bits;
        }
Esempio n. 3
0
        /// <summary> This method detects a barcode in a "pure" image -- that is, pure monochrome image
        /// which contains only an unrotated, unskewed, image of a barcode, with some white border
        /// around it. This is a specialized method that works exceptionally fast in this special
        /// case.
        /// </summary>
        private static BitMatrix extractPureBits(BinaryBitmap image)
        {
            // Now need to determine module size in pixels
            BitMatrix matrix = image.BlackMatrix;
            int height = matrix.Height;
            int width = matrix.Width;
            int minDimension = Math.Min(height, width);

            // First, skip white border by tracking diagonally from the top left down and to the right:
            int borderWidth = 0;
            while (borderWidth < minDimension && !matrix.get_Renamed(borderWidth, borderWidth))
            {
                borderWidth++;
            }
            if (borderWidth == minDimension)
            {
                throw ReaderException.Instance;
            }

            // And then keep tracking across the top-left black module to determine module size
            int moduleEnd = borderWidth;
            while (moduleEnd < minDimension && matrix.get_Renamed(moduleEnd, moduleEnd))
            {
                moduleEnd++;
            }
            if (moduleEnd == minDimension)
            {
                throw ReaderException.Instance;
            }

            int moduleSize = moduleEnd - borderWidth;

            // And now find where the rightmost black module on the first row ends
            int rowEndOfSymbol = width - 1;
            while (rowEndOfSymbol >= 0 && !matrix.get_Renamed(rowEndOfSymbol, borderWidth))
            {
                rowEndOfSymbol--;
            }
            if (rowEndOfSymbol < 0)
            {
                throw ReaderException.Instance;
            }
            rowEndOfSymbol++;

            // Make sure width of barcode is a multiple of module size
            if ((rowEndOfSymbol - borderWidth)%moduleSize != 0)
            {
                throw ReaderException.Instance;
            }
            int dimension = (rowEndOfSymbol - borderWidth)/moduleSize;

            // Push in the "border" by half the module width so that we start
            // sampling in the middle of the module. Just in case the image is a
            // little off, this will help recover.
            borderWidth += (moduleSize >> 1);

            int sampleDimension = borderWidth + (dimension - 1)*moduleSize;
            if (sampleDimension >= width || sampleDimension >= height)
            {
                throw ReaderException.Instance;
            }

            // Now just read off the bits
            var bits = new BitMatrix(dimension);
            for (int y = 0; y < dimension; y++)
            {
                int iOffset = borderWidth + y*moduleSize;
                for (int x = 0; x < dimension; x++)
                {
                    if (matrix.get_Renamed(borderWidth + x*moduleSize, iOffset))
                    {
                        bits.set_Renamed(x, y);
                    }
                }
            }
            return bits;
        }
Esempio n. 4
0
        /// <summary> This method detects a Data Matrix code in a "pure" image -- that is, pure monochrome image
        /// which contains only an unrotated, unskewed, image of a Data Matrix code, with some white border
        /// around it. This is a specialized method that works exceptionally fast in this special
        /// case.
        /// </summary>
        private static BitMatrix extractPureBits(BitMatrix image)
        {
            // Now need to determine module size in pixels

            int height = image.Height;
            int width = image.Width;
            int minDimension = Math.Min(height, width);

            // First, skip white border by tracking diagonally from the top left down and to the right:
            int borderWidth = 0;
            while (borderWidth < minDimension && !image.get_Renamed(borderWidth, borderWidth))
            {
                borderWidth++;
            }
            if (borderWidth == minDimension)
            {
                throw ReaderException.Instance;
            }

            // And then keep tracking across the top-left black module to determine module size
            int moduleEnd = borderWidth + 1;
            while (moduleEnd < width && image.get_Renamed(moduleEnd, borderWidth))
            {
                moduleEnd++;
            }
            if (moduleEnd == width)
            {
                throw ReaderException.Instance;
            }

            int moduleSize = moduleEnd - borderWidth;

            // And now find where the bottommost black module on the first column ends
            int columnEndOfSymbol = height - 1;
            while (columnEndOfSymbol >= 0 && !image.get_Renamed(borderWidth, columnEndOfSymbol))
            {
                columnEndOfSymbol--;
            }
            if (columnEndOfSymbol < 0)
            {
                throw ReaderException.Instance;
            }
            columnEndOfSymbol++;

            // Make sure width of barcode is a multiple of module size
            if ((columnEndOfSymbol - borderWidth)%moduleSize != 0)
            {
                throw ReaderException.Instance;
            }
            int dimension = (columnEndOfSymbol - borderWidth)/moduleSize;

            // Push in the "border" by half the module width so that we start
            // sampling in the middle of the module. Just in case the image is a
            // little off, this will help recover.
            borderWidth += (moduleSize >> 1);

            int sampleDimension = borderWidth + (dimension - 1)*moduleSize;
            if (sampleDimension >= width || sampleDimension >= height)
            {
                throw ReaderException.Instance;
            }

            // Now just read off the bits
            var bits = new BitMatrix(dimension);
            for (int i = 0; i < dimension; i++)
            {
                int iOffset = borderWidth + i*moduleSize;
                for (int j = 0; j < dimension; j++)
                {
                    if (image.get_Renamed(borderWidth + j*moduleSize, iOffset))
                    {
                        bits.set_Renamed(j, i);
                    }
                }
            }
            return bits;
        }