Exemplo n.º 1
0
 public void estimateBlackPoint(BlackPointEstimationMethod method, int argument)
 {
     if (!method.Equals(lastMethod) || argument != lastArgument)
     {
         int   width     = getWidth();
         int   height    = getHeight();
         int[] histogram = new int[LUMINANCE_BUCKETS];
         if (method.Equals(BlackPointEstimationMethod.TWO_D_SAMPLING))
         {
             int minDimension = width < height ? width : height;
             int startX       = (width - minDimension) >> 1;
             int startY       = (height - minDimension) >> 1;
             for (int n = 0; n < minDimension; n++)
             {
                 int luminance = getLuminance(startX + n, startY + n);
                 histogram[luminance >> LUMINANCE_SHIFT]++;
             }
         }
         else if (method.Equals(BlackPointEstimationMethod.ROW_SAMPLING))
         {
             if (argument < 0 || argument >= height)
             {
                 throw new Exception("Row is not within the image: " + argument);
             }
             initLuminances();
             luminances = getLuminanceRow(argument, luminances);
             for (int x = 0; x < width; x++)
             {
                 histogram[luminances[x] >> LUMINANCE_SHIFT]++;
             }
         }
         else
         {
             throw new Exception("Unknown method: " + method);
         }
         blackPoint   = BlackPointEstimator.estimate(histogram) << LUMINANCE_SHIFT;
         lastMethod   = method;
         lastArgument = argument;
     }
 }
Exemplo n.º 2
0
        public BitArray getBlackRow(int y, BitArray row, int startX, int getWidth)
        {
            if (row == null || row.getSize() < getWidth)
            {
                row = new BitArray(getWidth);
            }
            else
            {
                row.clear();
            }

            // Reuse the same int array each time
            initLuminances();
            luminances = getLuminanceRow(y, luminances);

            // If the current decoder calculated the blackPoint based on one row, assume we're trying to
            // decode a 1D barcode, and apply some sharpening.
            if (lastMethod.Equals(BlackPointEstimationMethod.ROW_SAMPLING))
            {
                int left   = luminances[startX];
                int center = luminances[startX + 1];
                for (int x = 1; x < getWidth - 1; x++)
                {
                    int right = luminances[startX + x + 1];
                    // Simple -1 4 -1 box filter with a weight of 2
                    int luminance = ((center << 2) - left - right) >> 1;
                    if (luminance < blackPoint)
                    {
                        row.set(x);
                    }
                    left   = center;
                    center = right;
                }
            }
            else
            {
                for (int x = 0; x < getWidth; x++)
                {
                    if (luminances[startX + x] < blackPoint)
                    {
                        row.set(x);
                    }
                }
            }
            return(row);
        }
 public void estimateBlackPoint(BlackPointEstimationMethod method, int argument){
   if (!method.Equals(lastMethod) || argument != lastArgument) {
     int width = getWidth();
     int height = getHeight();
     int[] histogram = new int[LUMINANCE_BUCKETS];
     if (method.Equals(BlackPointEstimationMethod.TWO_D_SAMPLING)) {
       int minDimension = width < height ? width : height;
       int startX = (width - minDimension) >> 1;
       int startY = (height - minDimension) >> 1;
       for (int n = 0; n < minDimension; n++) {
         int luminance = getLuminance(startX + n, startY + n);
         histogram[luminance >> LUMINANCE_SHIFT]++;
       }
     } else if (method.Equals(BlackPointEstimationMethod.ROW_SAMPLING)) {
       if (argument < 0 || argument >= height) {
         throw new Exception("Row is not within the image: " + argument);
       }
       initLuminances();
       luminances = getLuminanceRow(argument, luminances);
       for (int x = 0; x < width; x++) {
         histogram[luminances[x] >> LUMINANCE_SHIFT]++;
       }
     } else {
         throw new Exception("Unknown method: " + method);
     }
     blackPoint = BlackPointEstimator.estimate(histogram) << LUMINANCE_SHIFT;
     lastMethod = method;
     lastArgument = argument;
   }
 }