diff options
Diffstat (limited to 'src/org/codeaurora/snapcam/filter')
-rwxr-xr-x[-rw-r--r--] | src/org/codeaurora/snapcam/filter/ClearSightImageProcessor.java | 13 | ||||
-rw-r--r-- | src/org/codeaurora/snapcam/filter/ClearSightNativeEngine.java | 27 | ||||
-rwxr-xr-x[-rw-r--r--] | src/org/codeaurora/snapcam/filter/GDepth.java | 94 |
3 files changed, 71 insertions, 63 deletions
diff --git a/src/org/codeaurora/snapcam/filter/ClearSightImageProcessor.java b/src/org/codeaurora/snapcam/filter/ClearSightImageProcessor.java index feb6693f2..a5521bed2 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"); } @@ -1543,11 +1545,14 @@ public class ClearSightImageProcessor { ByteBuffer vuBuffer = planes[2].getBuffer(); int sizeY = yBuffer.capacity(); int sizeVU = vuBuffer.capacity(); - byte[] data = new byte[sizeY + sizeVU]; + int stride = image.getPlanes()[0].getRowStride(); + int height = image.getHeight(); + byte[] data = new byte[stride * height*3/2]; yBuffer.rewind(); yBuffer.get(data, 0, sizeY); vuBuffer.rewind(); vuBuffer.get(data, sizeY, sizeVU); + int[] strides = new int[] { planes[0].getRowStride(), planes[2].getRowStride() }; diff --git a/src/org/codeaurora/snapcam/filter/ClearSightNativeEngine.java b/src/org/codeaurora/snapcam/filter/ClearSightNativeEngine.java index 8b30ca032..5ba0fd951 100644 --- a/src/org/codeaurora/snapcam/filter/ClearSightNativeEngine.java +++ b/src/org/codeaurora/snapcam/filter/ClearSightNativeEngine.java @@ -41,8 +41,12 @@ import android.media.Image; import android.media.Image.Plane; import android.util.Log; +import com.android.camera.util.PersistUtil; + public class ClearSightNativeEngine { - private static final boolean DEBUG = false; + private static final boolean DEBUG = + (PersistUtil.getCamera2Debug() == PersistUtil.CAMERA2_DEBUG_DUMP_LOG) || + (PersistUtil.getCamera2Debug() == PersistUtil.CAMERA2_DEBUG_DUMP_ALL); private static final String TAG = "ClearSightNativeEngine"; static { try { @@ -75,8 +79,14 @@ public class ClearSightNativeEngine { private ArrayList<SourceImage> mCache = new ArrayList<SourceImage>(); private ArrayList<SourceImage> mSrcColor = new ArrayList<SourceImage>(); private ArrayList<SourceImage> mSrcMono = new ArrayList<SourceImage>(); + private final float mBrIntensity; + private final float mSmoothingIntensity; + private final boolean mIsVerticallyAlignedSensor; private ClearSightNativeEngine() { + mBrIntensity = PersistUtil.getDualCameraBrIntensity(); + mSmoothingIntensity = PersistUtil.getDualCameraSmoothingIntensity(); + mIsVerticallyAlignedSensor = PersistUtil.getDualCameraSensorAlign(); } public static void createInstance() { @@ -296,10 +306,16 @@ public class ClearSightNativeEngine { exposure /= 100000; Log.d(TAG, "processImage - iso: " + iso + " exposure ms: " + exposure); - return nativeClearSightProcessInit(numImages, + if (DEBUG) { + Log.d(TAG,"processImage - mBrIntensity :" + mBrIntensity + + ", mSmoothingIntensity :" + mSmoothingIntensity + + ", mIsVerticallyAlignedSensor :" + mIsVerticallyAlignedSensor); + } + return nativeClearSightProcessInit2(numImages, srcColorY, srcColorVU, metadataColor, mImageWidth, mImageHeight, mYStride, mVUStride, srcMonoY, metadataMono, mImageWidth, mImageHeight, - mYStride, mOtpCalibData, (int)exposure, iso); + mYStride, mOtpCalibData, (int)exposure, iso, + mBrIntensity, mSmoothingIntensity, mIsVerticallyAlignedSensor); } public boolean processImage(ClearsightImage csImage) { @@ -326,12 +342,13 @@ public class ClearSightNativeEngine { int strideY, int strideVU, ByteBuffer dstY, ByteBuffer dstVU, float[] metadata); - private native final boolean nativeClearSightProcessInit(int numImagePairs, + private native final boolean nativeClearSightProcessInit2(int numImagePairs, ByteBuffer[] srcColorY, ByteBuffer[] srcColorVU, float[][] metadataColor, int srcColorWidth, int srcColorHeight, int srcColorStrideY, int srcColorStrideVU, ByteBuffer[] srcMonoY, float[][] metadataMono, int srcMonoWidth, int srcMonoHeight, - int srcMonoStrideY, byte[] otp, int exposureMs, int iso); + int srcMonoStrideY, byte[] otp, int exposureMs, int iso, + float brIntensity, float smoothingIntensity, boolean isVerticallyAlignedSensor); private native final boolean nativeClearSightProcess(ByteBuffer dstY, ByteBuffer dstVU, int dstStrideY, int dstStrideVU, int[] roiRect); 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 |