Manta: exynos: libcamera2: Add Exif subsec time
authorMark Salyzyn <salyzyn@google.com>
Tue, 16 Sep 2014 21:00:10 +0000 (14:00 -0700)
committerMark Salyzyn <salyzyn@google.com>
Wed, 17 Sep 2014 22:42:22 +0000 (15:42 -0700)
- Add SUBSEC_TIME, SUBSEC_TIME_ORG and SUBSEC_TIME_DIGITIZE
- resolve compiler warnings

Bug: 17472049
Change-Id: I930b9643998017ad07b982a9a905afc29882b669

libcamera2/ExynosCameraHWInterface2.cpp
libcamera2/ExynosExif.h
libcamera2/ExynosJpegEncoderForCamera.cpp

index a722a90bdddb3ccc6f53f3b0eff65782d57ba49e..4d6591467580b2ec5dfe97d98c63fcd5068ceecc 100644 (file)
@@ -33,6 +33,7 @@
 
 //#define LOG_NDEBUG 0
 #define LOG_TAG "ExynosCameraHAL2"
+#include <sys/time.h>
 #include <utils/Log.h>
 #include <math.h>
 
@@ -5790,11 +5791,13 @@ void ExynosCameraHWInterface2::m_setExifChangedAttribute(exif_attribute_t *exifI
     }
 
     //3 Date time
-    time_t rawtime;
+    struct timeval rawtime;
     struct tm *timeinfo;
-    time(&rawtime);
-    timeinfo = localtime(&rawtime);
+    gettimeofday(&rawtime, NULL);
+    timeinfo = localtime(&rawtime.tv_sec);
     strftime((char *)exifInfo->date_time, 20, "%Y:%m:%d %H:%M:%S", timeinfo);
+    snprintf((char *)exifInfo->sub_sec, sizeof(exifInfo->sub_sec), "%03lu",
+        (unsigned long)rawtime.tv_usec / 1000UL);
 
     //2 0th IFD Exif Private Tags
     //3 Exposure Time
index 0b5a599738e58fce9565d371e83b1fb9f65a68e7..532e411692b5a3ef6ffd4bd8b07ffe0fad217ff7 100644 (file)
@@ -30,8 +30,9 @@
 #define IFD_SIZE                    12
 #define OFFSET_SIZE                 4
 
-#define NUM_0TH_IFD_TIFF            10
-#define NUM_0TH_IFD_EXIF            22
+/* Add any additional writeExifIfd() in sections, increase buffer size */
+#define NUM_0TH_IFD_TIFF            11
+#define NUM_0TH_IFD_EXIF            24
 #define NUM_0TH_IFD_GPS             10
 #define NUM_1TH_IFD_TIFF            9
 
@@ -55,6 +56,7 @@
 #define EXIF_TAG_ORIENTATION                    0x0112
 #define EXIF_TAG_SOFTWARE                       0x0131
 #define EXIF_TAG_DATE_TIME                      0x0132
+#define EXIF_TAG_SUBSEC_TIME                    0x9290
 #define EXIF_TAG_YCBCR_POSITIONING              0x0213
 #define EXIF_TAG_EXIF_IFD_POINTER               0x8769
 #define EXIF_TAG_GPS_IFD_POINTER                0x8825
@@ -66,7 +68,9 @@
 #define EXIF_TAG_ISO_SPEED_RATING               0x8827
 #define EXIF_TAG_EXIF_VERSION                   0x9000
 #define EXIF_TAG_DATE_TIME_ORG                  0x9003
+#define EXIF_TAG_SUBSEC_TIME_ORG                0x9291
 #define EXIF_TAG_DATE_TIME_DIGITIZE             0x9004
+#define EXIF_TAG_SUBSEC_TIME_DIGITIZE           0x9292
 #define EXIF_TAG_SHUTTER_SPEED                  0x9201
 #define EXIF_TAG_APERTURE                       0x9202
 #define EXIF_TAG_BRIGHTNESS                     0x9203
@@ -181,6 +185,7 @@ typedef struct {
     unsigned char software[32];
     unsigned char exif_version[4];
     unsigned char date_time[20];
+    unsigned char sub_sec[4];
     unsigned char user_comment[150];
 
     uint32_t width;
index d47b41bc3b95a7f0b569c0fac26698edd03b04b7..e5b84a98718b00acc72e87e16f18088e77d378f7 100644 (file)
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 
+#define LOG_TAG "ExynosJpegForCamera"
 #include <utils/Log.h>
 
 #include "ExynosJpegEncoderForCamera.h"
@@ -22,7 +23,6 @@
 static const char ExifAsciiPrefix[] = { 0x41, 0x53, 0x43, 0x49, 0x49, 0x0, 0x0, 0x0 };
 
 #define JPEG_ERROR_LOG ALOGE
-#define LOG_TAG "ExynosJpegForCamera"
 
 #define JPEG_THUMBNAIL_QUALITY (60)
 #define EXIF_LIMIT_SIZE (64*1024)
@@ -212,7 +212,7 @@ int  ExynosJpegEncoderForCamera::setOutBuf(int buf, char* vBuf, int size)
         return ERROR_NOT_YET_CREATED;
     }
 
