DecodeHandler.java (zxing-zxing-3.4.0) | : | DecodeHandler.java (zxing-zxing-3.4.1) | ||
---|---|---|---|---|
skipping to change at line 32 | skipping to change at line 32 | |||
import com.google.zxing.MultiFormatReader; | import com.google.zxing.MultiFormatReader; | |||
import com.google.zxing.PlanarYUVLuminanceSource; | import com.google.zxing.PlanarYUVLuminanceSource; | |||
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; | |||
import android.os.Bundle; | import android.os.Bundle; | |||
import android.os.Handler; | import android.os.Handler; | |||
import android.os.Looper; | import android.os.Looper; | |||
import android.os.Message; | import android.os.Message; | |||
import android.util.Log; | ||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | |||
import java.util.Map; | import java.util.Map; | |||
import java.util.concurrent.TimeUnit; | ||||
final class DecodeHandler extends Handler { | final class DecodeHandler extends Handler { | |||
private static final String TAG = DecodeHandler.class.getSimpleName(); | ||||
private final CaptureActivity activity; | private final CaptureActivity activity; | |||
private final MultiFormatReader multiFormatReader; | private final MultiFormatReader multiFormatReader; | |||
private boolean running = true; | private boolean running = true; | |||
DecodeHandler(CaptureActivity activity, Map<DecodeHintType,Object> hints) { | DecodeHandler(CaptureActivity activity, Map<DecodeHintType,Object> hints) { | |||
multiFormatReader = new MultiFormatReader(); | multiFormatReader = new MultiFormatReader(); | |||
multiFormatReader.setHints(hints); | multiFormatReader.setHints(hints); | |||
this.activity = activity; | this.activity = activity; | |||
} | } | |||
skipping to change at line 77 | skipping to change at line 73 | |||
/** | /** | |||
* Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, | * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, | |||
* reuse the same reader objects from one decode to the next. | * reuse the same reader objects from one decode to the next. | |||
* | * | |||
* @param data The YUV preview frame. | * @param data The YUV preview frame. | |||
* @param width The width of the preview frame. | * @param width The width of the preview frame. | |||
* @param height The height of the preview frame. | * @param height The height of the preview frame. | |||
*/ | */ | |||
private void decode(byte[] data, int width, int height) { | private void decode(byte[] data, int width, int height) { | |||
long start = System.nanoTime(); | ||||
Result rawResult = null; | Result rawResult = null; | |||
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminance Source(data, width, height); | PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminance Source(data, width, height); | |||
if (source != null) { | if (source != null) { | |||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); | BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); | |||
try { | try { | |||
rawResult = multiFormatReader.decodeWithState(bitmap); | rawResult = multiFormatReader.decodeWithState(bitmap); | |||
} catch (ReaderException re) { | } catch (ReaderException re) { | |||
// continue | // continue | |||
} finally { | } finally { | |||
multiFormatReader.reset(); | multiFormatReader.reset(); | |||
} | } | |||
} | } | |||
Handler handler = activity.getHandler(); | Handler handler = activity.getHandler(); | |||
if (rawResult != null) { | if (rawResult != null) { | |||
// Don't log the barcode contents for security. | // Don't log the barcode contents for security. | |||
long end = System.nanoTime(); | ||||
Log.d(TAG, "Found barcode in " + TimeUnit.NANOSECONDS.toMillis(end - start | ||||
) + " ms"); | ||||
if (handler != null) { | if (handler != null) { | |||
Message message = Message.obtain(handler, R.id.decode_succeeded, rawResu lt); | Message message = Message.obtain(handler, R.id.decode_succeeded, rawResu lt); | |||
Bundle bundle = new Bundle(); | Bundle bundle = new Bundle(); | |||
bundleThumbnail(source, bundle); | bundleThumbnail(source, bundle); | |||
message.setData(bundle); | message.setData(bundle); | |||
message.sendToTarget(); | message.sendToTarget(); | |||
} | } | |||
} else { | } else { | |||
if (handler != null) { | if (handler != null) { | |||
Message message = Message.obtain(handler, R.id.decode_failed); | Message message = Message.obtain(handler, R.id.decode_failed); | |||
End of changes. 5 change blocks. | ||||
8 lines changed or deleted | 0 lines changed or added |