mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -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 TextView textView;
|
||||
private BenchmarkThread benchmarkThread;
|
||||
private Thread benchmarkThread;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
|
@ -53,7 +53,7 @@ public final class BenchmarkActivity extends Activity {
|
|||
if (benchmarkThread == null) {
|
||||
runBenchmarkButton.setEnabled(false);
|
||||
textView.setText(R.string.benchmark_running);
|
||||
benchmarkThread = new BenchmarkThread(BenchmarkActivity.this, PATH);
|
||||
benchmarkThread = new Thread(new BenchmarkThread(BenchmarkActivity.this, PATH));
|
||||
benchmarkThread.start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,11 @@
|
|||
|
||||
package com.google.zxing.client.androidtest;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.RGBLuminanceSource;
|
||||
import com.google.zxing.ReaderException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
|
@ -27,12 +30,11 @@ import android.os.Message;
|
|||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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 int RUNS = 10;
|
||||
|
@ -78,14 +80,20 @@ final class BenchmarkThread extends Thread {
|
|||
}
|
||||
|
||||
private BenchmarkItem decode(String path) {
|
||||
RGBLuminanceSource source;
|
||||
try {
|
||||
source = new RGBLuminanceSource(path);
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
|
||||
Bitmap imageBitmap = BitmapFactory.decodeFile(path);
|
||||
if (imageBitmap == null) {
|
||||
Log.e(TAG, "Couldn't open " + path);
|
||||
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);
|
||||
for (int x = 0; x < RUNS; x++) {
|
||||
boolean success;
|
||||
|
|
|
@ -14,18 +14,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.androidtest;
|
||||
|
||||
import com.google.zxing.LuminanceSource;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
package com.google.zxing;
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
|
@ -33,18 +26,8 @@ public final class RGBLuminanceSource extends LuminanceSource {
|
|||
|
||||
private final byte[] luminances;
|
||||
|
||||
public RGBLuminanceSource(String path) throws FileNotFoundException {
|
||||
this(loadBitmap(path));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
public RGBLuminanceSource(int width, int height, int[] pixels) {
|
||||
super(width, height);
|
||||
// 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.
|
||||
luminances = new byte[width * height];
|
||||
|
@ -80,19 +63,13 @@ public final class RGBLuminanceSource extends LuminanceSource {
|
|||
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
|
||||
public byte[] getMatrix() {
|
||||
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