From: Jisung Ahn Date: Wed, 23 Jan 2013 11:01:31 +0000 (+0900) Subject: update exif X-Git-Tag: 2.1b_release~3^2~13^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a6d9cea104ddb8b7f4c666ff0aa2342db24c8545;p=apps%2Fhome%2Fug-image-viewer-efl.git update exif Change-Id: I9143a17f53d336fb46e609e7e341220b8503d9be --- diff --git a/common/src/ivug-exif.c b/common/src/ivug-exif.c old mode 100644 new mode 100755 index 2abe593..3f3b414 --- a/common/src/ivug-exif.c +++ b/common/src/ivug-exif.c @@ -98,9 +98,6 @@ #define GL_EXIF_JFIF_01 0x01 #define GL_EXIF_JFIF_02 0x02 - -#define GL_EXI_TMP_JPEG_FILE "/opt/usr/media/.gallery_tmp_write_exif.jpg" - #define GL_EXIF_IFD_DATA_FORMAT_UNSIGNED_BYTE 1 #define GL_EXIF_IFD_DATA_FORMAT_ASCII_STRINGS 1 #define GL_EXIF_IFD_DATA_FORMAT_UNSIGNED_SHORT 2 @@ -114,6 +111,7 @@ #define GL_EXIF_IFD_DATA_FORMAT_SIGNED_FLOAT 4 #define GL_EXIF_IFD_DATA_FORMAT_DOUBLE_FLOAT 8 +#define GL_EXI_TMP_JPEG_FILE "/opt/usr/media/.gallery_tmp_write_exif.jpg" /* Write one byte, testing for EOF */ static int __gl_exif_write_1_byte(FILE *fd, int c) @@ -873,9 +871,9 @@ static int __gl_exif_add_orientation_tag(const char *file_path, orientation_tag[7] = 0x01; orientation_tag[8] = 0x00; - orientation_tag[9] = 0x00; + orientation_tag[9] = (unsigned char)(*orientation); orientation_tag[10] = 0x00; - orientation_tag[11] = (unsigned char)(*orientation); + orientation_tag[11] = 0x00; } else { orientation_tag[0] = 0x12; @@ -891,7 +889,14 @@ static int __gl_exif_add_orientation_tag(const char *file_path, orientation_tag[10] = 0x00; orientation_tag[11] = 0x00; } - + /*if there is no other tag, then only insert orientation_tag,don't go to the while(1)*/ + if(tags_cnt == 1) { + for(j = 0; j < 12 ;j++) { + gl_dbg("orientation_tag- %02X", orientation_tag[j]); + if (__gl_exif_write_1_byte(tmp_fd, orientation_tag[j]) < 0) + goto GL_EXIF_FAILED; + } + } while(1){ if (--tags_cnt == 0) { break; @@ -1172,29 +1177,24 @@ static int __gl_exif_rw_jfif(FILE *fd, const char *file_path, /* Find Exif */ while(1) { + for (i = 0; i < 6; i++) { tmp_exif = __gl_exif_read_1_byte(fd); - if (tmp_exif < 0) - goto GL_EXIF_FAILED; - - tmp[0] = (unsigned char)tmp_exif; - if (tmp[0] != 0x45) - continue; - - for (i = 0; i < 5; i++) { - tmp_exif = __gl_exif_read_1_byte(fd); - if (tmp_exif < 0) + if (tmp_exif < 0) { + gl_dbgW("Not met Exif!"); goto GL_EXIF_FAILED; + } tmp[i] = (unsigned char)tmp_exif; gl_dbg("- %02X", tmp[i]); } - if (tmp[0] == 0x78 && tmp[1] == 0x69 && tmp[2] == 0x66 && - tmp[3] == 0x00 && tmp[4] == 0x00) { + if (tmp[0] == 0x45 && tmp[1] == 0x78 && tmp[2] == 0x69 && tmp[3] == 0x66 && + tmp[4] == 0x00 && tmp[5] == 0x00) { gl_dbgW("Met Exif!"); break; } else { - gl_dbgW("Not met Exif!"); - goto GL_EXIF_FAILED; + gl_dbg("Not met Exif!"); + fseek(fd, -5, SEEK_CUR); + continue; } } @@ -1265,7 +1265,18 @@ static int __gl_exif_rw_jfif(FILE *fd, const char *file_path, } gl_dbg("tags_cnt: %d", tags_cnt); if (tags_cnt == 0) { - gl_dbgE("tags_cnt == 0 - 2"); + gl_dbgE("tags_cnt == 0,no found orientation tag!"); + if (b_write) { + gl_dbgW("to add an orientation tag!"); + fclose(fd); + fd = NULL; + return __gl_exif_add_orientation_tag(file_path, orientation); + + } else{ + /* Normal orientation = 0degree = 1 */ + *orientation = 1; + ret = 0; + } goto GL_EXIF_FAILED; } @@ -1323,7 +1334,10 @@ static int __gl_exif_rw_jfif(FILE *fd, const char *file_path, tmp[8] = (unsigned char)(*orientation); /* Move pointer back to the entry start point */ - fseek(fd, -12, SEEK_CUR); + if (fseek(fd, -12, SEEK_CUR) < 0) { + gl_dbgE("fseek failed!"); + goto GL_EXIF_FAILED; + } fwrite(tmp, 1, 10, fd); } else { /* Get the Orientation value */ @@ -1355,6 +1369,54 @@ static int __gl_exif_rw_jfif(FILE *fd, const char *file_path, gl_dbg("All done"); return ret; } +bool _gl_exif_check_img_type(char *file_path) +{ + GL_CHECK_VAL(file_path, -1); + int tmp_exif = -1; + unsigned int i = 0; + unsigned char exif_data[4] = { 0, }; + FILE *fd = NULL; + bool ret = false; + + if ((fd = fopen(file_path, "rb")) == NULL) { + gl_dbgE("Can't open %s!", file_path); + return -1; + } + + + /* Read File head, check for JPEG SOI + Exif APP1 */ + for (i = 0; i < 4; i++) { + tmp_exif = __gl_exif_read_1_byte(fd); + if (tmp_exif < 0) + goto GL_EXIF_FAILED; + + exif_data[i] = (unsigned char)tmp_exif; + } + + if (exif_data[0] == GL_EXIF_TAG && exif_data[1] == GL_EXIF_SOI) { + gl_dbg("JPEG file"); + } else { + gl_dbgE("Not a JPEG file!"); + goto GL_EXIF_FAILED; + } + + if (exif_data[2] == GL_EXIF_TAG && exif_data[3] == GL_EXIF_APP1) { + gl_dbgW("Exif in APP1!"); + ret = true; + } else if (exif_data[2] == GL_EXIF_TAG && + exif_data[3] == GL_EXIF_APP0) { + gl_dbgW("Jfif in APP0!"); + ret = true; + } else { + gl_dbgE("Not a Exif in APP1 or Jiff in APP2[%d]!", exif_data[3]); + ret = false; + } + GL_EXIF_FAILED: + + fclose(fd); + gl_dbg(""); + return ret; +} static int __gl_exif_rw_orient(const char *file_path, unsigned int *orient, bool b_write) { @@ -1556,7 +1618,10 @@ static int __gl_exif_rw_orient(const char *file_path, unsigned int *orient, bool else exif_data[offset+8] = (unsigned char)(*orient); - fseek(fd, jfif_offset + (4 + 2 + 6 + 2) + offset, SEEK_SET); + if (fseek(fd, jfif_offset + (4 + 2 + 6 + 2) + offset, SEEK_SET) < 0) { + gl_dbgE("fseek failed!"); + goto GL_EXIF_FAILED; + } fwrite(exif_data + 2 + offset, 1, 10, fd); } else { /* Get the Orientation value */ diff --git a/main/src/view/ivug-main-view-menu.cpp b/main/src/view/ivug-main-view-menu.cpp index 6fe8e79..62d2374 100755 --- a/main/src/view/ivug-main-view-menu.cpp +++ b/main/src/view/ivug-main-view-menu.cpp @@ -1913,19 +1913,11 @@ void on_btn_more_clicked(void *data, Evas_Object *obj, void *event_info) { ivug_listpopup_item_append(popup, NULL, IDS_CROP, IDS_CROP); - char *ext = NULL; - ext = ivug_fileinfo_get_file_extension(mdata->filepath); - if(ext) + int degree = 0; + if ( ivug_exif_get_rotate(mdata->filepath, °ree) == 0 ) { - if(strncmp(ext, "jpg", strlen("jpg")) == 0 || strncmp(ext, "JPG", strlen("JPG")) == 0) - { - if(ivug_fileinfo_get_orientation(mdata->filepath) > 0) //exif exist - { - ivug_listpopup_item_append(popup, NULL, IDS_ROTATE_LEFT, IDS_ROTATE_LEFT); - ivug_listpopup_item_append(popup, NULL, IDS_ROTATE_RIGHT, IDS_ROTATE_RIGHT); - } - } - free(ext); + ivug_listpopup_item_append(popup, NULL, IDS_ROTATE_LEFT, IDS_ROTATE_LEFT); + ivug_listpopup_item_append(popup, NULL, IDS_ROTATE_RIGHT, IDS_ROTATE_RIGHT); } } }