- private void setPreviewMode(boolean on) {
- if (on != previewMode) {
- if (on) {
- params.type = 1; // preview
- params.srcWidth = previewResolution.x;
- params.srcHeight = previewResolution.y;
- params.leftPixel = (cameraResolution.x - params.srcWidth) / 2;
- params.topPixel = (cameraResolution.y - params.srcHeight) / 2;
- params.outputWidth = screenResolution.x;
- params.outputHeight = screenResolution.y;
- params.dataFormat = 2; // RGB565
- } else {
- params.type = 0; // still
- params.srcWidth = stillResolution.x * stillMultiplier;
- params.srcHeight = stillResolution.y * stillMultiplier;
- params.leftPixel = (cameraResolution.x - params.srcWidth) / 2;
- params.topPixel = (cameraResolution.y - params.srcHeight) / 2;
- params.outputWidth = stillResolution.x;
- params.outputHeight = stillResolution.y;
- params.dataFormat = 2; // RGB565
- }
- String captureType = on ? "preview" : "still";
- Log.v(TAG, "Setting params for " + captureType + ": srcWidth " + params.srcWidth +
- " srcHeight " + params.srcHeight + " leftPixel " + params.leftPixel + " topPixel " +
- params.topPixel + " outputWidth " + params.outputWidth + " outputHeight " +
- params.outputHeight);
- // TODO switch back to CameraDevice later
- // camera.setCaptureParams(params);
- // end TODO
- previewMode = on;
+ 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:
+ // 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());
+ }