-    if (buf == NULL) {
+    if (!buf) {
         return ERROR_BUFFR_IS_NULL;
     }
 
@@ -260,7 +260,7 @@ int ExynosJpegEncoderForCamera::encode(int *size, exif_attribute_t *exifInfo)
     int iJpegBuffer = m_stMainOutBuf.ionBuffer[0];
     char *pcJpegBuffer = m_stMainOutBuf.pcBuf[0];
 
-    if (pcJpegBuffer[0] == NULL) {
+    if (!pcJpegBuffer[0]) {
         JPEG_ERROR_LOG("%s::pcJpegBuffer[0] is null!!\n", __func__);
         return ERROR_OUT_BUFFER_CREATE_FAIL;
     }
@@ -361,6 +361,8 @@ int ExynosJpegEncoderForCamera::makeExif (unsigned char *exifOut,
                  strlen((char *)exifInfo->software) + 1, exifInfo->software, &LongerTagOffest, pIfdStart);
     writeExifIfd(&pCur, EXIF_TAG_DATE_TIME, EXIF_TYPE_ASCII,
                  20, exifInfo->date_time, &LongerTagOffest, pIfdStart);
+    writeExifIfd(&pCur, EXIF_TAG_SUBSEC_TIME, EXIF_TYPE_ASCII,
+                 sizeof(exifInfo->sub_sec), exifInfo->sub_sec);
     writeExifIfd(&pCur, EXIF_TAG_YCBCR_POSITIONING, EXIF_TYPE_SHORT,
                  1, exifInfo->ycbcr_positioning);
     writeExifIfd(&pCur, EXIF_TAG_EXIF_IFD_POINTER, EXIF_TYPE_LONG,
@@ -394,8 +396,12 @@ int ExynosJpegEncoderForCamera::makeExif (unsigned char *exifOut,
                  4, exifInfo->exif_version);
     writeExifIfd(&pCur, EXIF_TAG_DATE_TIME_ORG, EXIF_TYPE_ASCII,
                  20, exifInfo->date_time, &LongerTagOffest, pIfdStart);
+    writeExifIfd(&pCur, EXIF_TAG_SUBSEC_TIME_ORG, EXIF_TYPE_ASCII,
+                 sizeof(exifInfo->sub_sec), exifInfo->sub_sec);
     writeExifIfd(&pCur, EXIF_TAG_DATE_TIME_DIGITIZE, EXIF_TYPE_ASCII,
                  20, exifInfo->date_time, &LongerTagOffest, pIfdStart);
+    writeExifIfd(&pCur, EXIF_TAG_SUBSEC_TIME_DIGITIZE, EXIF_TYPE_ASCII,
+                 sizeof(exifInfo->sub_sec), exifInfo->sub_sec);
     writeExifIfd(&pCur, EXIF_TAG_SHUTTER_SPEED, EXIF_TYPE_SRATIONAL,
                  1, (rational_t *)&exifInfo->shutter_speed, &LongerTagOffest, pIfdStart);
     writeExifIfd(&pCur, EXIF_TAG_APERTURE, EXIF_TYPE_RATIONAL,
@@ -561,14 +567,13 @@ int ExynosJpegEncoderForCamera::makeExif (unsigned char *exifOut,
         memcpy(pNextIfdOffset, &tmp, OFFSET_SIZE);  // NEXT IFD offset skipped on 0th IFD
     }
 
-    unsigned char App1Marker[2] = { 0xff, 0xe1 };
-    memcpy(pApp1Start, App1Marker, 2);
-    pApp1Start += 2;
+    *(pApp1Start++) = 0xff;
+    *(pApp1Start++) = 0xe1;
 
     *size = 10 + LongerTagOffest;
     tmp = *size - 2;    // APP1 Maker isn't counted
-    unsigned char size_mm[2] = {(tmp >> 8) & 0xFF, tmp & 0xFF};
-    memcpy(pApp1Start, size_mm, 2);
+    *(pApp1Start++) = (tmp >> 8) & 0xFF;
+    *(pApp1Start++) = tmp & 0xFF;
 
     return ERROR_NONE;
 }