mirror of
https://github.com/zxing/zxing.git
synced 2025-01-13 20:27:34 -08:00
Slightly smarter version of last change
git-svn-id: https://zxing.googlecode.com/svn/trunk@891 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
de31f7a387
commit
64686b9fb1
|
@ -38,6 +38,7 @@ final class SnapshotThread implements Runnable {
|
||||||
private final Object waitLock;
|
private final Object waitLock;
|
||||||
private volatile boolean done;
|
private volatile boolean done;
|
||||||
private final MultimediaManager multimediaManager;
|
private final MultimediaManager multimediaManager;
|
||||||
|
private String bestEncoding;
|
||||||
|
|
||||||
SnapshotThread(ZXingMIDlet zXingMIDlet) {
|
SnapshotThread(ZXingMIDlet zXingMIDlet) {
|
||||||
this.zXingMIDlet = zXingMIDlet;
|
this.zXingMIDlet = zXingMIDlet;
|
||||||
|
@ -92,30 +93,12 @@ final class SnapshotThread implements Runnable {
|
||||||
|
|
||||||
private byte[] takeSnapshot() throws MediaException {
|
private byte[] takeSnapshot() throws MediaException {
|
||||||
|
|
||||||
// Check this property, present on some Nokias?
|
String bestEncoding = guessBestEncoding();
|
||||||
String supportsVideoCapture = System.getProperty("supports.video.capture");
|
|
||||||
if ("false".equals(supportsVideoCapture)) {
|
|
||||||
throw new MediaException("supports.video.capture is false");
|
|
||||||
}
|
|
||||||
|
|
||||||
String bestEncoding = null;
|
|
||||||
String videoSnapshotEncodings = System.getProperty("video.snapshot.encodings");
|
|
||||||
if (videoSnapshotEncodings != null) {
|
|
||||||
// We know explicitly what the camera supports; see if PNG is among them since
|
|
||||||
// Image.createImage() should always support it
|
|
||||||
int pngEncodingStart = videoSnapshotEncodings.indexOf("encoding=png");
|
|
||||||
if (pngEncodingStart >= 0) {
|
|
||||||
int space = videoSnapshotEncodings.indexOf(' ', pngEncodingStart);
|
|
||||||
bestEncoding = space >= 0 ?
|
|
||||||
videoSnapshotEncodings.substring(pngEncodingStart, space) :
|
|
||||||
videoSnapshotEncodings.substring(pngEncodingStart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VideoControl videoControl = zXingMIDlet.getVideoControl();
|
VideoControl videoControl = zXingMIDlet.getVideoControl();
|
||||||
byte[] snapshot = null;
|
byte[] snapshot = null;
|
||||||
try {
|
try {
|
||||||
snapshot = videoControl.getSnapshot(bestEncoding);
|
snapshot = videoControl.getSnapshot("".equals(bestEncoding) ? null : bestEncoding);
|
||||||
} catch (MediaException me) {
|
} catch (MediaException me) {
|
||||||
}
|
}
|
||||||
if (snapshot == null) {
|
if (snapshot == null) {
|
||||||
|
@ -129,4 +112,29 @@ final class SnapshotThread implements Runnable {
|
||||||
return snapshot;
|
return snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized String guessBestEncoding() throws MediaException {
|
||||||
|
if (bestEncoding == null) {
|
||||||
|
// Check this property, present on some Nokias?
|
||||||
|
String supportsVideoCapture = System.getProperty("supports.video.capture");
|
||||||
|
if ("false".equals(supportsVideoCapture)) {
|
||||||
|
throw new MediaException("supports.video.capture is false");
|
||||||
|
}
|
||||||
|
|
||||||
|
bestEncoding = "";
|
||||||
|
String videoSnapshotEncodings = System.getProperty("video.snapshot.encodings");
|
||||||
|
if (videoSnapshotEncodings != null) {
|
||||||
|
// We know explicitly what the camera supports; see if PNG is among them since
|
||||||
|
// Image.createImage() should always support it
|
||||||
|
int pngEncodingStart = videoSnapshotEncodings.indexOf("encoding=png");
|
||||||
|
if (pngEncodingStart >= 0) {
|
||||||
|
int space = videoSnapshotEncodings.indexOf(' ', pngEncodingStart);
|
||||||
|
bestEncoding = space >= 0 ?
|
||||||
|
videoSnapshotEncodings.substring(pngEncodingStart, space) :
|
||||||
|
videoSnapshotEncodings.substring(pngEncodingStart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bestEncoding;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue