hardware: samsung_slsi: libcamera2: Bug fix for digital zoom
authorhyeonmyeong Choi <hyeon.choi@samsung.com>
Wed, 29 Aug 2012 20:55:01 +0000 (13:55 -0700)
committerRebecca Schultz Zavin <rebecca@android.com>
Wed, 5 Sep 2012 21:59:16 +0000 (14:59 -0700)
This patch fixed bug for capture when digital zoom.

Change-Id: I37184b3245752db998958cbe326bd487b0affe06
Signed-off-by: hyeonmyeong Choi <hyeon.choi@samsung.com>
libcamera2/ExynosCameraHWInterface2.cpp
libcamera2/ExynosCameraHWInterface2.h

index 905ce47fea69cd0b4f07b8393b80ef70c3fdbcad..0e94cc28c1524379fb0653caefcb2074206d8df0 100644 (file)
@@ -838,6 +838,7 @@ ExynosCameraHWInterface2::ExynosCameraHWInterface2(int cameraId, camera2_device_
             m_needsRecordBufferInit(false),
             m_needsPreviewCbBufferInit(false),
             lastFrameCnt(-1),
+            m_zoomRatio(1),
             m_scp_closing(false),
             m_scp_closed(false),
             m_afState(HAL_AFSTATE_INACTIVE),
@@ -2645,7 +2646,7 @@ void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self)
                     OnAfTrigger(m_afPendingTriggerId);
                 }
             }
-            float zoomRatio = m_camera2->getSensorW() / shot_ext->shot.ctl.scaler.cropRegion[2];
+            m_zoomRatio = (float)m_camera2->getSensorW() / (float)shot_ext->shot.ctl.scaler.cropRegion[2];
             float zoomLeft, zoomTop, zoomWidth, zoomHeight;
             int crop_x = 0, crop_y = 0, crop_w = 0, crop_h = 0;
 
@@ -2656,11 +2657,11 @@ void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self)
                            0);
 
             if (m_streamThreads[0]->m_parameters.outputWidth >= m_streamThreads[0]->m_parameters.outputHeight) {
-                zoomWidth =  m_camera2->getSensorW() / zoomRatio;
+                zoomWidth =  m_camera2->getSensorW() / m_zoomRatio;
                 zoomHeight = zoomWidth *
                         m_streamThreads[0]->m_parameters.outputHeight / m_streamThreads[0]->m_parameters.outputWidth;
             } else {
-                zoomHeight = m_camera2->getSensorH() / zoomRatio;
+                zoomHeight = m_camera2->getSensorH() / m_zoomRatio;
                 zoomWidth = zoomHeight *
                         m_streamThreads[0]->m_parameters.outputWidth / m_streamThreads[0]->m_parameters.outputHeight;
             }
@@ -2669,6 +2670,11 @@ void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self)
 
             int32_t new_cropRegion[3] = { zoomLeft, zoomTop, zoomWidth };
 
+            if (new_cropRegion[0] * 2 + new_cropRegion[2] > m_camera2->getSensorW())
+                new_cropRegion[2]--;
+            else if (new_cropRegion[0] * 2 + new_cropRegion[2] < m_camera2->getSensorW())
+                new_cropRegion[2]++;
+
             shot_ext->shot.ctl.scaler.cropRegion[0] = new_cropRegion[0];
             shot_ext->shot.ctl.scaler.cropRegion[1] = new_cropRegion[1];
             shot_ext->shot.ctl.scaler.cropRegion[2] = new_cropRegion[2];
@@ -3664,11 +3670,18 @@ void ExynosCameraHWInterface2::m_streamFunc1(SignalDrivenThread *self)
             pictureFramesize = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat), pictureW, pictureH);
 
             if (m_exynosPictureCSC) {
-                m_getRatioSize(pictureW, pictureH,
-                               m_orgPictureRect.w, m_orgPictureRect.h,
-                               &cropX, &cropY,
-                               &cropW, &cropH,
-                               0);
+                float zoom_w = 0, zoom_h = 0;
+                if (m_orgPictureRect.w >= m_orgPictureRect.h) {
+                    zoom_w =  pictureW / m_zoomRatio;
+                    zoom_h = zoom_w * m_orgPictureRect.h / m_orgPictureRect.w;
+                } else {
+                    zoom_h = pictureH / m_zoomRatio;
+                    zoom_w = zoom_h * m_orgPictureRect.w / m_orgPictureRect.h;
+                }
+                cropX = (pictureW - zoom_w) / 2;
+                cropY = (pictureH - zoom_h) / 2;
+                cropW = zoom_w;
+                cropH = zoom_h;
 
                 ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d",
                       __FUNCTION__, cropX, cropY, cropW, cropH);
index 57c5ee907badee6c523c4270f13d051c27903b13..5e579f4777c63f090c1f62bcff43599b4f42d3ae 100644 (file)
@@ -608,6 +608,7 @@ class MainThread : public SignalDrivenThread {
     bool                                m_wideAspect;
     bool                                m_aspectChanged;
     uint32_t                            lastAfRegion[4];
+    float                               m_zoomRatio;
 
     mutable Mutex    m_qbufLock;