X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=android%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fandroid%2FCameraManager.java;h=8b7ae730e5d997d96027ae7c7b9477aa5cfb73f0;hb=acdc884c319f62186da2f9dfa42ce8dc27e79696;hp=fd4a3662070e6d8edaf5fcb35dfa758680dac488;hpb=2928327fe47e3bf901adbe88a72df525f30d0604;p=zxing.git diff --git a/android/src/com/google/zxing/client/android/CameraManager.java b/android/src/com/google/zxing/client/android/CameraManager.java index fd4a3662..8b7ae730 100755 --- a/android/src/com/google/zxing/client/android/CameraManager.java +++ b/android/src/com/google/zxing/client/android/CameraManager.java @@ -124,8 +124,8 @@ final class CameraManager { // Camera.setOneShotPreviewCallback() has a race condition in Cupcake, so we use the older // Camera.setPreviewCallback() on 1.5 and earlier. For Donut and later, we need to use // the more efficient one shot callback, as the older one can swamp the system and cause it - // to run out of memory. - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.CUPCAKE) { + // to run out of memory. We can't use SDK_INT because it was introduced in the Donut SDK. + if (Integer.parseInt(Build.VERSION.SDK) <= Build.VERSION_CODES.CUPCAKE) { useOneShotPreviewCallback = false; } else { useOneShotPreviewCallback = true; @@ -279,24 +279,31 @@ final class CameraManager { * @param data A preview frame. * @param width The width of the image. * @param height The height of the image. - * @return A BaseLuminanceSource subclass. + * @return A PlanarYUVLuminanceSource instance. */ - public BaseLuminanceSource buildLuminanceSource(byte[] data, int width, int height) { + public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) { Rect rect = getFramingRect(); switch (previewFormat) { + // This is the standard Android format which all devices are REQUIRED to support. + // In theory, it's the only one we should ever care about. case PixelFormat.YCbCr_420_SP: + return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, + rect.width(), rect.height()); + // This format has never been seen in the wild, but is compatible as we only care + // about the Y channel, so allow it. case PixelFormat.YCbCr_422_SP: return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect.height()); default: - // There's no PixelFormat constant for this buffer format yet. - if (previewFormatString.equals("yuv422i-yuyv")) { - return new InterleavedYUV422LuminanceSource(data, width, height, rect.left, rect.top, - rect.width(), rect.height()); + // The Samsung Moment incorrectly uses this variant instead of the 'sp' version. + // Fortunately, it too has all the Y data up front, so we can read it. + if (previewFormatString.equals("yuv420p")) { + return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, + rect.width(), rect.height()); } - break; } - return null; + throw new IllegalArgumentException("Unsupported picture format: " + + previewFormat + '/' + previewFormatString); } /** @@ -311,7 +318,7 @@ final class CameraManager { Log.v(TAG, "Default preview size: " + size.width + ", " + size.height); previewFormat = parameters.getPreviewFormat(); previewFormatString = parameters.get("preview-format"); - Log.v(TAG, "Default preview format: " + previewFormat); + Log.v(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString); // Ensure that the camera resolution is a multiple of 8, as the screen may not be. // TODO: A better solution would be to request the supported preview resolutions