Make some stuff to public to compile
[zxing.git] / bug / src / com / google / zxing / client / bug / AWTImageMonochromeBitmapSource.java
index 6752cb3..22bb5bc 100644 (file)
@@ -33,13 +33,12 @@ import java.awt.image.PixelGrabber;
  */
 public final class AWTImageMonochromeBitmapSource extends BaseMonochromeBitmapSource {
 
-  private final int height;
-  private final int width;
   private final int[] pixels;
 
   public AWTImageMonochromeBitmapSource(Image image) throws ReaderException {
-    height = image.getHeight(null);
-    width = image.getWidth(null);
+    super(image.getWidth(null), image.getHeight(null));
+    int height = getHeight();
+    int width = getWidth();
     pixels = new int[height * width];
     // Seems best in this situation to grab all pixels upfront. Grabbing any individual pixel
     // entails creating a relatively expensive object and calling through several methods.
@@ -47,31 +46,51 @@ public final class AWTImageMonochromeBitmapSource extends BaseMonochromeBitmapSo
     try {
       grabber.grabPixels();
     } catch (InterruptedException ie) {
-      throw new ReaderException("Interrupted while reading pixels");
+      throw ReaderException.getInstance();
     }
   }
 
-  public int getHeight() {
-    return height;
-  }
-
-  public int getWidth() {
-    return width;
-  }
-
   /**
    * See <code>com.google.zxing.client.j2me.LCDUIImageMonochromeBitmapSource</code> for more explanation
    * of the computation used in this method.
    */
   public int getLuminance(int x, int y) {
-    int pixel = pixels[x * width + y];
+    int pixel = pixels[y * getWidth() + x];
     return (((pixel & 0x00FF0000) >> 16) +
             ((pixel & 0x0000FF00) >>  7) +
              (pixel & 0x000000FF       )) >> 2;
   }
 
-  public void cacheRowForLuminance(int y) {
-    // do nothing; we are already forced to cache all pixels
+  public int[] getLuminanceRow(int y, int[] row) {
+    int width = getWidth();
+    if (row == null || row.length < width) {
+      row = new int[width];
+    }
+    int offset = y * width;
+    for (int x = 0; x < width; x++) {
+      int pixel = pixels[offset + x];
+      row[x] = (((pixel & 0x00FF0000) >> 16) +
+                ((pixel & 0x0000FF00) >>  7) +
+                 (pixel & 0x000000FF       )) >> 2;
+    }
+    return row;
+  }
+
+  public int[] getLuminanceColumn(int x, int[] column) {
+    int height = getHeight();
+    int width = getWidth();
+    if (column == null || column.length < height) {
+      column = new int[height];
+    }
+    int offset = x;
+    for (int y = 0; y < height; y++) {
+      int pixel = pixels[offset];
+      column[y] = (((pixel & 0x00FF0000) >> 16) +
+                   ((pixel & 0x0000FF00) >>  7) +
+                    (pixel & 0x000000FF       )) >> 2;
+      offset += width;
+    }
+    return column;
   }
 
 }