diff options
-rwxr-xr-x[-rw-r--r--] | src/com/android/camera/MediaSaveService.java | 52 | ||||
-rwxr-xr-x[-rw-r--r--] | src/com/android/camera/PhotoModule.java | 52 | ||||
-rwxr-xr-x[-rw-r--r--] | src/org/codeaurora/snapcam/filter/ClearSightImageProcessor.java | 8 | ||||
-rwxr-xr-x[-rw-r--r--] | src/org/codeaurora/snapcam/filter/GDepth.java | 94 |
4 files changed, 106 insertions, 100 deletions
diff --git a/src/com/android/camera/MediaSaveService.java b/src/com/android/camera/MediaSaveService.java index 00f5a4777..e3980f752 100644..100755 --- a/src/com/android/camera/MediaSaveService.java +++ b/src/com/android/camera/MediaSaveService.java @@ -161,7 +161,7 @@ public class MediaSaveService extends Service { t.execute(); } - public void addClearsightImage(byte[] clearsight, GImage bayer, GDepth.DepthMap depthMap, + public void addXmpImage(byte[] mainImage, GImage bayer, GDepth gDepth, String title, long date, Location loc, int width, int height, int orientation, ExifInterface exif, OnMediaSavedListener l, ContentResolver resolver, String pictureFormat) { @@ -169,11 +169,11 @@ public class MediaSaveService extends Service { Log.e(TAG, "Cannot add image when the queue is full"); return; } - ClearsightImageSaveTask t = new ClearsightImageSaveTask(clearsight, bayer, depthMap, + XmpImageSaveTask t = new XmpImageSaveTask(mainImage, bayer, gDepth, title, date, (loc == null) ? null : new Location(loc), width, height, orientation, exif, resolver, l, pictureFormat); - mMemoryUse += clearsight.length; + mMemoryUse += mainImage.length; if (isQueueFull()) { onQueueFull(); } @@ -382,11 +382,9 @@ public class MediaSaveService extends Service { } } - private class ClearsightImageSaveTask extends AsyncTask <Void, Void, Uri> { - private byte[] clearsight; - private byte[] depth; + private class XmpImageSaveTask extends AsyncTask <Void, Void, Uri> { + private byte[] mainImage; private GImage bayer; - private GDepth.DepthMap depthMap; private GDepth gDepth; private byte[] data; private String title; @@ -399,14 +397,14 @@ public class MediaSaveService extends Service { private OnMediaSavedListener listener; private String pictureFormat; - public ClearsightImageSaveTask(byte[] clearsight, GImage bayer,GDepth.DepthMap depthMap, - String title, long date, Location loc, - int width, int height, int orientation, - ExifInterface exif, ContentResolver resolver, - OnMediaSavedListener listener, String pictureFormat) { - this.clearsight = clearsight; + public XmpImageSaveTask(byte[] mainImage, GImage bayer, GDepth gDepth, + String title, long date, Location loc, + int width, int height, int orientation, + ExifInterface exif, ContentResolver resolver, + OnMediaSavedListener listener, String pictureFormat) { + this.mainImage = mainImage; + this.gDepth = gDepth; this.bayer = bayer; - this.depthMap = depthMap; this.title = title; this.date = date; this.loc = loc; @@ -417,8 +415,6 @@ public class MediaSaveService extends Service { this.resolver = resolver; this.listener = listener; this.pictureFormat = pictureFormat; - - gDepth = null; } @Override @@ -428,13 +424,9 @@ public class MediaSaveService extends Service { @Override protected Uri doInBackground(Void... v) { - if ( depthMap != null ) { - depthMap.buffer = converToJpegByte(depthMap.rawDepth, depthMap.width, depthMap.height); - gDepth = GDepth.createGDepth(depthMap); - } - data = embedGDepthAndBayerInClearSight(clearsight); + data = embedGDepthAndBayerInClearSight(mainImage); if ( data == null ) { - data = clearsight; + data = mainImage; Log.e(TAG, "embedGDepthAndBayerInClearSight fail"); } @@ -458,22 +450,6 @@ public class MediaSaveService extends Service { if (isQueueFull() != previouslyFull) onQueueAvailable(); } - private byte[] converToJpegByte(byte[] depthBuf, int width, int height) { - int[] colors = new int[depthBuf.length]; - for(int i=0; i < colors.length; ++i) { - colors[i] = (256+depthBuf[i])%256; - } - Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - for( int y=0; y < height; ++y ) { - for( int x=0; x < width; ++x) { - int c = colors[y*width+x]; - bitmap.setPixel(x, y, Color.rgb(c, c, c)); - } - } - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); - return baos.toByteArray(); - } private byte[] embedGDepthAndBayerInClearSight(byte[] clearSightImageBytes) { Log.d(TAG, "embedGDepthInClearSight"); diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index 4c4525b79..a9f9af91e 100644..100755 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -88,6 +88,9 @@ import com.android.camera.util.UsageStatistics; import org.codeaurora.snapcam.R; import org.codeaurora.snapcam.wrapper.ParametersWrapper; import org.codeaurora.snapcam.wrapper.CameraInfoWrapper; +import org.codeaurora.snapcam.filter.GDepth; +import org.codeaurora.snapcam.filter.GImage; + import android.widget.EditText; import android.app.AlertDialog; import android.content.DialogInterface; @@ -269,6 +272,8 @@ public class PhotoModule private byte[] mLastJpegData; private int mLastJpegOrientation = 0; + private boolean mIsBokehMode = false; + private Runnable mDoSnapRunnable = new Runnable() { @Override public void run() { @@ -1346,7 +1351,12 @@ public class PhotoModule private final class JpegPictureCallback implements CameraPictureCallback { + public static final int GDEPTH_SIZE = 1280 * 960; Location mLocation; + byte[] mBokeh; + byte[] mOrigin; + byte[] mDepth; + int mCallTime = 0; public JpegPictureCallback(Location loc) { mLocation = loc; @@ -1354,6 +1364,19 @@ public class PhotoModule @Override public void onPictureTaken(byte [] jpegData, CameraProxy camera) { + mCallTime ++; + if (mIsBokehMode) { + if (jpegData != null && mCallTime == 1) { + mBokeh = jpegData; + } + if (jpegData != null && mCallTime == 2 && mOrigin == null) { + mOrigin = jpegData; + } + if (jpegData != null && mCallTime == 3) { + mDepth = jpegData; + jpegData = mBokeh; + } + } mUI.stopSelfieFlash(); mUI.enableShutter(true); if (mUI.isPreviewCoverVisible()) { @@ -1513,10 +1536,26 @@ public class PhotoModule } String mPictureFormat = mParameters.get(KEY_PICTURE_FORMAT); Log.d(TAG, "capture:" + title + "." + mPictureFormat); - mActivity.getMediaSaveService().addImage( - jpegData, title, date, mLocation, width, height, - orientation, exif, mOnMediaSavedListener, - mContentResolver, mPictureFormat); + if (mIsBokehMode) { + if (jpegData != null && mCallTime == 3) { + if (mOrigin != null && mBokeh != null) { + GImage gImage = new GImage(mOrigin, "image/jpeg"); + GDepth.DepthMap map= new GDepth.DepthMap(1280,960); + map.buffer = mDepth; + map.roi = new Rect(0,0,width,height); + GDepth gDepth = GDepth.createGDepth(map); + mActivity.getMediaSaveService().addXmpImage(mBokeh,gImage, + gDepth,"bokeh_"+title,date,mLocation,width,height, + orientation,exif,mOnMediaSavedListener, + mContentResolver,mPictureFormat); + } + } + } else { + mActivity.getMediaSaveService().addImage( + jpegData, title, date, mLocation, width, height, + orientation, exif, mOnMediaSavedListener, + mContentResolver, mPictureFormat); + } if (mRefocus && mReceivedSnapNum == 7) { mUI.showRefocusToast(mRefocus); } @@ -1605,8 +1644,9 @@ public class PhotoModule public void onProgressChanged(SeekBar bar, int progress, boolean fromtouch) { if (mParameters != null) { mParameters.set(CameraSettings.KEY_QC_BOKEH_BLUR_VALUE, progress); + mCameraDevice.setParameters(mParameters); + Log.d(TAG,"seekbar bokeh degree = "+ progress); } - Log.d(TAG,"seekbar bokeh degree = "+ progress); } public void onStopTrackingTouch(SeekBar bar) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivity); @@ -3765,6 +3805,7 @@ public class PhotoModule if (!bokehMode.equals(mActivity.getString( R.string.pref_camera_bokeh_mode_entry_value_disable))) { + mIsBokehMode = true; if(!zsl.equals("on")) { ParametersWrapper.setZSLMode(mParameters, "on"); } @@ -3798,6 +3839,7 @@ public class PhotoModule } }); } else { + mIsBokehMode = false; bokehBlurDegree = "0"; mActivity.runOnUiThread(new Runnable() { @Override diff --git a/src/org/codeaurora/snapcam/filter/ClearSightImageProcessor.java b/src/org/codeaurora/snapcam/filter/ClearSightImageProcessor.java index b2a81389d..e4ab305b2 100644..100755 --- a/src/org/codeaurora/snapcam/filter/ClearSightImageProcessor.java +++ b/src/org/codeaurora/snapcam/filter/ClearSightImageProcessor.java @@ -1280,9 +1280,11 @@ public class ClearSightImageProcessor { if(mCallback != null) mCallback.onClearSightFailure(null); } - mMediaSaveService.addClearsightImage( + GDepth gDepth = GDepth.createGDepth(mDepthMap); + + mMediaSaveService.addXmpImage( clearSightBytes != null ? clearSightBytes : bayerBytes, - mGImage, mDepthMap,title, date, null, + mGImage, gDepth,title, date, null, width, height, orientation, exif, mMediaSavedListener, mMediaSaveService.getContentResolver(), "jpeg"); @@ -1414,7 +1416,7 @@ public class ClearSightImageProcessor { } depthMap = new GDepth.DepthMap(width, height); depthMap.roi = roiRect; - depthMap.rawDepth = depthBuffer; + depthMap.buffer = depthBuffer; }else{ Log.e(TAG, "dualCameraGenerateDDM failure"); } diff --git a/src/org/codeaurora/snapcam/filter/GDepth.java b/src/org/codeaurora/snapcam/filter/GDepth.java index 8f9a935a9..92c0e07f5 100644..100755 --- a/src/org/codeaurora/snapcam/filter/GDepth.java +++ b/src/org/codeaurora/snapcam/filter/GDepth.java @@ -30,6 +30,7 @@ package org.codeaurora.snapcam.filter; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Color; import android.graphics.Rect; import android.hardware.Camera.Size; import android.util.Base64; @@ -49,6 +50,8 @@ import com.adobe.xmp.XMPException; import com.adobe.xmp.XMPMeta; import com.adobe.xmp.XMPMetaFactory; +import static android.graphics.Color.rgb; + public class GDepth{ private final static String TAG = "Flow_GDepth"; public final static String NAMESPACE_URL = "http://ns.google.com/photos/1.0/depthmap/"; @@ -66,13 +69,13 @@ public class GDepth{ public final static String FORMAT_RANGE_INVERSE="RangeInverse"; public final static String FORMAT_RANGLE_LINEAR = "RangeLinear"; + public final static String FORMAT_8_BIT = "8-bit"; + private final static String MIME = "image/jpeg"; private DepthMap mDepthMap; private String mData; - private int mNear; - private int mFar; - private final String mFormat = "RangeLinear"; + private final String mFormat = FORMAT_8_BIT; private int[] mMap; static { @@ -86,29 +89,17 @@ public class GDepth{ private GDepth(DepthMap depthMap){ mDepthMap = depthMap; - mMap = new int[depthMap.buffer.length]; + if (depthMap != null && depthMap.buffer != null) { + mMap = new int[depthMap.buffer.length]; - for( int i=0; i < mMap.length; ++i ) { - mMap[i] = (256+depthMap.buffer[i])%256; - } - mNear = mFar = mMap[0]; - for(int d : mMap ) { - if ( d < mNear) { - mNear = d; - }else if ( d > mFar) { - mFar = d; + for( int i=0; i < mMap.length; ++i ) { + int gray = depthMap.buffer[i] & 0xff; + int color = Color.rgb(gray,gray,gray); + mMap[i] = color; } } } - public int getNear() { - return mNear; - } - - public int getFar(){ - return mFar; - } - public String getFormat(){ return mFormat; } @@ -117,6 +108,14 @@ public class GDepth{ return MIME; } + public int getNear() { + return 0; + } + + public int getFar() { + return 255; + } + public String getData(){ return mData; } @@ -126,17 +125,20 @@ public class GDepth{ } public static GDepth createGDepth(DepthMap depthMap){ GDepth gDepth = new GDepth(depthMap); - if ( gDepth.encoding() ) { + if ( gDepth.encoding() ) { return gDepth; } return null; } - private boolean encoding(){ + private boolean encoding(){ Log.d(TAG, "encoding"); boolean result = false; - int[] grayscaleImage = convertIntoImage(mMap); - byte[] jpegBytes = compressToJPEG(grayscaleImage ); + Bitmap bitmap = Bitmap.createBitmap( + mMap,mDepthMap.width, mDepthMap.height, Bitmap.Config.ARGB_8888); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); + byte[] jpegBytes = outputStream.toByteArray(); if (jpegBytes != null ) { String base64String = serializeAsBase64Str(jpegBytes); result = true; @@ -148,34 +150,21 @@ public class GDepth{ return result; } - private int[] convertIntoImage(int[] depthMap) { - int[] imageBuffer = new int[depthMap.length]; - float dividend = mFar-mNear; - for ( int i =0; i < imageBuffer.length; ++i) { - if ( depthMap[i] == 0 && mNear == 0 ) { - imageBuffer[i] = 0; - }else{ - imageBuffer[i] = getRangeLinearDepth(depthMap[i], mNear, dividend); - } - } - return imageBuffer; + public Bitmap getGdepthBitmap() { + Bitmap bitmap = Bitmap.createBitmap( + mMap,mDepthMap.width, mDepthMap.height, Bitmap.Config.ARGB_8888); + return bitmap; } - private int getRangeLinearDepth(int depth, int near, float dividend) { - return (int)(255*(depth-near)/dividend); - } - - private int getRangeLinearDepth(int depth, int near, int far) { - return (int)(255*(depth-near)/(float)(far-near)); - } - - private byte[] compressToJPEG(int[] image) { - Log.d(TAG, "compressToJPEG int[].size=" + image.length); - byte[] bitsBuffer = new byte[image.length]; - for(int i=0; i < image.length; ++i){ - bitsBuffer[i] = (byte)image[i]; + public Bitmap getBitGdepthBitmap() { + int[] data = new int[mMap.length]; + for (int i = 0; i < data.length; ++i) { + int p = mMap[i]; + data[i] = (p & 0xff) << 24; } - return compressToJPEG(bitsBuffer); + Bitmap bitmap = Bitmap.createBitmap( + data,mDepthMap.width, mDepthMap.height, Bitmap.Config.ALPHA_8); + return bitmap; } private byte[] compressToJPEG(byte[] image) { @@ -242,7 +231,6 @@ public class GDepth{ public int width; public int height; public Rect roi; - public byte[] rawDepth; public DepthMap(int width, int height){ this.width = width; this.height = height; @@ -251,8 +239,7 @@ public class GDepth{ private GDepth(int near, int far, String data) { - this.mNear = near; - this.mFar = far; + this.mData = data; } public static GDepth createGDepth(XMPMeta xmpMeta){ @@ -302,6 +289,5 @@ public class GDepth{ //conver to depth value return false; - } }
\ No newline at end of file |