Now it's better :)
authorPaul Kocialkowski <contact@paulk.fr>
Thu, 31 Jan 2013 21:45:46 +0000 (22:45 +0100)
committerPaul Kocialkowski <contact@paulk.fr>
Thu, 31 Jan 2013 21:45:46 +0000 (22:45 +0100)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
exynos_camera.c
exynos_camera.h
exynos_exif.c

index 8032f62..c0ef9a5 100644 (file)
@@ -994,7 +994,6 @@ int exynos_camera_picture(struct exynos_camera *exynos_camera)
        camera_memory_t *picture_data_memory = NULL;
        camera_memory_t *jpeg_thumbnail_data_memory = NULL;
 
-
        int camera_picture_format;
        int picture_width;
        int picture_height;
@@ -1005,6 +1004,8 @@ int exynos_camera_picture(struct exynos_camera *exynos_camera)
        int jpeg_thumbnail_quality;
        int jpeg_quality;
 
+       int data_size;
+
        int offset = 0;
        void *picture_addr = NULL;
        int picture_size = 0;
@@ -1343,20 +1344,39 @@ int exynos_camera_picture(struct exynos_camera *exynos_camera)
        exynos_exif_attributes_create_params(exynos_camera, &exif_attributes);
 
        rc = exynos_exif_create(exynos_camera, &exif_attributes,
-               picture_data_memory, picture_size,
                jpeg_thumbnail_data_memory, jpeg_thumbnail_size,
-               &exif_data_memory);
-if (rc == -EINVAL) {
-LOGE("OMG ITS EINVALL (%p %p %p %d %d)", picture_data_memory, jpeg_thumbnail_data_memory, &exif_data_memory, picture_size, jpeg_thumbnail_size);
-}
-       if (rc < 0) {
+               &exif_data_memory, &exif_size);
+       if (rc < 0 || exif_data_memory == NULL || exif_size <= 0) {
                LOGE("%s: EXIF create failed!", __func__);
                goto error;
        }
 
-/*
-exif_data_memory
-*/
+       data_size = exif_size + picture_size;
+
+       if (exynos_camera->callbacks.request_memory != NULL) {
+               data_memory =
+                       exynos_camera->callbacks.request_memory(-1,
+                               data_size, 1, 0);
+               if (data_memory == NULL) {
+                       LOGE("%s: data memory request failed!", __func__);
+                       goto error;
+               }
+       } else {
+               LOGE("%s: No memory request function!", __func__);
+               goto error;
+       }
+
+       // Copy the first two bytes of the JPEG picture
+       memcpy(data_memory->data, picture_data_memory->data, 2);
+
+       // Copy the EXIF data
+       memcpy((void *) ((int) data_memory->data + 2), exif_data_memory->data,
+               exif_size);
+
+       // Copy the JPEG picture
+       memcpy((void *) ((int) data_memory->data + 2 + exif_size),
+               (void *) ((int) picture_data_memory->data + 2), picture_size - 2);
+
        // Callbacks
 
        if (EXYNOS_CAMERA_MSG_ENABLED(CAMERA_MSG_SHUTTER) && EXYNOS_CAMERA_CALLBACK_DEFINED(notify))
@@ -1369,9 +1389,9 @@ exif_data_memory
                        jpeg_thumbnail_data_memory, 0, NULL, exynos_camera->callbacks.user);
 
        if (EXYNOS_CAMERA_MSG_ENABLED(CAMERA_MSG_COMPRESSED_IMAGE) && EXYNOS_CAMERA_CALLBACK_DEFINED(data) &&
-               exif_data_memory != NULL)
+               data_memory != NULL)
                exynos_camera->callbacks.data(CAMERA_MSG_COMPRESSED_IMAGE,
-                       exif_data_memory, 0, NULL, exynos_camera->callbacks.user);
+                       data_memory, 0, NULL, exynos_camera->callbacks.user);
 
        // Release memory
 
@@ -1384,6 +1404,9 @@ exif_data_memory
        if (exif_data_memory != NULL && exif_data_memory->release != NULL)
                exif_data_memory->release(exif_data_memory);
 
