Oops, off-by-one bug fix, and some more comments
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 7 Apr 2008 20:32:17 +0000 (20:32 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 7 Apr 2008 20:32:17 +0000 (20:32 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@350 59b500cc-1b3d-0410-9834-0bbf25fbcc57

javase/src/com/google/zxing/client/j2se/BufferedImageMonochromeBitmapSource.java

index bfe97bc..dd7c584 100644 (file)
@@ -53,10 +53,25 @@ public final class BufferedImageMonochromeBitmapSource implements MonochromeBitm
   private static final int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS;
   private static final int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS;
 
+  /**
+   * Creates an instance that uses the entire given image as a source of pixels to decode.
+   *
+   * @param image image to decode
+   */
   public BufferedImageMonochromeBitmapSource(BufferedImage image) {
     this(image, 0, 0, image.getWidth(), image.getHeight());
   }
 
+  /**
+   * Creates an instance that uses only a region of the given image as a source of pixels to decode.
+   *
+   * @param image image to decode a region of
+   * @param left x coordinate of leftmost pixels to decode
+   * @param top y coordinate of topmost pixels to decode
+   * @param right one more than the x coordinate of rightmost pixels to decode. That is, we will decode
+   *  pixels whose x coordinate is in [left,right)
+   * @param bottom likewise, one more than the y coordinate of the bottommost pixels to decode
+   */
   public BufferedImageMonochromeBitmapSource(BufferedImage image, int left, int top, int right, int bottom) {
     this.image = image;
     blackPoint = 0x7F;
@@ -64,7 +79,7 @@ public final class BufferedImageMonochromeBitmapSource implements MonochromeBitm
     lastArgument = 0;
     int sourceHeight = image.getHeight();
     int sourceWidth = image.getWidth();
-    if (left < 0 || top < 0 || right >= sourceWidth || bottom >= sourceHeight || right <= left || bottom <= top) {
+    if (left < 0 || top < 0 || right > sourceWidth || bottom > sourceHeight || right <= left || bottom <= top) {
       throw new IllegalArgumentException("Invalid bounds: (" + top + ',' + left + ") (" + right + ',' + bottom + ')');
     }
     this.left = left;