mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Move RGBLuminanceSource to core/
git-svn-id: https://zxing.googlecode.com/svn/trunk@2389 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
144321067c
commit
4aa2358e31
|
@ -32,7 +32,7 @@ public final class BenchmarkActivity extends Activity {
|
||||||
|
|
||||||
private Button runBenchmarkButton;
|
private Button runBenchmarkButton;
|
||||||
private TextView textView;
|
private TextView textView;
|
||||||
private BenchmarkThread benchmarkThread;
|
private Thread benchmarkThread;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
|
@ -53,7 +53,7 @@ public final class BenchmarkActivity extends Activity {
|
||||||
if (benchmarkThread == null) {
|
if (benchmarkThread == null) {
|
||||||
runBenchmarkButton.setEnabled(false);
|
runBenchmarkButton.setEnabled(false);
|
||||||
textView.setText(R.string.benchmark_running);
|
textView.setText(R.string.benchmark_running);
|
||||||
benchmarkThread = new BenchmarkThread(BenchmarkActivity.this, PATH);
|
benchmarkThread = new Thread(new BenchmarkThread(BenchmarkActivity.this, PATH));
|
||||||
benchmarkThread.start();
|
benchmarkThread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,11 @@
|
||||||
|
|
||||||
package com.google.zxing.client.androidtest;
|
package com.google.zxing.client.androidtest;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import com.google.zxing.BinaryBitmap;
|
import com.google.zxing.BinaryBitmap;
|
||||||
import com.google.zxing.MultiFormatReader;
|
import com.google.zxing.MultiFormatReader;
|
||||||
|
import com.google.zxing.RGBLuminanceSource;
|
||||||
import com.google.zxing.ReaderException;
|
import com.google.zxing.ReaderException;
|
||||||
import com.google.zxing.Result;
|
import com.google.zxing.Result;
|
||||||
import com.google.zxing.common.HybridBinarizer;
|
import com.google.zxing.common.HybridBinarizer;
|
||||||
|
@ -27,12 +30,11 @@ import android.os.Message;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
final class BenchmarkThread extends Thread {
|
final class BenchmarkThread implements Runnable {
|
||||||
|
|
||||||
private static final String TAG = BenchmarkThread.class.getSimpleName();
|
private static final String TAG = BenchmarkThread.class.getSimpleName();
|
||||||
private static final int RUNS = 10;
|
private static final int RUNS = 10;
|
||||||
|
@ -78,14 +80,20 @@ final class BenchmarkThread extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
private BenchmarkItem decode(String path) {
|
private BenchmarkItem decode(String path) {
|
||||||
RGBLuminanceSource source;
|
|
||||||
try {
|
Bitmap imageBitmap = BitmapFactory.decodeFile(path);
|
||||||
source = new RGBLuminanceSource(path);
|
if (imageBitmap == null) {
|
||||||
} catch (FileNotFoundException e) {
|
Log.e(TAG, "Couldn't open " + path);
|
||||||
Log.e(TAG, e.toString());
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int width = imageBitmap.getWidth();
|
||||||
|
int height = imageBitmap.getHeight();
|
||||||
|
int[] pixels = new int[width * height];
|
||||||
|
imageBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
|
||||||
|
|
||||||
|
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
|
||||||
|
|
||||||
BenchmarkItem item = new BenchmarkItem(path, RUNS);
|
BenchmarkItem item = new BenchmarkItem(path, RUNS);
|
||||||
for (int x = 0; x < RUNS; x++) {
|
for (int x = 0; x < RUNS; x++) {
|
||||||
boolean success;
|
boolean success;
|
||||||
|
|
|
@ -14,18 +14,11 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.google.zxing.client.androidtest;
|
package com.google.zxing;
|
||||||
|
|
||||||
import com.google.zxing.LuminanceSource;
|
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to help decode images from files which arrive as RGB data from
|
* This class is used to help decode images from files which arrive as RGB data from
|
||||||
* Android bitmaps. It does not support cropping or rotation.
|
* an ARGB pixel array. It does not support cropping or rotation.
|
||||||
*
|
*
|
||||||
* @author dswitkin@google.com (Daniel Switkin)
|
* @author dswitkin@google.com (Daniel Switkin)
|
||||||
*/
|
*/
|
||||||
|
@ -33,18 +26,8 @@ public final class RGBLuminanceSource extends LuminanceSource {
|
||||||
|
|
||||||
private final byte[] luminances;
|
private final byte[] luminances;
|
||||||
|
|
||||||
public RGBLuminanceSource(String path) throws FileNotFoundException {
|
public RGBLuminanceSource(int width, int height, int[] pixels) {
|
||||||
this(loadBitmap(path));
|
super(width, height);
|
||||||
}
|
|
||||||
|
|
||||||
public RGBLuminanceSource(Bitmap bitmap) {
|
|
||||||
super(bitmap.getWidth(), bitmap.getHeight());
|
|
||||||
|
|
||||||
int width = bitmap.getWidth();
|
|
||||||
int height = bitmap.getHeight();
|
|
||||||
int[] pixels = new int[width * height];
|
|
||||||
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
|
|
||||||
|
|
||||||
// In order to measure pure decoding speed, we convert the entire image to a greyscale array
|
// In order to measure pure decoding speed, we convert the entire image to a greyscale array
|
||||||
// up front, which is the same as the Y channel of the YUVLuminanceSource in the real app.
|
// up front, which is the same as the Y channel of the YUVLuminanceSource in the real app.
|
||||||
luminances = new byte[width * height];
|
luminances = new byte[width * height];
|
||||||
|
@ -80,19 +63,13 @@ public final class RGBLuminanceSource extends LuminanceSource {
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since this class does not support cropping, the underlying byte array already contains
|
/**
|
||||||
// exactly what the caller is asking for, so give it to them without a copy.
|
* Since this class does not support cropping, the underlying byte array already contains
|
||||||
|
* exactly what the caller is asking for, so give it to them without a copy.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public byte[] getMatrix() {
|
public byte[] getMatrix() {
|
||||||
return luminances;
|
return luminances;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap loadBitmap(String path) throws FileNotFoundException {
|
|
||||||
Bitmap bitmap = BitmapFactory.decodeFile(path);
|
|
||||||
if (bitmap == null) {
|
|
||||||
throw new FileNotFoundException("Couldn't open " + path);
|
|
||||||
}
|
|
||||||
return bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue