mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Made this more like RGBMonochromBitmapSource, caching a row instead of the whole image
git-svn-id: https://zxing.googlecode.com/svn/trunk@425 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
d77371d5fc
commit
20df62a8af
|
@ -27,15 +27,20 @@ import javax.microedition.lcdui.Image;
|
||||||
*/
|
*/
|
||||||
public final class LCDUIImageMonochromeBitmapSource extends BaseMonochromeBitmapSource {
|
public final class LCDUIImageMonochromeBitmapSource extends BaseMonochromeBitmapSource {
|
||||||
|
|
||||||
private final int[] rgbPixels;
|
private final Image image;
|
||||||
private final int width;
|
|
||||||
private final int height;
|
private final int height;
|
||||||
|
private final int width;
|
||||||
|
private final int[] rgbRow;
|
||||||
|
private final int[] pixelHolder;
|
||||||
|
private int cachedRow;
|
||||||
|
|
||||||
public LCDUIImageMonochromeBitmapSource(Image image) {
|
public LCDUIImageMonochromeBitmapSource(Image image) {
|
||||||
width = image.getWidth();
|
this.image = image;
|
||||||
height = image.getHeight();
|
height = image.getHeight();
|
||||||
rgbPixels = new int[width * height];
|
width = image.getWidth();
|
||||||
image.getRGB(rgbPixels, 0, width, 0, 0, width, height);
|
rgbRow = new int[width];
|
||||||
|
pixelHolder = new int[1];
|
||||||
|
cachedRow = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
|
@ -47,7 +52,13 @@ public final class LCDUIImageMonochromeBitmapSource extends BaseMonochromeBitmap
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLuminance(int x, int y) {
|
public int getLuminance(int x, int y) {
|
||||||
int pixel = rgbPixels[y * width + x];
|
int pixel;
|
||||||
|
if (cachedRow == y) {
|
||||||
|
pixel = rgbRow[x];
|
||||||
|
} else {
|
||||||
|
image.getRGB(pixelHolder, 0, width, x, y, 1, 1);
|
||||||
|
pixel = pixelHolder[0];
|
||||||
|
}
|
||||||
|
|
||||||
// Instead of multiplying by 306, 601, 117, we multiply by 256, 512, 256, so that
|
// Instead of multiplying by 306, 601, 117, we multiply by 256, 512, 256, so that
|
||||||
// the multiplies can be implemented as shifts.
|
// the multiplies can be implemented as shifts.
|
||||||
|
@ -66,9 +77,11 @@ public final class LCDUIImageMonochromeBitmapSource extends BaseMonochromeBitmap
|
||||||
(pixel & 0x000000FF )) >> 2;
|
(pixel & 0x000000FF )) >> 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing to do, since we have direct access to the image data.
|
|
||||||
public void cacheRowForLuminance(int y) {
|
public void cacheRowForLuminance(int y) {
|
||||||
|
if (y != cachedRow) {
|
||||||
|
image.getRGB(rgbRow, 0, width, 0, y, width, 1);
|
||||||
|
cachedRow = y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue