/// <summary>
        /// Applies simple sharpening to the row data to improve performance of the 1D Readers.
        /// </summary>
        /// <param name="y"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public override BitArray getBlackRow(int y, BitArray row)
        {
            LuminanceSource source = LuminanceSource;
            int             width  = source.Width;

            if (row == null || row.Size < width)
            {
                row = new BitArray(width);
            }
            else
            {
                row.clear();
            }

            initArrays(width);
            byte[] localLuminances = source.getRow(y, luminances);
            int[]  localBuckets    = buckets;
            for (int x = 0; x < width; x++)
            {
                localBuckets[(localLuminances[x] & 0xff) >> LUMINANCE_SHIFT]++;
            }
            int blackPoint;

            if (!estimateBlackPoint(localBuckets, out blackPoint))
            {
                return(null);
            }

            if (width < 3)
            {
                // Special case for very small images
                for (int x = 0; x < width; x++)
                {
                    if ((localLuminances[x] & 0xff) < blackPoint)
                    {
                        row[x] = true;
                    }
                }
            }
            else
            {
                int left   = localLuminances[0] & 0xff;
                int center = localLuminances[1] & 0xff;
                for (int x = 1; x < width - 1; x++)
                {
                    int right = localLuminances[x + 1] & 0xff;
                    // A simple -1 4 -1 box filter with a weight of 2.
                    // ((center << 2) - left - right) >> 1
                    if (((center * 4) - left - right) / 2 < blackPoint)
                    {
                        row[x] = true;
                    }
                    left   = center;
                    center = right;
                }
            }

            return(row);
        }
Exemple #2
0
        /// <summary>
        /// Fetches one row of luminance data from the underlying platform's bitmap. Values range from
        /// 0 (black) to 255 (white). Because Java does not have an unsigned byte type, callers will have
        /// to bitwise and with 0xff for each value. It is preferable for implementations of this method
        /// to only fetch this row rather than the whole image, since no 2D Readers may be installed and
        /// getMatrix() may never be called.
        /// </summary>
        /// <param name="y">The row to fetch, 0 &lt;= y &lt; Height.</param>
        /// <param name="row">An optional preallocated array. If null or too small, it will be ignored.
        /// Always use the returned object, and ignore the .length of the array.</param>
        /// <returns>
        /// An array containing the luminance data.
        /// </returns>
        override public byte[] getRow(int y, byte[] row)
        {
            row = @delegate.getRow(y, row);
            int width = Width;

            for (int i = 0; i < width; i++)
            {
                row[i] = (byte)(255 - (row[i] & 0xFF));
            }
            return(row);
        }
Exemple #3
0
        public void testCrop()
        {
            Assert.IsTrue(SOURCE.CropSupported);
            LuminanceSource cropped = SOURCE.crop(1, 1, 1, 1);

            Assert.AreEqual(1, cropped.Height);
            Assert.AreEqual(1, cropped.Width);
            // java and .Net differs, not sure, why
            //var expectedInJava = new byte[] {0x7F};
            var expected = new byte[] { 0x95 };

            Assert.AreEqual(expected, cropped.getRow(0, null));
        }
Exemple #4
0
        // Applies simple sharpening to the row data to improve performance of the 1D Readers.
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public BitArray getBlackRow(int y, BitArray row) throws com.google.zxing.NotFoundException
        public override BitArray getBlackRow(int y, BitArray row)
        {
            LuminanceSource source = LuminanceSource;
            int             width  = source.Width;

            if (row == null || row.Size < width)
            {
                row = new BitArray(width);
            }
            else
            {
                //row.SetAll(false);
                row.clear();
            }

            initArrays(width);
            sbyte[] localLuminances = source.getRow(y, luminances);
            int[]   localBuckets    = buckets;
            for (int x = 0; x < width; x++)
            {
                int pixel = localLuminances[x] & 0xff;
                localBuckets[pixel >> LUMINANCE_SHIFT]++;
            }
            int blackPoint = estimateBlackPoint(localBuckets);

            int left   = localLuminances[0] & 0xff;
            int center = localLuminances[1] & 0xff;

            for (int x = 1; x < width - 1; x++)
            {
                int right = localLuminances[x + 1] & 0xff;
                // A simple -1 4 -1 box filter with a weight of 2.
                int luminance = ((center << 2) - left - right) >> 1;
                if (luminance < blackPoint)
                {
                    //row.Set(x, true);
                    row.set(x);
                }
                left   = center;
                center = right;
            }
            return(row);
        }