mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
Apparent fix for issue 383 / Moment + Android 2.1 issue
git-svn-id: https://zxing.googlecode.com/svn/trunk@1309 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
88649bb0d4
commit
484fc75f44
|
@ -52,8 +52,12 @@ final class CameraConfigurationManager {
|
||||||
previewFormat = parameters.getPreviewFormat();
|
previewFormat = parameters.getPreviewFormat();
|
||||||
previewFormatString = parameters.get("preview-format");
|
previewFormatString = parameters.get("preview-format");
|
||||||
Log.v(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
|
Log.v(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
|
||||||
screenResolution = getScreenResolution();
|
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||||
cameraResolution = getCameraResolution(parameters);
|
Display display = manager.getDefaultDisplay();
|
||||||
|
screenResolution = new Point(display.getWidth(), display.getHeight());
|
||||||
|
Log.v(TAG, "Screen resolution: " + screenResolution);
|
||||||
|
cameraResolution = getCameraResolution(parameters, screenResolution);
|
||||||
|
Log.v(TAG, "Camera resolution: " + screenResolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +68,7 @@ final class CameraConfigurationManager {
|
||||||
*/
|
*/
|
||||||
void setDesiredCameraParameters(Camera camera) {
|
void setDesiredCameraParameters(Camera camera) {
|
||||||
Camera.Parameters parameters = camera.getParameters();
|
Camera.Parameters parameters = camera.getParameters();
|
||||||
Log.v(TAG, "Setting preview size: " + cameraResolution.x + ", " + cameraResolution.y);
|
Log.v(TAG, "Setting preview size: " + cameraResolution);
|
||||||
parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
|
parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
|
||||||
setFlash(parameters);
|
setFlash(parameters);
|
||||||
setZoom(parameters);
|
setZoom(parameters);
|
||||||
|
@ -76,6 +80,10 @@ final class CameraConfigurationManager {
|
||||||
return cameraResolution;
|
return cameraResolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Point getScreenResolution() {
|
||||||
|
return screenResolution;
|
||||||
|
}
|
||||||
|
|
||||||
int getPreviewFormat() {
|
int getPreviewFormat() {
|
||||||
return previewFormat;
|
return previewFormat;
|
||||||
}
|
}
|
||||||
|
@ -84,13 +92,7 @@ final class CameraConfigurationManager {
|
||||||
return previewFormatString;
|
return previewFormatString;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point getScreenResolution() {
|
private static Point getCameraResolution(Camera.Parameters parameters, Point screenResolution) {
|
||||||
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
|
||||||
Display display = manager.getDefaultDisplay();
|
|
||||||
return new Point(display.getWidth(), display.getHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Point getCameraResolution(Camera.Parameters parameters) {
|
|
||||||
|
|
||||||
String previewSizeValueString = parameters.get("preview-size-values");
|
String previewSizeValueString = parameters.get("preview-size-values");
|
||||||
// saw this on Xperia
|
// saw this on Xperia
|
||||||
|
@ -101,7 +103,7 @@ final class CameraConfigurationManager {
|
||||||
Point cameraResolution = null;
|
Point cameraResolution = null;
|
||||||
|
|
||||||
if (previewSizeValueString != null) {
|
if (previewSizeValueString != null) {
|
||||||
Log.v(TAG, "preview-size parameter: " + previewSizeValueString);
|
Log.v(TAG, "preview-size-values parameter: " + previewSizeValueString);
|
||||||
cameraResolution = findBestPreviewSizeValue(previewSizeValueString, screenResolution);
|
cameraResolution = findBestPreviewSizeValue(previewSizeValueString, screenResolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +159,7 @@ final class CameraConfigurationManager {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int findBestMotZoomValue(String stringValues, int tenDesiredZoom) {
|
private static int findBestMotZoomValue(CharSequence stringValues, int tenDesiredZoom) {
|
||||||
int tenBestValue = 0;
|
int tenBestValue = 0;
|
||||||
for (String stringValue : COMMA_PATTERN.split(stringValues)) {
|
for (String stringValue : COMMA_PATTERN.split(stringValues)) {
|
||||||
stringValue = stringValue.trim();
|
stringValue = stringValue.trim();
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package com.google.zxing.client.android.camera;
|
package com.google.zxing.client.android.camera;
|
||||||
|
|
||||||
import com.google.zxing.ResultPoint;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
|
@ -56,6 +54,7 @@ public final class CameraManager {
|
||||||
private final CameraConfigurationManager configManager;
|
private final CameraConfigurationManager configManager;
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
private Rect framingRect;
|
private Rect framingRect;
|
||||||
|
private Rect framingRectInPreview;
|
||||||
private boolean initialized;
|
private boolean initialized;
|
||||||
private boolean previewing;
|
private boolean previewing;
|
||||||
private final boolean useOneShotPreviewCallback;
|
private final boolean useOneShotPreviewCallback;
|
||||||
|
@ -205,31 +204,49 @@ public final class CameraManager {
|
||||||
* @return The rectangle to draw on screen in window coordinates.
|
* @return The rectangle to draw on screen in window coordinates.
|
||||||
*/
|
*/
|
||||||
public Rect getFramingRect() {
|
public Rect getFramingRect() {
|
||||||
Point cameraResolution = configManager.getCameraResolution();
|
Point screenResolution = configManager.getScreenResolution();
|
||||||
if (framingRect == null) {
|
if (framingRect == null) {
|
||||||
if (camera == null) {
|
if (camera == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int width = cameraResolution.x * 3 / 4;
|
int width = screenResolution.x * 3 / 4;
|
||||||
if (width < MIN_FRAME_WIDTH) {
|
if (width < MIN_FRAME_WIDTH) {
|
||||||
width = MIN_FRAME_WIDTH;
|
width = MIN_FRAME_WIDTH;
|
||||||
} else if (width > MAX_FRAME_WIDTH) {
|
} else if (width > MAX_FRAME_WIDTH) {
|
||||||
width = MAX_FRAME_WIDTH;
|
width = MAX_FRAME_WIDTH;
|
||||||
}
|
}
|
||||||
int height = cameraResolution.y * 3 / 4;
|
int height = screenResolution.y * 3 / 4;
|
||||||
if (height < MIN_FRAME_HEIGHT) {
|
if (height < MIN_FRAME_HEIGHT) {
|
||||||
height = MIN_FRAME_HEIGHT;
|
height = MIN_FRAME_HEIGHT;
|
||||||
} else if (height > MAX_FRAME_HEIGHT) {
|
} else if (height > MAX_FRAME_HEIGHT) {
|
||||||
height = MAX_FRAME_HEIGHT;
|
height = MAX_FRAME_HEIGHT;
|
||||||
}
|
}
|
||||||
int leftOffset = (cameraResolution.x - width) / 2;
|
int leftOffset = (screenResolution.x - width) / 2;
|
||||||
int topOffset = (cameraResolution.y - height) / 2;
|
int topOffset = (screenResolution.y - height) / 2;
|
||||||
framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
|
framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
|
||||||
Log.v(TAG, "Calculated framing rect: " + framingRect);
|
Log.v(TAG, "Calculated framing rect: " + framingRect);
|
||||||
}
|
}
|
||||||
return framingRect;
|
return framingRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like {@link #getFramingRect} but coordinates are in terms of the preview frame,
|
||||||
|
* not UI / screen.
|
||||||
|
*/
|
||||||
|
public Rect getFramingRectInPreview() {
|
||||||
|
if (framingRectInPreview == null) {
|
||||||
|
Rect rect = new Rect(getFramingRect());
|
||||||
|
Point cameraResolution = configManager.getCameraResolution();
|
||||||
|
Point screenResolution = configManager.getScreenResolution();
|
||||||
|
rect.left = rect.left * cameraResolution.x / screenResolution.x;
|
||||||
|
rect.right = rect.right * cameraResolution.x / screenResolution.x;
|
||||||
|
rect.top = rect.top * cameraResolution.y / screenResolution.y;
|
||||||
|
rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;
|
||||||
|
framingRectInPreview = rect;
|
||||||
|
}
|
||||||
|
return framingRectInPreview;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the result points from still resolution coordinates to screen coordinates.
|
* Converts the result points from still resolution coordinates to screen coordinates.
|
||||||
*
|
*
|
||||||
|
@ -237,8 +254,9 @@ public final class CameraManager {
|
||||||
* @return An array of Points scaled to the size of the framing rect and offset appropriately
|
* @return An array of Points scaled to the size of the framing rect and offset appropriately
|
||||||
* so they can be drawn in screen coordinates.
|
* so they can be drawn in screen coordinates.
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
public Point[] convertResultPoints(ResultPoint[] points) {
|
public Point[] convertResultPoints(ResultPoint[] points) {
|
||||||
Rect frame = getFramingRect();
|
Rect frame = getFramingRectInPreview();
|
||||||
int count = points.length;
|
int count = points.length;
|
||||||
Point[] output = new Point[count];
|
Point[] output = new Point[count];
|
||||||
for (int x = 0; x < count; x++) {
|
for (int x = 0; x < count; x++) {
|
||||||
|
@ -248,6 +266,7 @@ public final class CameraManager {
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A factory method to build the appropriate LuminanceSource object based on the format
|
* A factory method to build the appropriate LuminanceSource object based on the format
|
||||||
|
@ -259,7 +278,7 @@ public final class CameraManager {
|
||||||
* @return A PlanarYUVLuminanceSource instance.
|
* @return A PlanarYUVLuminanceSource instance.
|
||||||
*/
|
*/
|
||||||
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
|
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
|
||||||
Rect rect = getFramingRect();
|
Rect rect = getFramingRectInPreview();
|
||||||
int previewFormat = configManager.getPreviewFormat();
|
int previewFormat = configManager.getPreviewFormat();
|
||||||
String previewFormatString = configManager.getPreviewFormatString();
|
String previewFormatString = configManager.getPreviewFormatString();
|
||||||
switch (previewFormat) {
|
switch (previewFormat) {
|
||||||
|
|
Loading…
Reference in a new issue