Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
[#4] Android UI doesn't support Portrait and is small - portrait scan…
Browse files Browse the repository at this point in the history
…ning of non-QR codes didn't work
  • Loading branch information
EddyVerbruggen authored and trongrg committed May 13, 2015
1 parent f74da67 commit e197d22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,6 @@ public int compare(Camera.Size a, Camera.Size b) {

WindowManager manager = (WindowManager) this.context.getSystemService(Context.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();
// don't vertically stretch the camera view on portrait mode
if (rotation == Surface.ROTATION_0) {
if (bestSize.y <= bestSize.x) {
bestSize.y = (int) ((float)bestSize.y / screenAspectRatio * ((float)bestSize.x / (float) bestSize.y));
}
}

Log.i(TAG, "Found best approximate preview size: " + bestSize);
return bestSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,31 @@ public synchronized void setManualFramingRect(int width, int height) {
}
}

/**
* A factory method to build the appropriate LuminanceSource object based on the format
* of the preview buffers, as described by Camera.Parameters.
*
* @param data A preview frame.
* @param width The width of the image.
* @param height The height of the image.
* @return A PlanarYUVLuminanceSource instance.
*/
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
// Hack of orientation
Display display = windowManager.getDefaultDisplay();
int rotation = display.getRotation();

byte[] rotatedData = new byte[data.length];
if (rotation == Surface.ROTATION_0) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
rotatedData[x * height + height - y - 1] = data[x + y * width];
}
}
int tmp = width;
width = height;
height = tmp;
} else {
rotatedData = null;
}

Rect rect = getFramingRectInPreview();
if (rect == null) {
return null;
}
// Go ahead and assume it's YUV rather than die.
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
return new PlanarYUVLuminanceSource(rotation == Surface.ROTATION_0 ? rotatedData : data, width, height, rect.left, rect.top,
rect.width(), rect.height(), false);
}
}

0 comments on commit e197d22

Please sign in to comment.