From 6ca2ccc20d75ac92e2423c71e03d04a579838050 Mon Sep 17 00:00:00 2001 From: junjiez Date: Mon, 28 Nov 2016 14:09:34 +0800 Subject: SnapdragonCamera:Fix preview is flipped on 8996 Modidfy render script to implement flip another way not 90 according to the camera mounting position. Change-Id: Id6b305fd2b00bc4193f1ba73d4253794e04ee3a6 CRs-Fixed: 1087483 --- rs/rotator.rs | 20 +++++++++++++++----- .../camera/imageprocessor/FrameProcessor.java | 9 ++++++--- 2 files changed, 21 insertions(+), 8 deletions(-) mode change 100644 => 100755 rs/rotator.rs mode change 100644 => 100755 src/com/android/camera/imageprocessor/FrameProcessor.java diff --git a/rs/rotator.rs b/rs/rotator.rs old mode 100644 new mode 100755 index 5a27e00f7..2c57951d6 --- a/rs/rotator.rs +++ b/rs/rotator.rs @@ -35,32 +35,42 @@ rs_allocation gIn; uint32_t width; uint32_t height; uint32_t pad; -bool gFlip; +uint32_t degree; uchar __attribute__((kernel)) rotate90andMerge(uint32_t x, uint32_t y) { uchar yValue = rsGetElementAt_uchar(gIn, x + y*width); - if(gFlip) { + if(degree == 180) { if(x >= width - pad) return (uchar)0; rsSetElementAt_uchar(gOut, yValue, (width-1-x-pad)*height + height - 1 - y); - } else { + } else if (degree == 90) { rsSetElementAt_uchar(gOut, yValue, x*height + height - 1 - y); + } else if (degree == 270) { + if(x >= width - pad) + return (uchar)0; + rsSetElementAt_uchar(gOut, yValue, (width-1-x-pad)*height + y); } + if(x%2 == 0 && y%2 == 0) { uint32_t ySize = width*height; uint32_t index = ySize + x + ((y/2) * width); uchar vValue = rsGetElementAt_uchar(gIn, index); uchar uValue = rsGetElementAt_uchar(gIn, index + 1); - if(gFlip) { + if(degree == 180) { if(x >= width - pad) return (uchar)0; rsSetElementAt_uchar(gOut, uValue, ySize + (width-2-x-pad)/2*height + height - 1 - y); rsSetElementAt_uchar(gOut, vValue, ySize + (width-2-x-pad)/2*height + height - 1 - y - 1); - } else { + } else if (degree == 90) { rsSetElementAt_uchar(gOut, uValue, ySize + x/2*height + height - 1 - y); rsSetElementAt_uchar(gOut, vValue, ySize + x/2*height + height - 1 - y - 1); + } else if (degree == 270) { + if(x >= (width - pad)) + return (uchar)0; + rsSetElementAt_uchar(gOut, uValue, ySize + (width-1-x-pad)/2*height + y -1); + rsSetElementAt_uchar(gOut, vValue, ySize + (width-1-x-pad)/2*height + y); } } return (uchar)0; diff --git a/src/com/android/camera/imageprocessor/FrameProcessor.java b/src/com/android/camera/imageprocessor/FrameProcessor.java old mode 100644 new mode 100755 index a2ae18c1c..5dc50c4e5 --- a/src/com/android/camera/imageprocessor/FrameProcessor.java +++ b/src/com/android/camera/imageprocessor/FrameProcessor.java @@ -40,6 +40,7 @@ import android.renderscript.Allocation; import android.renderscript.Element; import android.renderscript.RenderScript; import android.renderscript.Type; +import android.util.Log; import android.util.Size; import android.view.Surface; import android.widget.Toast; @@ -155,10 +156,12 @@ public class FrameProcessor { mRsRotator.set_width(width); mRsRotator.set_height(height); mRsRotator.set_pad(stridePad); - if(mModule.getMainCameraCharacteristics() != null && - mModule.getMainCameraCharacteristics().get(CameraCharacteristics.SENSOR_ORIENTATION) == 270) { - mRsRotator.set_gFlip(true); + int degree = 90; + if(mModule.getMainCameraCharacteristics() != null) { + degree = mModule.getMainCameraCharacteristics(). + get(CameraCharacteristics.SENSOR_ORIENTATION); } + mRsRotator.set_degree(degree); mRsYuvToRGB.set_gIn(mProcessAllocation); mRsYuvToRGB.set_width(height); mRsYuvToRGB.set_height(width); -- cgit v1.2.3