From bd327152395d1bd1387d80133ae562eb9b442c22 Mon Sep 17 00:00:00 2001 From: zhubingwei Date: Tue, 2 Apr 2024 10:14:22 +0800 Subject: [PATCH 1/5] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E5=A4=9A0x927c?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=A2=AB=E8=A6=86=E7=9B=96=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20=20=20=20=202.=E6=B7=BB=E5=8A=A0=E9=87=8A=E6=94=BEExifMnoteD?= =?UTF-8?q?ataPriv=20*priv=20=20=20=20=203.=E6=B7=BB=E5=8A=A0mnote=5Fhuawe?= =?UTF-8?q?i=5Fentry=5Fset=5Fvalue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhubingwei --- libexif/exif-data.c | 66 ++++++++------- libexif/huawei/exif-mnote-data-huawei.c | 10 ++- libexif/huawei/exif-mnote-data-huawei.h | 3 + libexif/huawei/mnote-huawei-entry.c | 72 +++++++++++++++- libexif/huawei/mnote-huawei-entry.h | 2 + libexif/huawei/mnote-huawei-tag.c | 106 +++++++++++++++--------- libexif/huawei/mnote-huawei-tag.h | 1 + 7 files changed, 192 insertions(+), 68 deletions(-) diff --git a/libexif/exif-data.c b/libexif/exif-data.c index 352379f..dcf7b83 100644 --- a/libexif/exif-data.c +++ b/libexif/exif-data.c @@ -234,7 +234,7 @@ exif_data_load_data_entry (ExifData *data, ExifEntry *entry, entry->data[6]); } - if (!data->priv->offset_mnote || (entry->data && !memcmp(entry->data, "HUAWEI\0\0", 8))) { + if (!data->priv->offset_mnote || (entry->data && !memcmp(entry->data, HUAWEI_HEADER, 8))) { data->priv->offset_mnote = doff; } } @@ -263,21 +263,25 @@ exif_data_save_data_entry (ExifData *data, ExifEntry *e, if (!(data->priv->options & EXIF_DATA_OPTION_DONT_CHANGE_MAKER_NOTE)) { /* If this is the maker note tag, update it. */ - if ((e->tag == EXIF_TAG_MAKER_NOTE) && data->priv->md) { - /* TODO: this is using the wrong ExifMem to free e->data */ - exif_mem_free (data->priv->mem, e->data); - e->data = NULL; - e->size = 0; - exif_mnote_data_set_offset (data->priv->md, *ds - 6); - exif_mnote_data_save (data->priv->md, &e->data, &e->size); - e->components = e->size; - if (exif_format_get_size (e->format) != 1) { - /* e->format is taken from input code, - * but we need to make sure it is a 1 byte - * entity due to the multiplication below. */ - e->format = EXIF_FORMAT_UNDEFINED; + do { + if ((e->tag == EXIF_TAG_MAKER_NOTE) && data->priv->md) { + if (is_huawei_md(data->priv->md) && memcmp(e->data, HUAWEI_HEADER, 8)) break; + + /* TODO: this is using the wrong ExifMem to free e->data */ + exif_mem_free (data->priv->mem, e->data); + e->data = NULL; + e->size = 0; + exif_mnote_data_set_offset (data->priv->md, *ds - 6); + exif_mnote_data_save (data->priv->md, &e->data, &e->size); + e->components = e->size; + if (exif_format_get_size (e->format) != 1) { + /* e->format is taken from input code, + * but we need to make sure it is a 1 byte + * entity due to the multiplication below. */ + e->format = EXIF_FORMAT_UNDEFINED; + } } - } + } while(0); } exif_set_long (*d + 6 + offset + 4, @@ -349,21 +353,25 @@ exif_data_save_data_entry_general (ExifData *data, ExifEntry *e, if (!(data->priv->options & EXIF_DATA_OPTION_DONT_CHANGE_MAKER_NOTE)) { /* If this is the maker note tag, update it. */ - if ((e->tag == EXIF_TAG_MAKER_NOTE) && data->priv->md) { - /* TODO: this is using the wrong ExifMem to free e->data */ - exif_mem_free(data->priv->mem, e->data); - e->data = NULL; - e->size = 0; - exif_mnote_data_set_offset(data->priv->md, *ds - 6 + JPEG_HEADER_LEN); - exif_mnote_data_save(data->priv->md, &e->data, &e->size); - e->components = e->size; - if (exif_format_get_size(e->format) != 1) { - /* e->format is taken from input code, - * but we need to make sure it is a 1 byte - * entity due to the multiplication below. */ - e->format = EXIF_FORMAT_UNDEFINED; + do { + if ((e->tag == EXIF_TAG_MAKER_NOTE) && data->priv->md) { + if (is_huawei_md(data->priv->md) && memcmp(e->data, HUAWEI_HEADER, 8)) break; + + /* TODO: this is using the wrong ExifMem to free e->data */ + exif_mem_free(data->priv->mem, e->data); + e->data = NULL; + e->size = 0; + exif_mnote_data_set_offset(data->priv->md, *ds - 6 + JPEG_HEADER_LEN); + exif_mnote_data_save(data->priv->md, &e->data, &e->size); + e->components = e->size; + if (exif_format_get_size(e->format) != 1) { + /* e->format is taken from input code, + * but we need to make sure it is a 1 byte + * entity due to the multiplication below. */ + e->format = EXIF_FORMAT_UNDEFINED; + } } - } + }while(0); } exif_set_long(*d + 6 - JPEG_HEADER_LEN + offset + 4, diff --git a/libexif/huawei/exif-mnote-data-huawei.c b/libexif/huawei/exif-mnote-data-huawei.c index 09a5f22..fb0c95a 100644 --- a/libexif/huawei/exif-mnote-data-huawei.c +++ b/libexif/huawei/exif-mnote-data-huawei.c @@ -28,6 +28,7 @@ const int DATA_OR_OFFSET = 4; const int HUAWEI_HEADER_OFFSET = 8; + const char HUAWEI_HEADER[] = { 'H', 'U', 'A', 'W', 'E', 'I', '\0', '\0', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -84,6 +85,12 @@ exif_mnote_data_huawei_clear (ExifMnoteDataHuawei *n) n->count = 0; n->is_loaded = 0; } + + if (n->ifd_tag != MNOTE_HUAWEI_INFO && d->priv) { + exif_mem_free(d->mem, d->priv); + exif_mem_unref (d->mem); + d->priv = NULL; + } } static void @@ -172,6 +179,7 @@ exif_mnote_data_huawei_save_data (ExifMnoteData *ne, unsigned char *buf, unsigne ExifMnoteDataHuawei *t_n = n->entries[i].md; exif_mnote_data_huawei_save_data(n->entries[i].md, buf+ifd_data_offset + ifd_data_offset_increment, t_n->ifd_size, pOrder); ifd_data_offset_increment += t_n->ifd_size; + exif_set_long (n->entries[i].data, n->order, t_offset); } if (components_size > DATA_OR_OFFSET) { @@ -343,7 +351,7 @@ exif_mnote_data_huawei_load (ExifMnoteData *ne, const unsigned char *buf, unsign return; } - n->ifd_tag = 0xffff; + n->ifd_tag = MNOTE_HUAWEI_INFO; if ((buf[0] == 'I' && buf[1] == 'I') || (buf[0] == 'M' && buf[1] == 'M')) { head_offset = 0; diff --git a/libexif/huawei/exif-mnote-data-huawei.h b/libexif/huawei/exif-mnote-data-huawei.h index 5eef9f8..6902966 100644 --- a/libexif/huawei/exif-mnote-data-huawei.h +++ b/libexif/huawei/exif-mnote-data-huawei.h @@ -25,6 +25,9 @@ #include #include + +extern const char HUAWEI_HEADER[]; + typedef struct _ExifMnoteDataHuawei ExifMnoteDataHuawei; diff --git a/libexif/huawei/mnote-huawei-entry.c b/libexif/huawei/mnote-huawei-entry.c index 41f5b65..069e7a2 100644 --- a/libexif/huawei/mnote-huawei-entry.c +++ b/libexif/huawei/mnote-huawei-entry.c @@ -14,7 +14,6 @@ */ #include "config.h" -#include "mnote-huawei-entry.h" #include #include @@ -25,6 +24,10 @@ #include #include +#include "mnote-huawei-tag.h" +#include "mnote-huawei-entry.h" +#include "exif-mnote-data-huawei.h" + char * mnote_huawei_entry_get_value(MnoteHuaweiEntry *entry, char *v, unsigned int maxlen) @@ -51,4 +54,71 @@ mnote_huawei_entry_get_value(MnoteHuaweiEntry *entry, char *v, unsigned int maxl *(v+write_pos-1) = 0; return v; +} + +int +mnote_huawei_entry_set_value(MnoteHuaweiEntry *entry, char *v, int strlen) +{ + if (!entry || !v || entry->md) return -1; + ExifMnoteData* parent_md = (ExifMnoteData*)entry->parent_md; + if (!parent_md) return -1; + + char data[1024] = {0}; + int increment = 0; + int components = 0; + int components_size = 0; + char *token = NULL; + + if (entry->format == EXIF_FORMAT_UNDEFINED) { + increment = 1; + } else if (entry->format == EXIF_FORMAT_SLONG || EXIF_FORMAT_LONG) { + increment = 4; + } else { + return -1; + } + + char* pv = exif_mem_alloc(parent_md->mem, strlen + 1); + if (!pv) return -1; + memset(pv, 0, strlen + 1); + memcpy(pv, v, strlen); + + token = strtok(pv, " "); + for (;token && components_size < sizeof(data);) { + int value = atoi(token); + int offset = increment*components; + if (increment == 1) { + if (value > 0xff || value < 0) { + goto FAILED; + } + *(data+offset) = value; + } else { + exif_set_slong((data+offset), entry->order, value); + } + components++; + components_size = components * increment; + token = strtok(NULL, " "); + } + + if (!components || (entry->format != EXIF_FORMAT_UNDEFINED && components > 1)) { + goto FAILED; + } + + if (entry->size < components_size) { + unsigned char* realloc = NULL; + realloc = exif_mem_realloc(parent_md->mem, entry->data, components_size); + if (!realloc) { + goto FAILED; + } + entry->data = realloc; + } + + entry->components = components; + entry->size = components_size; + memcpy(entry->data, data, components_size); + exif_mem_free(parent_md->mem, pv); + return 0; + +FAILED: + exif_mem_free(parent_md->mem, pv); + return -1; } \ No newline at end of file diff --git a/libexif/huawei/mnote-huawei-entry.h b/libexif/huawei/mnote-huawei-entry.h index 447cb55..1861dbd 100644 --- a/libexif/huawei/mnote-huawei-entry.h +++ b/libexif/huawei/mnote-huawei-entry.h @@ -21,6 +21,7 @@ #include typedef struct _MnoteHuaweiEntry MnoteHuaweiEntry; +typedef struct _ExifMnoteDataHuawei ExifMnoteDataHuawei; struct _MnoteHuaweiEntry { MnoteHuaweiTag tag; @@ -40,6 +41,7 @@ extern "C" { #endif /* __cplusplus */ char *mnote_huawei_entry_get_value (MnoteHuaweiEntry *entry, char *v, unsigned int maxlen); +int mnote_huawei_entry_set_value(MnoteHuaweiEntry *entry, char *v, int strlen); #ifdef __cplusplus } diff --git a/libexif/huawei/mnote-huawei-tag.c b/libexif/huawei/mnote-huawei-tag.c index c482a9e..da1aadb 100644 --- a/libexif/huawei/mnote-huawei-tag.c +++ b/libexif/huawei/mnote-huawei-tag.c @@ -14,20 +14,47 @@ */ #include -#include "mnote-huawei-tag.h" - #include - #include +#include "mnote-huawei-tag.h" +typedef struct _MnoteHuaweiTable MnoteHuaweiTable; -static const struct { +struct _MnoteHuaweiTable { MnoteHuaweiTag tag; const char *name; const char *title; const char *description; MnoteHuaweiTagType TagType; -} table[] = { +}; + +static const MnoteHuaweiTable huawei_table[] = { + {MNOTE_HUAWEI_CAPTURE_MODE, "HwMnoteCaptureMode", N_("Capture Mode"), "CaptureMode"}, + {MNOTE_HUAWEI_BURST_NUMBER, "HwMnoteBurstNumber", N_("Burst Number"), "BurstNumber"}, + {MNOTE_HUAWEI_FRONT_CAMERA, "HwMnoteFrontCamera", N_("Front Camera"), "FrontCamera"}, + {MNOTE_HUAWEI_ROLL_ANGLE, "HwMnoteRollAngle", N_("Roll Angle"), "RollAngle"}, + {MNOTE_HUAWEI_PITCH_ANGLE, "HwMnotePitchAngle", N_("Pitch Angle"), "PitchAngle"}, + {MNOTE_HUAWEI_PHYSICAL_APERTURE, "HwMnotePhysicalAperture", N_("Physical Aperture"), "PhysicalAperture"}, + {MNOTE_HUAWEI_FOCUS_MODE, "HwMnoteFocusMode", N_("Focus Mode"), "FocusMode"}, + + {0, "HwUnknow", N_("Unknow Tag"), "UnknowTag"}, +}; + +static const MnoteHuaweiTable huawei_face_table[] = { + {MNOTE_HUAWEI_FACE_INFO, "HwMnoteFacePointer", N_("Face Info"), "FaceInfo", MNOTE_HUAWEI_TAG_TYPE_IFD}, + {MNOTE_HUAWEI_FACE_VERSION, "HwMnoteFaceVersion", N_("Face Version"), "FaceVersion"}, + {MNOTE_HUAWEI_FACE_COUNT, "HwMnoteFaceCount", N_("Count"), "Count"}, + {MNOTE_HUAWEI_FACE_CONF, "HwMnoteFaceConf", N_("Conf"), "Conf"}, + {MNOTE_HUAWEI_FACE_SMILE_SCORE, "HwMnoteFaceSmileScore", N_("Smile Score"), "SmileScore"}, + {MNOTE_HUAWEI_FACE_RECT, "HwMnoteFaceRect", N_("Rect"), "Rect"}, + {MNOTE_HUAWEI_FACE_LEYE_CENTER, "HwMnoteFaceLeyeCenter", N_("LeyeCenter"), "LeyeCenter"}, + {MNOTE_HUAWEI_FACE_REYE_CENTER, "HwMnoteFaceReyeCenter", N_("Reye Center"), "ReyeCenter"}, + {MNOTE_HUAWEI_FACE_MOUTH_CENTER, "HwMnoteFaceMouthCenter", N_("Mouth Center"), "MouthCenter"}, + + {0, "HwUnknow", N_("Unknow Tag"), "UnknowTag"}, +}; + +static const MnoteHuaweiTable huawei_scene_table[] = { {MNOTE_HUAWEI_SCENE_INFO, "HwMnoteScenePointer", N_("Scene Info"), "SceneInfo", MNOTE_HUAWEI_TAG_TYPE_IFD}, {MNOTE_HUAWEI_SCENE_VERSION, "HwMnoteSceneVersion", N_("Scene Version"), "SceneVersion"}, {MNOTE_HUAWEI_SCENE_FOOD_CONF, "HwMnoteSceneFoodConf", N_("Food Conf"), "FoodConf"}, @@ -41,63 +68,68 @@ static const struct { {MNOTE_HUAWEI_SCENE_NIGHT_CONF, "HwMnoteSceneNightConf", N_("Night Conf"), "NightConf"}, {MNOTE_HUAWEI_SCENE_TEXT_CONF, "HwMnoteSceneTextConf", N_("Text Conf"), "TextConf"}, - {MNOTE_HUAWEI_FACE_INFO, "HwMnoteFacePointer", N_("Face Info"), "FaceInfo", MNOTE_HUAWEI_TAG_TYPE_IFD}, - {MNOTE_HUAWEI_FACE_VERSION, "HwMnoteFaceVersion", N_("Face Version"), "FaceVersion"}, - {MNOTE_HUAWEI_FACE_COUNT, "HwMnoteFaceCount", N_("Count"), "Count"}, - {MNOTE_HUAWEI_FACE_CONF, "HwMnoteFaceConf", N_("Conf"), "Conf"}, - {MNOTE_HUAWEI_FACE_SMILE_SCORE, "HwMnoteFaceSmileScore", N_("Smile Score"), "SmileScore"}, - {MNOTE_HUAWEI_FACE_RECT, "HwMnoteFaceRect", N_("Rect"), "Rect"}, - {MNOTE_HUAWEI_FACE_LEYE_CENTER, "HwMnoteFaceLeyeCenter", N_("LeyeCenter"), "LeyeCenter"}, - {MNOTE_HUAWEI_FACE_REYE_CENTER, "HwMnoteFaceReyeCenter", N_("Reye Center"), "ReyeCenter"}, - {MNOTE_HUAWEI_FACE_MOUTH_CENTER, "HwMnoteFaceMouthCenter", N_("Mouth Center"), "MouthCenter"}, - - {MNOTE_HUAWEI_CAPTURE_MODE, "HwMnoteCaptureMode", N_("Capture Mode"), "CaptureMode"}, - {MNOTE_HUAWEI_BURST_NUMBER, "HwMnoteBurstNumber", N_("Burst Number"), "BurstNumber"}, - {MNOTE_HUAWEI_FRONT_CAMERA, "HwMnoteFrontCamera", N_("Front Camera"), "FrontCamera"}, - {MNOTE_HUAWEI_ROLL_ANGLE, "HwMnoteRollAngle", N_("Roll Angle"), "RollAngle"}, - {MNOTE_HUAWEI_PITCH_ANGLE, "HwMnotePitchAngle", N_("Pitch Angle"), "PitchAngle"}, - {MNOTE_HUAWEI_PHYSICAL_APERTURE, "HwMnotePhysicalAperture", N_("Physical Aperture"), "PhysicalAperture"}, - {MNOTE_HUAWEI_FOCUS_MODE, "HwMnoteFocusMode", N_("Focus Mode"), "FocusMode"}, - {0, "HwUnknow", N_("Unknow Tag"), "UnknowTag"}, }; -#define GET_TAG_INFO(t, idx, ret) do { \ - for (int i = 0; i < sizeof (table) / sizeof (table[0]); i++) { \ - ret = table[i].idx; \ - if (table[i].tag == t) break; \ +#define GET_TAG_INFO(tb, tb_size, tag, idx, ret) do { \ + for (int i = 0; i> 9 & 1) { + *size = sizeof (huawei_table) / sizeof (huawei_table[0]); + return huawei_table; + } + + if (tag >> 8 & 1) { + *size = sizeof (huawei_face_table) / sizeof (huawei_face_table[0]); + return huawei_face_table; + } + + *size = sizeof (huawei_scene_table) / sizeof (huawei_scene_table[0]); + return huawei_scene_table; +} const char * -mnote_huawei_tag_get_name (MnoteHuaweiTag t) +mnote_huawei_tag_get_name (MnoteHuaweiTag tag) { const char* p = NULL; - GET_TAG_INFO(t, name, p); + int size = 0; + MnoteHuaweiTable* tb = get_tag_table(tag, &size); + GET_TAG_INFO(tb, size, tag, name, p); return p; } const char * -mnote_huawei_tag_get_title (MnoteHuaweiTag t) +mnote_huawei_tag_get_title (MnoteHuaweiTag tag) { const char* p = NULL; - GET_TAG_INFO(t, title, p); + int size = 0; + MnoteHuaweiTable* tb = get_tag_table(tag, &size); + GET_TAG_INFO(tb, size, tag, title, p); return p; } const char * -mnote_huawei_tag_get_description (MnoteHuaweiTag t) +mnote_huawei_tag_get_description (MnoteHuaweiTag tag) { const char* p = NULL; - GET_TAG_INFO(t, description, p); + int size = 0; + MnoteHuaweiTable* tb = get_tag_table(tag, &size); + GET_TAG_INFO(tb, size, tag, description, p); return p; } MnoteHuaweiTagType -mnote_huawei_tag_type (MnoteHuaweiTag t) +mnote_huawei_tag_type (MnoteHuaweiTag tag) { MnoteHuaweiTagType p = 0; - GET_TAG_INFO(t, TagType, p); + int size = 0; + MnoteHuaweiTable* tb = get_tag_table(tag, &size); + GET_TAG_INFO(tb, size, tag, TagType, p); return p; } diff --git a/libexif/huawei/mnote-huawei-tag.h b/libexif/huawei/mnote-huawei-tag.h index 632a540..b9b81ba 100644 --- a/libexif/huawei/mnote-huawei-tag.h +++ b/libexif/huawei/mnote-huawei-tag.h @@ -23,6 +23,7 @@ extern "C" { #endif /* __cplusplus */ enum _MnoteHuaweiTag { + MNOTE_HUAWEI_INFO = 0xFFFF, MNOTE_HUAWEI_CAPTURE_MODE = 0x0200, MNOTE_HUAWEI_BURST_NUMBER = 0x0201, MNOTE_HUAWEI_FRONT_CAMERA = 0x0202, -- Gitee From e2cb6d25e03e18f3cd21170ac55de7054ad8c54e Mon Sep 17 00:00:00 2001 From: zhubingwei Date: Tue, 2 Apr 2024 14:32:26 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhuawei=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhubingwei Change-Id: Ib32f57b48659038163446adddb9c8ff0841754d6 --- libexif/huawei/mnote-huawei-entry.c | 2 +- libexif/huawei/mnote-huawei-tag.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libexif/huawei/mnote-huawei-entry.c b/libexif/huawei/mnote-huawei-entry.c index 069e7a2..453b9db 100644 --- a/libexif/huawei/mnote-huawei-entry.c +++ b/libexif/huawei/mnote-huawei-entry.c @@ -63,7 +63,7 @@ mnote_huawei_entry_set_value(MnoteHuaweiEntry *entry, char *v, int strlen) ExifMnoteData* parent_md = (ExifMnoteData*)entry->parent_md; if (!parent_md) return -1; - char data[1024] = {0}; + unsigned char data[1024] = {0}; int increment = 0; int components = 0; int components_size = 0; diff --git a/libexif/huawei/mnote-huawei-tag.c b/libexif/huawei/mnote-huawei-tag.c index da1aadb..14dac46 100644 --- a/libexif/huawei/mnote-huawei-tag.c +++ b/libexif/huawei/mnote-huawei-tag.c @@ -78,7 +78,7 @@ static const MnoteHuaweiTable huawei_scene_table[] = { ret = tb[tb_size-1].idx;\ } while (0) -MnoteHuaweiTable* get_tag_table(MnoteHuaweiTag tag, int* size) +const MnoteHuaweiTable* get_tag_table(MnoteHuaweiTag tag, int* size) { if (tag >> 9 & 1) { *size = sizeof (huawei_table) / sizeof (huawei_table[0]); @@ -99,17 +99,17 @@ mnote_huawei_tag_get_name (MnoteHuaweiTag tag) { const char* p = NULL; int size = 0; - MnoteHuaweiTable* tb = get_tag_table(tag, &size); + const MnoteHuaweiTable* tb = get_tag_table(tag, &size); GET_TAG_INFO(tb, size, tag, name, p); return p; } const char * -mnote_huawei_tag_get_title (MnoteHuaweiTag tag) +mnote_huawei_tag_get_title (MnoteHuaweiTag tag) { const char* p = NULL; int size = 0; - MnoteHuaweiTable* tb = get_tag_table(tag, &size); + const MnoteHuaweiTable* tb = get_tag_table(tag, &size); GET_TAG_INFO(tb, size, tag, title, p); return p; } @@ -119,7 +119,7 @@ mnote_huawei_tag_get_description (MnoteHuaweiTag tag) { const char* p = NULL; int size = 0; - MnoteHuaweiTable* tb = get_tag_table(tag, &size); + const MnoteHuaweiTable* tb = get_tag_table(tag, &size); GET_TAG_INFO(tb, size, tag, description, p); return p; } @@ -129,7 +129,7 @@ mnote_huawei_tag_type (MnoteHuaweiTag tag) { MnoteHuaweiTagType p = 0; int size = 0; - MnoteHuaweiTable* tb = get_tag_table(tag, &size); + const MnoteHuaweiTable* tb = get_tag_table(tag, &size); GET_TAG_INFO(tb, size, tag, TagType, p); return p; } -- Gitee From 1a0b535c694d5ec16e26ebb77df38c9cc87caf8e Mon Sep 17 00:00:00 2001 From: zhubingwei Date: Tue, 2 Apr 2024 16:23:12 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhubingwei --- libexif/huawei/exif-mnote-data-huawei.c | 48 +++++++++++++------------ libexif/huawei/mnote-huawei-data-type.c | 4 +-- libexif/huawei/mnote-huawei-entry.c | 39 +++++++++++++------- libexif/huawei/mnote-huawei-entry.h | 4 +-- libexif/huawei/mnote-huawei-tag.c | 13 ++++--- libexif/huawei/mnote-huawei-tag.h | 2 +- 6 files changed, 65 insertions(+), 45 deletions(-) diff --git a/libexif/huawei/exif-mnote-data-huawei.c b/libexif/huawei/exif-mnote-data-huawei.c index fb0c95a..99b4122 100644 --- a/libexif/huawei/exif-mnote-data-huawei.c +++ b/libexif/huawei/exif-mnote-data-huawei.c @@ -28,9 +28,8 @@ const int DATA_OR_OFFSET = 4; const int HUAWEI_HEADER_OFFSET = 8; - const char HUAWEI_HEADER[] = { 'H', 'U', 'A', 'W', 'E', 'I', '\0', '\0', - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; void memory_dump(const void *ptr, int len) { @@ -38,8 +37,8 @@ void memory_dump(const void *ptr, int len) for (int i = 0; i < len; i++) { if (i % 8 == 0 && i != 0) printf(" "); - if (i % 16 == 0 && i != 0) - printf("\n%08X: ", i); + if (i % 16 == 0 && i != 0) + printf("\n%08X: ", i); printf("%02x ", *((uint8_t *)ptr + i)); } printf("\n"); @@ -113,7 +112,7 @@ exif_mnote_data_huawei_set_offset (ExifMnoteData *n, unsigned int o) } static void -exif_mnote_data_huawei_malloc_size_data (ExifMnoteData *ne, unsigned int *malloc_size) +exif_mnote_data_huawei_malloc_size_data (ExifMnoteData *ne, unsigned int *malloc_size) { ExifMnoteDataHuawei *n = (ExifMnoteDataHuawei *) ne; @@ -237,7 +236,7 @@ exif_mnote_data_huawei_save (ExifMnoteData *ne, unsigned char **buf, unsigned in } static int -exif_mnote_data_huawei_load_data (ExifMnoteData *ne, const unsigned char *buf, unsigned int buf_size, +exif_mnote_data_huawei_load_data (ExifMnoteData *ne, const unsigned char *buf, unsigned int buf_size, unsigned int* cur_ifd_data_offset, const unsigned int order_offset) { size_t tcount, offset, ifd_size=0; @@ -367,14 +366,14 @@ exif_mnote_data_huawei_load (ExifMnoteData *ne, const unsigned char *buf, unsign n->order = EXIF_BYTE_ORDER_MOTOROLA; else { exif_log (ne->log, EXIF_LOG_CODE_CORRUPT_DATA, - "ExifMnoteHuawei", "Unknown order."); + "ExifMnoteHuawei", "Unknown order."); return; } /* Remove any old entries */ exif_mnote_data_huawei_clear (n); - unsigned int ifd_data_offset= n->offset + head_offset + sizeof(HUAWEI_HEADER); + unsigned int ifd_data_offset= n->offset + head_offset + sizeof(HUAWEI_HEADER); int ret = exif_mnote_data_huawei_load_data(ne, buf, buf_size, &ifd_data_offset, order_offset); if (ret) { exif_log (ne->log, EXIF_LOG_CODE_CORRUPT_DATA, @@ -384,7 +383,7 @@ exif_mnote_data_huawei_load (ExifMnoteData *ne, const unsigned char *buf, unsign } unsigned int -exif_mnote_data_huawei_count_data (ExifMnoteData *ne, MnoteHuaweiEntryCount* ec) +exif_mnote_data_huawei_count_data (ExifMnoteData *ne, MnoteHuaweiEntryCount* ec) { ExifMnoteDataHuawei *n = (ExifMnoteDataHuawei *) ne; if (!ne) return 0; @@ -405,14 +404,15 @@ exif_mnote_data_huawei_count_data (ExifMnoteData *ne, MnoteHuaweiEntryCount* ec) } unsigned int -exif_mnote_data_huawei_count (ExifMnoteData *ne) +exif_mnote_data_huawei_count (ExifMnoteData *ne) { if (!ne) return 0; unsigned int count = exif_mnote_data_huawei_count_data(ne, NULL); return count; }; -MnoteHuaweiEntry* exif_mnote_data_huawei_get_entry_by_tag_data (ExifMnoteDataHuawei *n, int *idx, const MnoteHuaweiTag tag) +MnoteHuaweiEntry* +exif_mnote_data_huawei_get_entry_by_tag_data (ExifMnoteDataHuawei *n, int *idx, const MnoteHuaweiTag tag) { MnoteHuaweiEntry* entry = NULL; if (!n) return NULL; @@ -433,13 +433,15 @@ MnoteHuaweiEntry* exif_mnote_data_huawei_get_entry_by_tag_data (ExifMnoteDataHua return entry; } -MnoteHuaweiEntry* exif_mnote_data_huawei_get_entry_by_tag (ExifMnoteDataHuawei *n, const MnoteHuaweiTag tag) +MnoteHuaweiEntry* +exif_mnote_data_huawei_get_entry_by_tag (ExifMnoteDataHuawei *n, const MnoteHuaweiTag tag) { int i = 0; return exif_mnote_data_huawei_get_entry_by_tag_data(n, &i, tag); } -MnoteHuaweiEntry* exif_mnote_data_huawei_get_entry_by_index_data (ExifMnoteDataHuawei *n, int *idx, const int dest_idx) +MnoteHuaweiEntry* +exif_mnote_data_huawei_get_entry_by_index_data (ExifMnoteDataHuawei *n, int *idx, const int dest_idx) { MnoteHuaweiEntry* entry = NULL; if (!n) return NULL; @@ -460,13 +462,15 @@ MnoteHuaweiEntry* exif_mnote_data_huawei_get_entry_by_index_data (ExifMnoteDataH return entry; } -MnoteHuaweiEntry* exif_mnote_data_huawei_get_entry_by_index (ExifMnoteDataHuawei *n, const int dest_idx) +MnoteHuaweiEntry* +exif_mnote_data_huawei_get_entry_by_index (ExifMnoteDataHuawei *n, const int dest_idx) { int i = 0; return exif_mnote_data_huawei_get_entry_by_index_data(n, &i, dest_idx); } -void mnote_huawei_get_entry_count (const ExifMnoteDataHuawei* n, MnoteHuaweiEntryCount** entry_count) +void +mnote_huawei_get_entry_count (const ExifMnoteDataHuawei* n, MnoteHuaweiEntryCount** entry_count) { if (!n) return; @@ -497,13 +501,13 @@ void mnote_huawei_get_entry_count (const ExifMnoteDataHuawei* n, MnoteHuaweiEntr *entry_count = ec; } -void mnote_huawei_free_entry_count (MnoteHuaweiEntryCount* entry_count) +void mnote_huawei_free_entry_count (MnoteHuaweiEntryCount* entry_count) { exif_huawei_entry_count_free(entry_count); } static unsigned int -exif_mnote_data_huawei_get_id (ExifMnoteData *ne, unsigned int i) +exif_mnote_data_huawei_get_id (ExifMnoteData *ne, unsigned int i) { ExifMnoteDataHuawei *n = (ExifMnoteDataHuawei *) ne; if (!n) return 0; @@ -515,7 +519,7 @@ exif_mnote_data_huawei_get_id (ExifMnoteData *ne, unsigned int i) } static const char * -exif_mnote_data_huawei_get_name (ExifMnoteData *ne, unsigned int i) +exif_mnote_data_huawei_get_name (ExifMnoteData *ne, unsigned int i) { ExifMnoteDataHuawei *n = (ExifMnoteDataHuawei *) ne; if (!n) return NULL; @@ -527,7 +531,7 @@ exif_mnote_data_huawei_get_name (ExifMnoteData *ne, unsigned int i) } static const char * -exif_mnote_data_huawei_get_title (ExifMnoteData *ne, unsigned int i) +exif_mnote_data_huawei_get_title (ExifMnoteData *ne, unsigned int i) { ExifMnoteDataHuawei *n = (ExifMnoteDataHuawei *) ne; if (!n) return NULL; @@ -539,7 +543,7 @@ exif_mnote_data_huawei_get_title (ExifMnoteData *ne, unsigned int i) } static const char * -exif_mnote_data_huawei_get_description (ExifMnoteData *ne, unsigned int i) +exif_mnote_data_huawei_get_description (ExifMnoteData *ne, unsigned int i) { ExifMnoteDataHuawei *n = (ExifMnoteDataHuawei *) ne; if (!n) return NULL; @@ -563,7 +567,7 @@ exif_mnote_data_huawei_get_value (ExifMnoteData *ne, unsigned int i, char *val, } int -exif_mnote_data_huawei_identify (const ExifData *ed, const ExifEntry *e) +exif_mnote_data_huawei_identify (const ExifData *ed, const ExifEntry *e) { int ret = 0; @@ -583,7 +587,7 @@ int is_huawei_md(ExifMnoteData* ne) } ExifMnoteData * -exif_mnote_data_huawei_new (ExifMem *mem) +exif_mnote_data_huawei_new (ExifMem *mem) { ExifMnoteData *ne; diff --git a/libexif/huawei/mnote-huawei-data-type.c b/libexif/huawei/mnote-huawei-data-type.c index f4af25e..338f4fd 100644 --- a/libexif/huawei/mnote-huawei-data-type.c +++ b/libexif/huawei/mnote-huawei-data-type.c @@ -55,11 +55,11 @@ exif_huawei_entry_count_free (MnoteHuaweiEntryCount *ec) { ExifMem *mem; - if (!ec) + if (!ec) return; mem = ec->mem; - if (ec->entries) + if (ec->entries) exif_mem_free(mem, ec->entries); exif_mem_free (mem, ec); diff --git a/libexif/huawei/mnote-huawei-entry.c b/libexif/huawei/mnote-huawei-entry.c index 453b9db..7659762 100644 --- a/libexif/huawei/mnote-huawei-entry.c +++ b/libexif/huawei/mnote-huawei-entry.c @@ -57,29 +57,41 @@ mnote_huawei_entry_get_value(MnoteHuaweiEntry *entry, char *v, unsigned int maxl } int -mnote_huawei_entry_set_value(MnoteHuaweiEntry *entry, char *v, int strlen) +mnote_huawei_entry_set_value(MnoteHuaweiEntry *entry, const char *v, int strlen) { - if (!entry || !v || entry->md) return -1; - ExifMnoteData* parent_md = (ExifMnoteData*)entry->parent_md; - if (!parent_md) return -1; - unsigned char data[1024] = {0}; int increment = 0; int components = 0; int components_size = 0; char *token = NULL; + int ret = 0; + char* pv = NULL; + + if (!entry || !v || entry->md) { + ret = -1; + goto FAILED; + } + ExifMnoteData* parent_md = (ExifMnoteData*)entry->parent_md; + if (!parent_md) { + ret = -1; + goto FAILED; + } if (entry->format == EXIF_FORMAT_UNDEFINED) { increment = 1; } else if (entry->format == EXIF_FORMAT_SLONG || EXIF_FORMAT_LONG) { increment = 4; } else { - return -1; + ret = -1; + goto FAILED; } - char* pv = exif_mem_alloc(parent_md->mem, strlen + 1); - if (!pv) return -1; - memset(pv, 0, strlen + 1); + pv = exif_mem_alloc(parent_md->mem, strlen + 1); + if (!pv) { + ret = -1; + goto FAILED; + } + *(pv+strlen) = 0; memcpy(pv, v, strlen); token = strtok(pv, " "); @@ -88,6 +100,7 @@ mnote_huawei_entry_set_value(MnoteHuaweiEntry *entry, char *v, int strlen) int offset = increment*components; if (increment == 1) { if (value > 0xff || value < 0) { + ret = -1; goto FAILED; } *(data+offset) = value; @@ -100,6 +113,7 @@ mnote_huawei_entry_set_value(MnoteHuaweiEntry *entry, char *v, int strlen) } if (!components || (entry->format != EXIF_FORMAT_UNDEFINED && components > 1)) { + ret = -1; goto FAILED; } @@ -107,6 +121,7 @@ mnote_huawei_entry_set_value(MnoteHuaweiEntry *entry, char *v, int strlen) unsigned char* realloc = NULL; realloc = exif_mem_realloc(parent_md->mem, entry->data, components_size); if (!realloc) { + ret = -1; goto FAILED; } entry->data = realloc; @@ -115,10 +130,8 @@ mnote_huawei_entry_set_value(MnoteHuaweiEntry *entry, char *v, int strlen) entry->components = components; entry->size = components_size; memcpy(entry->data, data, components_size); - exif_mem_free(parent_md->mem, pv); - return 0; FAILED: - exif_mem_free(parent_md->mem, pv); - return -1; + if (pv) exif_mem_free(parent_md->mem, pv); + return ret; } \ No newline at end of file diff --git a/libexif/huawei/mnote-huawei-entry.h b/libexif/huawei/mnote-huawei-entry.h index 1861dbd..e552948 100644 --- a/libexif/huawei/mnote-huawei-entry.h +++ b/libexif/huawei/mnote-huawei-entry.h @@ -21,7 +21,7 @@ #include typedef struct _MnoteHuaweiEntry MnoteHuaweiEntry; -typedef struct _ExifMnoteDataHuawei ExifMnoteDataHuawei; +typedef struct _ExifMnoteDataHuawei ExifMnoteDataHuawei; struct _MnoteHuaweiEntry { MnoteHuaweiTag tag; @@ -41,7 +41,7 @@ extern "C" { #endif /* __cplusplus */ char *mnote_huawei_entry_get_value (MnoteHuaweiEntry *entry, char *v, unsigned int maxlen); -int mnote_huawei_entry_set_value(MnoteHuaweiEntry *entry, char *v, int strlen); +int mnote_huawei_entry_set_value(MnoteHuaweiEntry *entry, const char *v, int strlen); #ifdef __cplusplus } diff --git a/libexif/huawei/mnote-huawei-tag.c b/libexif/huawei/mnote-huawei-tag.c index 14dac46..2f35c30 100644 --- a/libexif/huawei/mnote-huawei-tag.c +++ b/libexif/huawei/mnote-huawei-tag.c @@ -18,7 +18,7 @@ #include #include "mnote-huawei-tag.h" -typedef struct _MnoteHuaweiTable MnoteHuaweiTable; +typedef struct _MnoteHuaweiTable MnoteHuaweiTable; struct _MnoteHuaweiTable { MnoteHuaweiTag tag; @@ -76,23 +76,26 @@ static const MnoteHuaweiTable huawei_scene_table[] = { if (tb[i].tag == tag) {ret = tb[i].idx; return ret;}\ } \ ret = tb[tb_size-1].idx;\ - } while (0) + } while (0) + +const int HUAWEI_TABLE = 9; +const int HUAWEI_FACE_TABLE = 8; const MnoteHuaweiTable* get_tag_table(MnoteHuaweiTag tag, int* size) { - if (tag >> 9 & 1) { + if (tag >> HUAWEI_TABLE & 1) { *size = sizeof (huawei_table) / sizeof (huawei_table[0]); return huawei_table; } - if (tag >> 8 & 1) { + if (tag >> HUAWEI_FACE_TABLE & 1) { *size = sizeof (huawei_face_table) / sizeof (huawei_face_table[0]); return huawei_face_table; } *size = sizeof (huawei_scene_table) / sizeof (huawei_scene_table[0]); return huawei_scene_table; -} +} const char * mnote_huawei_tag_get_name (MnoteHuaweiTag tag) diff --git a/libexif/huawei/mnote-huawei-tag.h b/libexif/huawei/mnote-huawei-tag.h index b9b81ba..b31a205 100644 --- a/libexif/huawei/mnote-huawei-tag.h +++ b/libexif/huawei/mnote-huawei-tag.h @@ -68,7 +68,7 @@ typedef enum _MnoteHuaweiTagType MnoteHuaweiTagType; const char *mnote_huawei_tag_get_name (MnoteHuaweiTag); const char *mnote_huawei_tag_get_title (MnoteHuaweiTag); const char *mnote_huawei_tag_get_description (MnoteHuaweiTag); -MnoteHuaweiTagType mnote_huawei_tag_type (MnoteHuaweiTag); +MnoteHuaweiTagType mnote_huawei_tag_type (MnoteHuaweiTag); #ifdef __cplusplus } -- Gitee From 9b3ad9152b993f3dd44a9002ca46b515b8893f3d Mon Sep 17 00:00:00 2001 From: "zhubingwei@huawei.com" Date: Tue, 2 Apr 2024 15:52:28 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8DEXIF=5FTAG=5FSUBJECT=5FLO?= =?UTF-8?q?CATION=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhubingwei@huawei.com Change-Id: Ice091a1a70002ae218a4365438c7e1c1a017ee6d --- libexif/exif-entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexif/exif-entry.c b/libexif/exif-entry.c index cc4e686..b9e9ed1 100644 --- a/libexif/exif-entry.c +++ b/libexif/exif-entry.c @@ -1516,7 +1516,6 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag) break; /* SHORT, 1 component, no default */ - case EXIF_TAG_SUBJECT_LOCATION: case EXIF_TAG_SENSING_METHOD: case EXIF_TAG_PHOTOMETRIC_INTERPRETATION: case EXIF_TAG_COMPRESSION: @@ -1595,6 +1594,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag) break; /* SHORT, 2 components, default 0 0 */ + case EXIF_TAG_SUBJECT_LOCATION: case EXIF_TAG_SUBJECT_AREA: e->components = 2; e->format = EXIF_FORMAT_SHORT; -- Gitee From 8f1f48b0fcd709e12ca5f5c8a035c43052d9d66e Mon Sep 17 00:00:00 2001 From: "zhubingwei@huawei.com" Date: Wed, 3 Apr 2024 16:42:20 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=90=8C=E5=90=8DCFAPatt?= =?UTF-8?q?ern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhubingwei@huawei.com Change-Id: I8770943ba24a74546f20d5684ab06ae36f6ffc98 --- libexif/exif-tag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexif/exif-tag.c b/libexif/exif-tag.c index a3edb40..066ef8a 100644 --- a/libexif/exif-tag.c +++ b/libexif/exif-tag.c @@ -446,7 +446,7 @@ static const struct TagEntry { {EXIF_TAG_CFA_REPEAT_PATTERN_DIM, "CFARepeatPatternDim", "CFARepeatPatternDim", "", ESL_UNKNOWN}, /* Not in EXIF 2.2 */ - {EXIF_TAG_CFA_PATTERN, "CFAPattern", + {EXIF_TAG_CFA_PATTERN, "CFAPattern2", N_("CFA Pattern"), N_("Indicates the color filter array (CFA) geometric pattern of the " "image sensor when a one-chip color area sensor is used. " -- Gitee