+       if (data_memory != NULL && data_memory->release != NULL)
+               data_memory->release(data_memory);
+
        return 0;
 
 error:
@@ -1393,6 +1416,12 @@ error:
        if (picture_data_memory != NULL && picture_data_memory->release != NULL)
                picture_data_memory->release(picture_data_memory);
 
+       if (exif_data_memory != NULL && exif_data_memory->release != NULL)
+               exif_data_memory->release(exif_data_memory);
+
+       if (data_memory != NULL && data_memory->release != NULL)
+               data_memory->release(data_memory);
+
        return -1;
 }
 
index bc348cc..629587d 100644 (file)
@@ -219,9 +219,8 @@ int exynos_exif_attributes_create_params(struct exynos_camera *exynos_camera,
 
 int exynos_exif_create(struct exynos_camera *exynos_camera,
        exif_attribute_t *exif_attributes,
-       camera_memory_t *picture_data_memory, int picture_size,
        camera_memory_t *jpeg_thumbnail_data_memory, int jpeg_thumbnail_size,
-       camera_memory_t **exif_data_memory_p);
+       camera_memory_t **exif_data_memory_p, int *exif_size_p);
 
 /*
  * Param
index 2a16c4b..b474b6c 100644 (file)
@@ -399,13 +399,10 @@ int exynos_exif_write_data(void *exif_data, unsigned short tag,
        return size;
 }
 
-// fix respective count/length
-
 int exynos_exif_create(struct exynos_camera *exynos_camera,
        exif_attribute_t *exif_attributes,
-       camera_memory_t *picture_data_memory, int picture_size,
        camera_memory_t *jpeg_thumbnail_data_memory, int jpeg_thumbnail_size,
-       camera_memory_t **exif_data_memory_p)
+       camera_memory_t **exif_data_memory_p, int *exif_size_p)
 {
        // Markers
        unsigned char exif_app1_marker[] = { 0xff, 0xe1 };
@@ -434,12 +431,11 @@ int exynos_exif_create(struct exynos_camera *exynos_camera,
        unsigned int value;
 
        if (exynos_camera == NULL || exif_attributes == NULL ||
-               picture_data_memory == NULL || picture_size <= 0 ||
                jpeg_thumbnail_data_memory == NULL || jpeg_thumbnail_size <= 0 ||
-               exif_data_memory_p == NULL)
+               exif_data_memory_p == NULL || exif_size_p == NULL)
                return -EINVAL;
 
-       exif_data_size = EXIF_FILE_SIZE + picture_size + jpeg_thumbnail_size;
+       exif_data_size = EXIF_FILE_SIZE + jpeg_thumbnail_size;
 
        if (exynos_camera->callbacks.request_memory != NULL) {
                exif_data_memory = exynos_camera->callbacks.request_memory(-1,
@@ -453,17 +449,10 @@ int exynos_exif_create(struct exynos_camera *exynos_camera,
                goto error;
        }
 
-       *exif_data_memory_p = exif_data_memory;
-
        exif_data = exif_data_memory->data;
-       pointer = (unsigned char *) exif_data;
-
        memset(exif_data, 0, exif_data_size);
 
-       // Copy the first two bytes of the JPEG picture
-       memcpy(pointer, picture_data_memory->data, 2);
-       pointer += 2;
-
+       pointer = (unsigned char *) exif_data;
        exif_ifd_data_start = (void *) pointer;
 
        // Skip 4 bytes for APP1 marker
@@ -790,8 +779,8 @@ int exynos_exif_create(struct exynos_camera *exynos_camera,
 
        memcpy(pointer, exif_app1_size, sizeof(exif_app1_size));
 
-       // Add the picture after the EXIF data
-       memcpy((void *) ((int) exif_data + exif_size), picture_data_memory->data, picture_size);
+       *exif_data_memory_p = exif_data_memory;
+       *exif_size_p = exif_size;
 
        return 0;
 
@@ -800,6 +789,7 @@ error:
                exif_data_memory->release(exif_data_memory);
 
        *exif_data_memory_p = NULL;
+       *exif_size_p = 0;
 
        return -1;
 }