Camera3: Fix thumbnail stretch issue

If image is already rotated by post proc, swap the thumbnail
destination buffer width and height before giving it to the
encoder

Change-Id: I328a762887b469fc88d298c131cde356dc2dd03f
(cherry picked from commit ab93af6714041141d8a66e6e2c921097e1341a08)
diff --git a/camera/QCamera2/HAL3/QCamera3PostProc.cpp b/camera/QCamera2/HAL3/QCamera3PostProc.cpp
index 0ee075f..a69257d 100644
--- a/camera/QCamera2/HAL3/QCamera3PostProc.cpp
+++ b/camera/QCamera2/HAL3/QCamera3PostProc.cpp
@@ -920,18 +920,22 @@
         memset(&crop, 0, sizeof(cam_rect_t));
         //TBD_later - Zoom event removed in stream
         //thumb_stream->getCropInfo(crop);
-        memset(&src_dim, 0, sizeof(cam_dimension_t));
-        thumb_stream->getFrameDimension(src_dim);
-        jpg_job.encode_job.thumb_dim.src_dim = src_dim;
         m_parent->getThumbnailSize(jpg_job.encode_job.thumb_dim.dst_dim);
+        if (!hal_obj->needRotationReprocess()) {
+           memset(&src_dim, 0, sizeof(cam_dimension_t));
+           thumb_stream->getFrameDimension(src_dim);
+           jpg_job.encode_job.rotation = m_parent->getJpegRotation();
+           ALOGD("%s: jpeg rotation is set to %d", __func__, jpg_job.encode_job.rotation);
+        } else {
+           //swap the thumbnail destination width and height if it has already been rotated
+           int temp = jpg_job.encode_job.thumb_dim.dst_dim.width;
+           jpg_job.encode_job.thumb_dim.dst_dim.width = jpg_job.encode_job.thumb_dim.dst_dim.height;
+           jpg_job.encode_job.thumb_dim.dst_dim.height = temp;
+        }
+        jpg_job.encode_job.thumb_dim.src_dim = src_dim;
         jpg_job.encode_job.thumb_dim.crop = crop;
         jpg_job.encode_job.thumb_index = thumb_frame->buf_idx;
     }
-    if (!hal_obj->needRotationReprocess()) {
-       jpg_job.encode_job.rotation = m_parent->getJpegRotation();
-       ALOGD("%s: jpeg rotation is set to %d", __func__, jpg_job.encode_job.rotation);
-    }
-
     // Find meta data frame. Meta data frame contains additional exif info
     // which will be extracted and filled in by encoder.
     //Note: In this version meta data will be null