summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-09-22 23:29:17 -0400
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-09-22 23:29:17 -0400
commite15c0ad52981ba7413002b028784e09da772ec35 (patch)
tree4a5bebaf3b9e5e4fd7a696dec00961199981179c
parentf0b7d4b0d1823ea547e4976544866fa35f577898 (diff)
parentcd972b0cd67d7a45084d9757ebd49b8f22989edd (diff)
downloadLegacyCamera-e15c0ad52981ba7413002b028784e09da772ec35.tar.gz
Merge change 26484 into eclair
* changes: Fix 2129498: add a MaxNumOfPixels parameter for client to specify the captured picture size.
-rw-r--r--src/com/android/camera/Camera.java88
-rw-r--r--src/com/android/camera/ImageManager.java61
-rw-r--r--src/com/android/camera/Util.java29
3 files changed, 120 insertions, 58 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index b26f449d..068ff860 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -150,6 +150,12 @@ public class Camera extends Activity implements View.OnClickListener,
private ImageView mLastPictureButton;
private ThumbnailController mThumbController;
+ // mCropValue, mSaveUri, mMaxNumOfPixels are used only if
+ // isImageCaptureIntent() is true.
+ private String mCropValue;
+ private Uri mSaveUri;
+ private int mMaxNumOfPixels;
+
private int mViewFinderWidth, mViewFinderHeight;
private ImageCapture mImageCapture = null;
@@ -722,10 +728,16 @@ public class Camera extends Activity implements View.OnClickListener,
mImageCapture.getLastCaptureUri());
mThumbController.updateDisplayIfNeeded();
} else {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inSampleSize = 4;
- mCaptureOnlyBitmap = BitmapFactory.decodeByteArray(
- data, 0, data.length, options);
+ mCaptureOnlyBitmap = Util.makeBitmap(data, mMaxNumOfPixels);
+
+ // This is really stupid...
+ String filepath = ImageManager.getTempJpegPath();
+ int degree = 0;
+ if (saveDataToFile(filepath, data)) {
+ degree = ImageManager.getExifOrientation(filepath);
+ new File(filepath).delete();
+ }
+ mCaptureOnlyBitmap = Util.rotate(mCaptureOnlyBitmap, degree);
showPostCaptureAlert();
}
}
@@ -831,6 +843,19 @@ public class Camera extends Activity implements View.OnClickListener,
}
}
+ public boolean saveDataToFile(String filePath, byte[] data) {
+ FileOutputStream f = null;
+ try {
+ f = new FileOutputStream(filePath);
+ f.write(data);
+ } catch (IOException e) {
+ return false;
+ } finally {
+ MenuHelper.closeSilently(f);
+ }
+ return true;
+ }
+
private void setLastPictureThumb(byte[] data, int degree, Uri uri) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 16;
@@ -886,6 +911,10 @@ public class Camera extends Activity implements View.OnClickListener,
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mIsImageCaptureIntent = isImageCaptureIntent();
+ if (mIsImageCaptureIntent) {
+ setupCaptureParams();
+ }
+
LayoutInflater inflater = getLayoutInflater();
ViewGroup rootView = (ViewGroup) findViewById(R.id.camera);
@@ -988,25 +1017,15 @@ public class Camera extends Activity implements View.OnClickListener,
}
Bitmap bitmap = mImageCapture.getLastBitmap();
- String cropValue = null;
- Uri saveUri = null;
-
- Bundle myExtras = getIntent().getExtras();
- if (myExtras != null) {
- saveUri = (Uri) myExtras.getParcelable(MediaStore.EXTRA_OUTPUT);
- cropValue = myExtras.getString("crop");
- }
-
-
- if (cropValue == null) {
+ if (mCropValue == null) {
// First handle the no crop case -- just return the value. If the
// caller specifies a "save uri" then write the data to it's
// stream. Otherwise, pass back a scaled down version of the bitmap
// directly in the extras.
- if (saveUri != null) {
+ if (mSaveUri != null) {
OutputStream outputStream = null;
try {
- outputStream = mContentResolver.openOutputStream(saveUri);
+ outputStream = mContentResolver.openOutputStream(mSaveUri);
bitmap.compress(Bitmap.CompressFormat.JPEG, 75,
outputStream);
outputStream.close();
@@ -1025,15 +1044,6 @@ public class Camera extends Activity implements View.OnClickListener,
}
}
} else {
- float scale = .5F;
- Matrix m = new Matrix();
- m.setScale(scale, scale);
-
- bitmap = Bitmap.createBitmap(bitmap, 0, 0,
- bitmap.getWidth(),
- bitmap.getHeight(),
- m, true);
-
setResult(RESULT_OK,
new Intent("inline-data").putExtra("data", bitmap));
finish();
@@ -1068,11 +1078,11 @@ public class Camera extends Activity implements View.OnClickListener,
}
Bundle newExtras = new Bundle();
- if (cropValue.equals("circle")) {
+ if (mCropValue.equals("circle")) {
newExtras.putString("circleCrop", "true");
}
- if (saveUri != null) {
- newExtras.putParcelable(MediaStore.EXTRA_OUTPUT, saveUri);
+ if (mSaveUri != null) {
+ newExtras.putParcelable(MediaStore.EXTRA_OUTPUT, mSaveUri);
} else {
newExtras.putBoolean("return-data", true);
}
@@ -1775,6 +1785,26 @@ public class Camera extends Activity implements View.OnClickListener,
return (MediaStore.ACTION_IMAGE_CAPTURE.equals(action));
}
+ private void setupCaptureParams() {
+ Bundle myExtras = getIntent().getExtras();
+ if (myExtras != null) {
+ mSaveUri = (Uri) myExtras.getParcelable(MediaStore.EXTRA_OUTPUT);
+ mCropValue = myExtras.getString("crop");
+ mMaxNumOfPixels = myExtras.getInt("MaxNumOfPixels");
+ }
+
+ // If the caller specified a Uri, we can save a larger bitmap through
+ // the content provider. Otherwise return the bitmap in the intent and
+ // have to use a smaller bitmap.
+ if (mSaveUri == null) {
+ mMaxNumOfPixels = 50 * 1024;
+ } else if (mMaxNumOfPixels == 0) {
+ // mMaxNumOfPixels == 0 if we cannot get the extra bundle above or
+ // it does not contain the parameter.
+ mMaxNumOfPixels = 200 * 1024;
+ }
+ }
+
private void showPostCaptureAlert() {
if (mIsImageCaptureIntent) {
findViewById(R.id.shutter_button).setVisibility(View.INVISIBLE);
diff --git a/src/com/android/camera/ImageManager.java b/src/com/android/camera/ImageManager.java
index ae1311b4..529c5bcb 100644
--- a/src/com/android/camera/ImageManager.java
+++ b/src/com/android/camera/ImageManager.java
@@ -285,31 +285,7 @@ public class ImageManager {
values.put(ImageColumns.MINI_THUMB_MAGIC, 0);
int degree = 0;
if (jpegData != null) {
- ExifInterface exif = null;
- try {
- exif = new ExifInterface(filepath);
- } catch (IOException ex) {
- Log.e(TAG, "cannot read exif", ex);
- }
- if (exif != null) {
- int orientation = exif.getAttributeInt(
- ExifInterface.TAG_ORIENTATION, -1);
- if (orientation != -1) {
- // We only recognize a subset of orientation tag values.
- switch(orientation) {
- case ExifInterface.ORIENTATION_ROTATE_90:
- degree = 90;
- break;
- case ExifInterface.ORIENTATION_ROTATE_180:
- degree = 180;
- break;
- case ExifInterface.ORIENTATION_ROTATE_270:
- degree = 270;
- break;
- }
-
- }
- }
+ degree = getExifOrientation(filepath);
}
values.put(Images.Media.ORIENTATION, degree);
cr.update(uri, values, null, null);
@@ -326,6 +302,36 @@ public class ImageManager {
}
}
+ public static int getExifOrientation(String filepath) {
+ int degree = 0;
+ ExifInterface exif = null;
+ try {
+ exif = new ExifInterface(filepath);
+ } catch (IOException ex) {
+ Log.e(TAG, "cannot read exif", ex);
+ }
+ if (exif != null) {
+ int orientation = exif.getAttributeInt(
+ ExifInterface.TAG_ORIENTATION, -1);
+ if (orientation != -1) {
+ // We only recognize a subset of orientation tag values.
+ switch(orientation) {
+ case ExifInterface.ORIENTATION_ROTATE_90:
+ degree = 90;
+ break;
+ case ExifInterface.ORIENTATION_ROTATE_180:
+ degree = 180;
+ break;
+ case ExifInterface.ORIENTATION_ROTATE_270:
+ degree = 270;
+ break;
+ }
+
+ }
+ }
+ return degree;
+ }
+
// This is the factory function to create an image list.
public static IImageList makeImageList(ContentResolver cr,
ImageListParam param) {
@@ -588,4 +594,9 @@ public class ImageManager {
return Environment.getExternalStorageDirectory().toString() +
"/DCIM/.thumbnails/video_last_thumb";
}
+
+ public static String getTempJpegPath() {
+ return Environment.getExternalStorageDirectory().toString() +
+ "/DCIM/.tempjpeg";
+ }
}
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index 659a99ea..a417e329 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -386,14 +386,12 @@ public class Util {
public static Bitmap makeBitmap(int minSideLength, int maxNumOfPixels,
Uri uri, ContentResolver cr, ParcelFileDescriptor pfd,
BitmapFactory.Options options) {
- Bitmap b = null;
try {
if (pfd == null) pfd = makeInputStream(uri, cr);
if (pfd == null) return null;
if (options == null) options = new BitmapFactory.Options();
FileDescriptor fd = pfd.getFileDescriptor();
- options.inSampleSize = 1;
options.inJustDecodeBounds = true;
BitmapManager.instance().decodeFileDescriptor(fd, options);
if (options.mCancel || options.outWidth == -1
@@ -406,14 +404,37 @@ public class Util {
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- b = BitmapManager.instance().decodeFileDescriptor(fd, options);
+ return BitmapManager.instance().decodeFileDescriptor(fd, options);
} catch (OutOfMemoryError ex) {
Log.e(TAG, "Got oom exception ", ex);
return null;
} finally {
closeSilently(pfd);
}
- return b;
+ }
+
+ public static Bitmap makeBitmap(byte[] jpegData, int maxNumOfPixels) {
+ try {
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length,
+ options);
+ if (options.mCancel || options.outWidth == -1
+ || options.outHeight == -1) {
+ return null;
+ }
+ options.inSampleSize = computeSampleSize(
+ options, IImage.UNCONSTRAINED, maxNumOfPixels);
+ options.inJustDecodeBounds = false;
+
+ options.inDither = false;
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ return BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length,
+ options);
+ } catch (OutOfMemoryError ex) {
+ Log.e(TAG, "Got oom exception ", ex);
+ return null;
+ }
}
private static ParcelFileDescriptor makeInputStream(