From c5e2b3837655ce92c638c2363330c5a4d1b8176c Mon Sep 17 00:00:00 2001 From: junjiez Date: Thu, 22 Jun 2017 14:41:57 +0800 Subject: SnapdragonCamera:RTB_snapshot 1.pack the bokeh image, origin image, depthmap into jpeg with XMP information. 2.Fix the blur degree is not changed when swipe the seek bar. Change-Id: I05d31ccd2a5d50f4df2fcda2549822eb2ead67ec --- .../snapcam/filter/ClearSightImageProcessor.java | 8 +- src/org/codeaurora/snapcam/filter/GDepth.java | 94 +++++++++------------- 2 files changed, 45 insertions(+), 57 deletions(-) mode change 100644 => 100755 src/org/codeaurora/snapcam/filter/ClearSightImageProcessor.java mode change 100644 => 100755 src/org/codeaurora/snapcam/filter/GDepth.java (limited to 'src/org/codeaurora/snapcam/filter') diff --git a/src/org/codeaurora/snapcam/filter/ClearSightImageProcessor.java b/src/org/codeaurora/snapcam/filter/ClearSightImageProcessor.java old mode 100644 new mode 100755 index b2a81389d..e4ab305b2 --- 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 old mode 100644 new mode 100755 index 8f9a935a9..92c0e07f5 --- 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 -- cgit v1.2.3