diff --git a/BUILD.gn b/BUILD.gn index 087c7c6..0261ed4 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -92,11 +92,16 @@ if (defined(ohos_lite)) { # is on lite Os for ipcamera ohos_source_set("exif_static") { subsystem_name = "thirdparty" part_name = "libexif" - - if (is_arkui_x) { # Arkui_x not sopported external_deps - deps = [ "//third_party/bounds_checking_function:libsec_static" ] + # arkui-x not supported external_deps + if (is_arkui_x) { + deps = [ + "//third_party/bounds_checking_function:libsec_static", + "//vendor/huawei/base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog"] } else { - external_deps = [ "bounds_checking_function:libsec_shared" ] + external_deps = [ + "bounds_checking_function:libsec_shared", + "hilog:libhilog" + ] } branch_protector_ret = "pac_ret" sources = [ @@ -153,9 +158,14 @@ if (defined(ohos_lite)) { # is on lite Os for ipcamera branch_protector_ret = "pac_ret" deps = [ ":exif_static" ] if (is_arkui_x) { - deps += [ "//third_party/bounds_checking_function:libsec_static" ] + deps += [ + "//third_party/bounds_checking_function:libsec_static", + "//vendor/huawei/base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog"] } else { - external_deps = [ "bounds_checking_function:libsec_shared" ] + external_deps = [ + "bounds_checking_function:libsec_shared", + "hilog:libhilog" + ] } public_configs = [ ":build_public_config" ] install_images = [ system_base_dir ] @@ -163,4 +173,4 @@ if (defined(ohos_lite)) { # is on lite Os for ipcamera innerapi_tags = [ "chipsetsdk" ] part_name = "libexif" } -} +} \ No newline at end of file diff --git a/OAT.xml b/OAT.xml index b15c05d..56c678c 100644 --- a/OAT.xml +++ b/OAT.xml @@ -62,12 +62,16 @@ + + + + diff --git a/bundle.json b/bundle.json index 4bd474e..bdcf816 100644 --- a/bundle.json +++ b/bundle.json @@ -22,7 +22,10 @@ "rom": "196KB", "ram": "392KB", "deps": { - "components": [ "bounds_checking_function" ], + "components": [ + "bounds_checking_function", + "hilog" + ], "third_party": [] }, "build": { diff --git a/libexif/exif-entry.c b/libexif/exif-entry.c index 830e87c..40a379f 100644 --- a/libexif/exif-entry.c +++ b/libexif/exif-entry.c @@ -1158,8 +1158,7 @@ exif_entry_get_value (ExifEntry *e, char *val, unsigned int maxlen) } else { snprintf (val, maxlen, _("1/%.0f"), 1. / d); } - } - else { + } else { if (min_denominator == 1) { snprintf (val, maxlen, "%.0f", d); } else { diff --git a/libexif/huawei/exif-mnote-data-huawei.c b/libexif/huawei/exif-mnote-data-huawei.c index 9651b23..4c32a6f 100644 --- a/libexif/huawei/exif-mnote-data-huawei.c +++ b/libexif/huawei/exif-mnote-data-huawei.c @@ -26,8 +26,8 @@ #include #include -#define CHECKOVERFLOW(offset,datasize,structsize) (( offset >= datasize) || (structsize > datasize) || \ - (offset > datasize - structsize )) +#define CHECKOVERFLOW(offset, datasize, structsize) \ + (((offset) >= (datasize)) || ((structsize) > (datasize)) || ((offset) > (datasize) - (structsize))) const int DATA_OR_OFFSET = 4; const int HUAWEI_HEADER_OFFSET = 8; @@ -95,7 +95,9 @@ 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) { - if (!ne) return; + if (!ne) { + return; + } ExifMnoteDataHuawei *n = (ExifMnoteDataHuawei *) ne; if (!n) { exif_log (ne->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifMnoteHuawei", "n is NULL"); @@ -208,7 +210,7 @@ exif_mnote_data_huawei_save (ExifMnoteData *ne, unsigned char **buf, unsigned in unsigned int malloc_size = sizeof(HUAWEI_HEADER); exif_mnote_data_huawei_malloc_size_data(ne, &malloc_size); - if (malloc_size < 8) { + if (!malloc_size) { exif_log (ne->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifMnoteHuawei", "The memory(%d) request failed", malloc_size); return; } @@ -295,7 +297,7 @@ exif_mnote_data_huawei_load_data (ExifMnoteData *ne, const unsigned char *buf, u if (CHECKOVERFLOW(t_offset, buf_size, components_size)) { exif_log (ne->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifMnoteDataHuawei", "Tag data past end of buffer"); - continue; + continue; } entries[tcount].data = exif_mem_alloc (ne->mem, components_size); if (!entries[tcount].data) { @@ -305,18 +307,18 @@ exif_mnote_data_huawei_load_data (ExifMnoteData *ne, const unsigned char *buf, u unsigned int t_size = 0; if (components_size > 4) { - t_size = order_offset + t_offset - HUAWEI_HEADER_OFFSET + components_size; + t_size = order_offset + t_offset - HUAWEI_HEADER_OFFSET; if (CHECKOVERFLOW(t_size, buf_size, components_size)) { exif_log (ne->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifMnoteDataHuawei", "Tag data past end of buffer"); - continue; + continue; } memcpy (entries[tcount].data, buf + order_offset + t_offset - HUAWEI_HEADER_OFFSET, components_size); } else { if (CHECKOVERFLOW(ifd_data - buf + t_offset, buf_size, components_size)) { exif_log (ne->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifMnoteDataHuawei", "Tag data past end of buffer"); - continue; + continue; } memcpy (entries[tcount].data, ifd_data + t_offset, components_size); } @@ -367,7 +369,9 @@ exif_mnote_data_huawei_load_data (ExifMnoteData *ne, const unsigned char *buf, u static void exif_mnote_data_huawei_load (ExifMnoteData *ne, const unsigned char *buf, unsigned int buf_size) { - if (!ne) return; + if (!ne) { + return; + } unsigned int head_offset = 6; ExifMnoteDataHuawei *n = (ExifMnoteDataHuawei *) ne; if (!n || !buf || !buf_size) { diff --git a/libexif/huawei/mnote-huawei-entry.c b/libexif/huawei/mnote-huawei-entry.c index 7aa0f80..b93e525 100644 --- a/libexif/huawei/mnote-huawei-entry.c +++ b/libexif/huawei/mnote-huawei-entry.c @@ -17,6 +17,7 @@ #include "exif-mnote-data-huawei.h" #include "mnote-huawei-entry.h" #include "mnote-huawei-tag.h" +#include "hilog/log.h" #include #include @@ -29,14 +30,22 @@ #include #include +#undef LOG_DOMAIN +#define LOG_DOMAIN 0xD002B60 +#undef LOG_TAG +#define LOG_TAG "mnote-huawei-entry" + #define DATA_LENGTH 1024 #define BLANK_SIZE 1 +#define NEGATIVE_SIGN_SIZE 1 #define PARSE_BASE_DECIMAL 10 #define TIMESTAMP_LENGTH 10 -#define TIMESTAMP_YEAR_MONTH_DAY 8 +#define THREE_COMPONENTS 3 +#define SHORT_INCREMENT 2 /* Get length of number for value in unsigned integer */ -uint32_t get_unsigned_int_length(uint32_t value) { +uint32_t get_unsigned_int_length(uint32_t value) +{ if (value == 0) { return 1; } @@ -44,13 +53,14 @@ uint32_t get_unsigned_int_length(uint32_t value) { } /* Get length of number for value in signed integer */ -uint32_t get_signed_int_length(int32_t value) { +uint32_t get_signed_int_length(int32_t value) +{ if (value == 0) { return 1; } /* If the number is negative, include the '-' sign in the length */ - return (uint32_t)log10(abs(value)) + (value < 0 ? 2 : 1); + return (uint32_t)log10(abs(value)) + (value < 0 ? 1 + NEGATIVE_SIGN_SIZE : 1); } /* Get length of number for value in unsigned char */ @@ -61,6 +71,144 @@ uint32_t get_unsigned_char_length(uint32_t value) { return (uint32_t)log10(value) + 1; } +/* Get components from exif */ +char * +format_exif_components(MnoteHuaweiEntry *e, char *v, unsigned int maxlen, unsigned int write_pos) +{ + for (unsigned long i = 0; i < e->components && write_pos < maxlen; i++) { + int returnSize; + if (e->format == EXIF_FORMAT_UNDEFINED) { + ExifLong data = 0; + data = (e->data + i)[0]; + if ((get_unsigned_int_length(data) + BLANK_SIZE) > (maxlen - write_pos)) { + return NULL; + } + returnSize = snprintf_s(v + write_pos, maxlen - write_pos, + maxlen - write_pos, "%u ", data); + } else if (e->format == EXIF_FORMAT_SLONG) { + ExifSLong data = 0; + data = exif_get_slong(e->data + i * sizeof(ExifSLong), e->order); + if ((get_signed_int_length(data) + BLANK_SIZE) > (maxlen - write_pos)) { + return NULL; + } + returnSize = snprintf_s(v + write_pos, maxlen - write_pos, + maxlen - write_pos, "%d ", data); + } else if (e->format == EXIF_FORMAT_LONG) { + ExifLong data = 0; + data = exif_get_long(e->data + i * sizeof(ExifLong), e->order); + if ((get_unsigned_int_length(data) + BLANK_SIZE) > (maxlen - write_pos)) { + return NULL; + } + returnSize = snprintf_s(v + write_pos, maxlen - write_pos, + maxlen - write_pos, "%u ", data); + } else if (e->format == EXIF_FORMAT_SSHORT) { + ExifSShort data = 0; + data = exif_get_sshort(e->data + i * sizeof(ExifSShort), e->order); + if ((get_signed_int_length(data) + BLANK_SIZE) > (maxlen - write_pos)) { + return NULL; + } + returnSize = snprintf_s(v + write_pos, maxlen - write_pos, + maxlen - write_pos, "%d ", data); + } else if (e->format == EXIF_FORMAT_BYTE) { + ExifByte data = 0; + data = e->data[i]; + if ((get_unsigned_char_length(data) + BLANK_SIZE) > (maxlen - write_pos)) { + return NULL; + } + returnSize = snprintf_s(v + write_pos, maxlen - write_pos, + maxlen - write_pos, "%d ", data); + } else { + snprintf_s(v, maxlen, maxlen, _("unsupported data types: %d"), e->format); + return NULL; + } + + if (returnSize < 0) { + HILOG_INFO(LOG_CORE, "Do %{public}s snprintf_s fail", __func__); + return NULL; + } + write_pos += (unsigned int)returnSize; + } + + *(v + write_pos - 1) = 0; + return v; +} + +/* To process video timestamp in mnote_huawei_entry_get_value function */ +char *handle_video_timestamp(MnoteHuaweiEntry *e, char *v, unsigned int maxlen, unsigned int *write_pos) +{ + for (unsigned long i = 0; i < e->components && *write_pos < maxlen; i++) { + unsigned long offset = i * exif_format_get_size(e->format); + ExifRational r = exif_get_rational(e->data + offset, e->order); + int returnSize; + if (r.denominator == 0) { + returnSize = snprintf_s(v + *write_pos, maxlen - *write_pos, + maxlen - *write_pos, "%u ", r.numerator); + } else { + returnSize = snprintf_s(v + *write_pos, maxlen - *write_pos, + maxlen - *write_pos, "%u%u ", r.numerator, r.denominator); + } + if (returnSize < 0) { + return NULL; + } + *write_pos += (unsigned long)returnSize; + } + *(v + *write_pos - 1) = 0; + return v; +} + +/* To process xtstyle in mnote_huawei_entry_get_value function */ +char *handle_xtstyle(MnoteHuaweiEntry *e, char *v, unsigned int maxlen, unsigned int *write_pos) +{ + for (unsigned long i = 0; i < e->components && *write_pos < maxlen; i++) { + unsigned long offset = i * exif_format_get_size(e->format); + ExifRational r = exif_get_rational(e->data + offset, e->order); + int returnSize; + if (r.denominator != 0) { + returnSize = snprintf_s(v + *write_pos, maxlen - *write_pos, + maxlen - *write_pos, "%.3f", (double) r.numerator / (double) r.denominator); + } else { + returnSize = snprintf_s(v + *write_pos, maxlen - *write_pos, + maxlen - *write_pos, "%u ", r.numerator); + } + if (returnSize < 0) { + return NULL; + } + *write_pos += (unsigned long)returnSize; + } + *(v + *write_pos - 1) = 0; + return v; +} + +/* To process stars information in mnote_huawei_entry_get_value function */ +char *handle_stars_info(MnoteHuaweiEntry *e, char *v, unsigned int maxlen, unsigned int *write_pos) +{ + for (unsigned long i = 0; i < e->components && *write_pos < maxlen; i++) { + unsigned long offset = i * exif_format_get_size(e->format); + ExifSLong slong_data = exif_get_slong(e->data + offset, e->order); + int returnSize; + returnSize = snprintf_s(v + *write_pos, maxlen - *write_pos, + maxlen - *write_pos, "%d ", slong_data); + if (returnSize < 0) { + return NULL; + } + *write_pos += (unsigned long)returnSize; + } + *(v + *write_pos - 1) = 0; + return v; +} + +/* To judge if it is xtstyle */ +bool is_xtstyle(MnoteHuaweiEntry *e) +{ + if ((e->tag == MNOTE_HUAWEI_XTSTYLE_CUSTOM_LIGHT_SHADOW || + e->tag == MNOTE_HUAWEI_XTSTYLE_CUSTOM_SATURATION || + e->tag == MNOTE_HUAWEI_XTSTYLE_CUSTOM_HUE) && + e->format == EXIF_FORMAT_RATIONAL) { + return true; + } + return false; +} + char * mnote_huawei_entry_get_value(MnoteHuaweiEntry *e, char *v, unsigned int maxlen) { @@ -69,95 +217,44 @@ mnote_huawei_entry_get_value(MnoteHuaweiEntry *e, char *v, unsigned int maxlen) memset(v, 0, maxlen); unsigned int write_pos = 0; - if (e->data == NULL) { + if (e == NULL || e->data == NULL) { return NULL; } if (e->format == EXIF_FORMAT_ASCII) { - int returnSize = snprintf_s(v, maxlen, maxlen, _("%.*s"), e->size, e->data); - if (returnSize < 0) { + if (snprintf_s(v, maxlen, maxlen, _("%.*s"), e->size, e->data) < 0) { return NULL; } return v; } if (e->tag == MNOTE_MICRO_VIDEO_PRESENTATION_TIMESTAMP_US) { - for (unsigned long i = 0; i < e->components && write_pos < maxlen; i++) { - unsigned long offset = i * exif_format_get_size(e->format); - ExifRational r = exif_get_rational(e->data + offset, e->order); - if (r.denominator == 0) { - int returnSize = snprintf_s(v + write_pos, maxlen - write_pos, - maxlen - write_pos, "%u ", r.numerator); - if (returnSize < 0) { - return NULL; - } - write_pos += (unsigned int)returnSize; - } else { - int returnSize = snprintf_s(v + write_pos, maxlen - write_pos, - maxlen - write_pos, "%u%u ", r.numerator, r.denominator); - if (returnSize < 0) { - return NULL; - } - write_pos += (unsigned int)returnSize; - } - } - *(v + write_pos - 1) = 0; - return v; + return handle_video_timestamp(e, v, maxlen, &write_pos); } - for (unsigned long i = 0; i < e->components && write_pos < maxlen; i++) { - if (e->format == EXIF_FORMAT_UNDEFINED) { - ExifLong data = 0; - data = (e->data + i)[0]; - if ((get_unsigned_int_length(data) + BLANK_SIZE) > (maxlen - write_pos)) { - return NULL; - } - int returnSize = snprintf(v + write_pos, maxlen - write_pos, "%u ", data); - if (returnSize < 0) { - return NULL; - } - write_pos += (unsigned int)returnSize; - } else if (e->format == EXIF_FORMAT_SLONG) { - ExifSLong data = 0; - data = exif_get_slong(e->data + i * sizeof(ExifSLong), e->order); - if ((get_signed_int_length(data) + BLANK_SIZE) > (maxlen - write_pos)) { - return NULL; - } - int returnSize = snprintf(v + write_pos, maxlen - write_pos, "%d ", data); - if (returnSize < 0) { - return NULL; - } - write_pos += (unsigned int)returnSize; - } else if (e->format == EXIF_FORMAT_LONG) { - ExifLong data = 0; - data = exif_get_long(e->data + i * sizeof(ExifLong), e->order); - if ((get_unsigned_int_length(data) + BLANK_SIZE) > (maxlen - write_pos)) { - return NULL; - } - int returnSize = snprintf(v + write_pos, maxlen - write_pos, "%u ", data); - if (returnSize < 0) { - return NULL; - } - write_pos += (unsigned int)returnSize; - } else if (e->format == EXIF_FORMAT_BYTE) { - ExifByte data = 0; - data = e->data[i]; - if ((get_unsigned_char_length(data) + BLANK_SIZE) > (maxlen - write_pos)) { - return NULL; - } - int returnSize = snprintf(v + write_pos, maxlen - write_pos, "%d ", data); - if (returnSize < 0) { - return NULL; - } - write_pos += (unsigned int)returnSize; - } else { - snprintf(v, maxlen, _("unsupported data types: %d"), e->format); - return NULL; - } + if (is_xtstyle(e)) { + return handle_xtstyle(e, v, maxlen, &write_pos); } - *(v + write_pos - 1) = 0; - return v; + if (e->tag == MNOTE_HUAWEI_STARS_INFO) { + return handle_stars_info(e, v, maxlen, &write_pos); + } + + return format_exif_components(e, v, maxlen, write_pos); +} + +static int parse_rational_timestamp(const char *input, char *buffer, size_t buffer_size, unsigned long *result) +{ + if (snprintf_s(buffer, buffer_size, buffer_size, "%s", input) < 0) { + return -1; + } + errno = 0; + unsigned long value = strtoul(buffer, NULL, PARSE_BASE_DECIMAL); + if (errno == ERANGE && value == ULONG_MAX) { + return -1; + } + *result = value; + return 0; } int @@ -180,32 +277,97 @@ mnote_huawei_entry_rational_timestamp_process(char *buff, const int buff_size, c for (; timestamp_char && components_size < buff_size;) { int offset = increment * components_local; char timestamp_buff[11] = {0}; - int returnSize = snprintf_s(timestamp_buff, sizeof(timestamp_buff), - sizeof(timestamp_buff), "%s", timestamp_char); - if (returnSize < 0) { + unsigned long numerator = 0; + if (parse_rational_timestamp(timestamp_char, timestamp_buff, sizeof(timestamp_buff), &numerator) < 0) { ret = -1; goto FINISH; } - errno = 0; - unsigned long numerator = strtoul(timestamp_buff, NULL, PARSE_BASE_DECIMAL); - if (errno == ERANGE && numerator == ULONG_MAX) { + unsigned long denominator = 0; + if (parse_rational_timestamp(timestamp_char + TIMESTAMP_LENGTH, + timestamp_buff, sizeof(timestamp_buff), &denominator) < 0) { ret = -1; goto FINISH; } - returnSize = snprintf_s(timestamp_buff, TIMESTAMP_YEAR_MONTH_DAY, - TIMESTAMP_YEAR_MONTH_DAY, "%s", timestamp_char + TIMESTAMP_LENGTH); - if (returnSize < 0) { - ret = -1; - goto FINISH; - } - errno = 0; - unsigned long denominator = strtoul(timestamp_buff, NULL, PARSE_BASE_DECIMAL); - if (errno == ERANGE && denominator == ULONG_MAX) { - ret = -1; - goto FINISH; + ExifRational r = { + .numerator = numerator, + .denominator = denominator, + }; + + exif_set_rational((unsigned char*)buff + offset, order, r); + components_local++; + components_size = components_local * increment; + timestamp_char = strtok(NULL, " "); + } + +FINISH: + *components = components_local; + if (!components_local) { + ret = -1; + } + if (pv) + exif_mem_free(mem, pv); + return ret; +} + +int +mnote_huawei_entry_rational_process(char *buff, const int buff_size, const char *v, int strlen, + int *components, ExifMem *mem, ExifByteOrder order) +{ + char *timestamp_char = NULL, *pv = NULL; + int components_local = 0, components_size = 0, ret = 0; + const int increment = 8; + + pv = exif_mem_alloc(mem, strlen + 1); + if (!pv) { + ret = -1; + goto FINISH; + } + *(pv + strlen) = 0; + if (EOK != memcpy_s(pv, strlen + 1, v, strlen)) { + HILOG_INFO(LOG_CORE, + "memcpy failed at %{public}s, strlen:%{public}d, strlen:%{public}s", __func__, strlen, v); + ret = -1; + goto FINISH; + } + + timestamp_char = strtok(pv, " "); + for (; timestamp_char && components_size < buff_size;) { + int offset = increment * components_local; + char numerator_str[11] = {0}; + char denominator_str[11] = {0}; + char *slash_pos = strchr(timestamp_char, '/'); + unsigned long numerator = 0; + unsigned long denominator = 0; + if (slash_pos) { + size_t numerator_len = slash_pos - timestamp_char; + if (snprintf_s(numerator_str, sizeof(numerator_str), + sizeof(numerator_str), "%.*s", numerator_len, timestamp_char) < 0) { + ret = -1; + goto FINISH; + } + numerator = strtoul(numerator_str, NULL, PARSE_BASE_DECIMAL); + + if (snprintf_s(denominator_str, sizeof(denominator_str), + sizeof(denominator_str), "%s", slash_pos + 1) < 0) { + ret = -1; + goto FINISH; + } + denominator = strtoul(denominator_str, NULL, PARSE_BASE_DECIMAL); + } else { + if (snprintf_s(numerator_str, sizeof(numerator_str), + sizeof(numerator_str), "%s", timestamp_char) < 0) { + ret = -1; + goto FINISH; + } + numerator = strtoul(numerator_str, NULL, PARSE_BASE_DECIMAL); + denominator = 1; } + if (denominator == 0) { + ret = -1; + goto FINISH; + } ExifRational r = { .numerator = numerator, .denominator = denominator, @@ -254,7 +416,12 @@ mnote_huawei_entry_value_process(char *buff, const int buff_size, const char *v, goto FINISH; } *(pv + strlen) = 0; - memcpy_s(pv, strlen + 1, v, strlen); + if (EOK != memcpy_s(pv, strlen + 1, v, strlen)) { + HILOG_INFO(LOG_CORE, + "memcpy failed at %{public}s, strlen:%{public}d, strlen:%{public}s", __func__, strlen, v); + ret = -1; + goto FINISH; + } token = strtok(pv, " "); for (; token && components_size < buff_size;) { @@ -266,6 +433,8 @@ mnote_huawei_entry_value_process(char *buff, const int buff_size, const char *v, goto FINISH; } *(buff + offset) = value; + } else if (increment == SHORT_INCREMENT) { + exif_set_sshort((unsigned char*)(buff + offset), order, value); } else { exif_set_slong((unsigned char*)(buff + offset), order, value); } @@ -298,6 +467,8 @@ mnote_huawei_entry_set_value(MnoteHuaweiEntry *e, const char *v, int strlen) if (e->format == EXIF_FORMAT_UNDEFINED || e->format == EXIF_FORMAT_ASCII || e->format == EXIF_FORMAT_BYTE) { increment = 1; + } else if (e->format == EXIF_FORMAT_SHORT || e->format == EXIF_FORMAT_SSHORT) { + increment = SHORT_INCREMENT; } else if (e->format == EXIF_FORMAT_SLONG || e->format == EXIF_FORMAT_LONG) { increment = 4; } else if (e->format == EXIF_FORMAT_RATIONAL || e->format == EXIF_FORMAT_SRATIONAL) { @@ -312,6 +483,9 @@ mnote_huawei_entry_set_value(MnoteHuaweiEntry *e, const char *v, int strlen) &components, e->mem, e->order); } else if (e->format == EXIF_FORMAT_ASCII) { ret = mnote_huawei_entry_string_process(data, sizeof(data), v, strlen, &components); + } else if (e->format == EXIF_FORMAT_RATIONAL) { + ret = mnote_huawei_entry_rational_process(data, sizeof(data), v, strlen, + &components, e->mem, e->order); } else { ret = mnote_huawei_entry_value_process(data, sizeof(data), v, strlen, increment, &components, e->mem, e->order); @@ -416,94 +590,97 @@ static const unsigned int VIDEO_TIMESTAMP_COMPONENTS = 8; /* Base information about Huawei tags */ static const HuaweiTagInitInfo huawei_tag_init_table[] = { - { MNOTE_HUAWEI_SCENE_INFO, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_FACE_INFO, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_CAPTURE_MODE, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_BURST_NUMBER, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_FRONT_CAMERA, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_PHYSICAL_APERTURE, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_MOVING_PHOTO_VERSION, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_FACE_VERSION, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_FACE_COUNT, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_FACE_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_SCENE_VERSION, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_SCENE_FOOD_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_SCENE_STAGE_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_SCENE_BLUESKY_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_SCENE_GREENPLANT_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_SCENE_BEACH_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_SCENE_SNOW_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_SCENE_SUNSET_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_SCENE_FLOWERS_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_SCENE_NIGHT_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_SCENE_TEXT_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_INFO, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_FACE_INFO, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_CAPTURE_MODE, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_BURST_NUMBER, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_FRONT_CAMERA, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_PHYSICAL_APERTURE, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_MOVING_PHOTO_VERSION, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_FACE_VERSION, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_FACE_COUNT, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_FACE_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_VERSION, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_FOOD_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_STAGE_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_BLUESKY_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_GREENPLANT_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_BEACH_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_SNOW_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_SUNSET_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_FLOWERS_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_NIGHT_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_SCENE_TEXT_CONF, EXIF_FORMAT_LONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_ROLL_ANGLE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_PITCH_ANGLE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_FOCUS_MODE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_IS_XMAGE_SUPPORTED, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_XMAGE_MODE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_XMAGE_LEFT, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_XMAGE_TOP, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_XMAGE_RIGHT, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_XMAGE_BOTTOM, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_CLOUD_ENHANCEMENT_MODE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_WIND_SNAPSHOT_MODE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_HUAWEI_AI_EDIT, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_ROLL_ANGLE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_PITCH_ANGLE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_FOCUS_MODE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_IS_XMAGE_SUPPORTED, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_XMAGE_MODE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_XMAGE_LEFT, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_XMAGE_TOP, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_XMAGE_RIGHT, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_XMAGE_BOTTOM, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_CLOUD_ENHANCEMENT_MODE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_WIND_SNAPSHOT_MODE, EXIF_FORMAT_SLONG, 1, NULL, 0 }, + { MNOTE_HUAWEI_AI_EDIT, EXIF_FORMAT_SLONG, 1, NULL, 0 }, - { MNOTE_MOVING_PHOTO_ID, EXIF_FORMAT_ASCII, sizeof("[None]"), "[None]", 0 }, - - { MNOTE_MICRO_VIDEO_PRESENTATION_TIMESTAMP_US, + { MNOTE_MOVING_PHOTO_ID, EXIF_FORMAT_ASCII, sizeof("[None]"), "[None]", 0 }, + { MNOTE_MICRO_VIDEO_PRESENTATION_TIMESTAMP_US, EXIF_FORMAT_RATIONAL, VIDEO_TIMESTAMP_COMPONENTS, NULL, 1 }, - { MNOTE_HUAWEI_FACE_SMILE_SCORE, EXIF_FORMAT_UNDEFINED, 1, NULL, 0 }, - { MNOTE_HUAWEI_FACE_RECT, EXIF_FORMAT_UNDEFINED, 1, NULL, 0 }, - { MNOTE_HUAWEI_FACE_LEYE_CENTER, EXIF_FORMAT_UNDEFINED, 1, NULL, 0 }, - { MNOTE_HUAWEI_FACE_REYE_CENTER, EXIF_FORMAT_UNDEFINED, 1, NULL, 0 }, - { MNOTE_HUAWEI_FACE_MOUTH_CENTER, EXIF_FORMAT_UNDEFINED, 1, NULL, 0 }, + { MNOTE_HUAWEI_FACE_SMILE_SCORE, EXIF_FORMAT_UNDEFINED, 1, NULL, 0 }, + { MNOTE_HUAWEI_FACE_RECT, EXIF_FORMAT_UNDEFINED, 1, NULL, 0 }, + { MNOTE_HUAWEI_FACE_LEYE_CENTER, EXIF_FORMAT_UNDEFINED, 1, NULL, 0 }, + { MNOTE_HUAWEI_FACE_REYE_CENTER, EXIF_FORMAT_UNDEFINED, 1, NULL, 0 }, + { MNOTE_HUAWEI_FACE_MOUTH_CENTER, EXIF_FORMAT_UNDEFINED, 1, NULL, 0 }, + { MNOTE_HUAWEI_XTSTYLE_TEMPLATE_NAME, EXIF_FORMAT_SSHORT, 1, NULL, 0 }, + { MNOTE_HUAWEI_XTSTYLE_CUSTOM_LIGHT_SHADOW, EXIF_FORMAT_RATIONAL, 1, NULL, 1 }, + { MNOTE_HUAWEI_XTSTYLE_CUSTOM_SATURATION, EXIF_FORMAT_RATIONAL, 1, NULL, 1 }, + { MNOTE_HUAWEI_XTSTYLE_CUSTOM_HUE, EXIF_FORMAT_RATIONAL, 1, NULL, 1 }, + { MNOTE_HUAWEI_XTSTYLE_EXPOSUREPARAM_PARAM, EXIF_FORMAT_SSHORT, THREE_COMPONENTS, NULL, 0 }, + { MNOTE_HUAWEI_STARS_INFO, EXIF_FORMAT_SLONG, 1, NULL, 0 } }; - void mnote_huawei_entry_initialize(MnoteHuaweiEntry *e, MnoteHuaweiTag tag, ExifByteOrder order) { - if (!e || e->data) - return; + if (!e || e->data) + return; - e->tag = tag; - e->order = order; + e->tag = tag; + e->order = order; - const HuaweiTagInitInfo *info = NULL; - for (size_t i = 0; i < sizeof(huawei_tag_init_table) / sizeof(huawei_tag_init_table[0]); ++i) { - if (huawei_tag_init_table[i].tag == tag) { - info = &huawei_tag_init_table[i]; - break; - } - } + const HuaweiTagInitInfo *info = NULL; + for (size_t i = 0; i < sizeof(huawei_tag_init_table) / sizeof(huawei_tag_init_table[0]); ++i) { + if (huawei_tag_init_table[i].tag == tag) { + info = &huawei_tag_init_table[i]; + break; + } + } - if (info) { - e->components = info->components; - e->format = info->format; - e->size = e->components * exif_format_get_size(e->format); - e->data = mnote_huawei_entry_alloc(e, e->size); - if (!e->data) { - clear_mnote_huawei_entry(e); - return; - } + if (info) { + e->components = info->components; + e->format = info->format; + e->size = e->components * exif_format_get_size(e->format); + e->data = mnote_huawei_entry_alloc(e, e->size); + if (!e->data) { + clear_mnote_huawei_entry(e); + return; + } - if (info->default_ascii) { - if (snprintf_s((char *)e->data, e->size, e->components, "%s", info->default_ascii)) { - clear_mnote_huawei_entry(e); - return; - } - } + if (info->default_ascii) { + if (snprintf_s((char *)e->data, e->size, e->components, "%s", info->default_ascii)) { + clear_mnote_huawei_entry(e); + return; + } + } - if (info->zero_initialize) { - memset(e->data, 0, e->size); - } - - } else { - e->components = 0; - e->format = EXIF_FORMAT_UNDEFINED; - e->size = 0; - e->data = NULL; - } + if (info->zero_initialize) { + memset(e->data, 0, e->size); + } + } else { + e->components = 0; + e->format = EXIF_FORMAT_UNDEFINED; + e->size = 0; + e->data = NULL; + } } \ No newline at end of file diff --git a/libexif/huawei/mnote-huawei-entry.h b/libexif/huawei/mnote-huawei-entry.h index 1511436..28a25df 100644 --- a/libexif/huawei/mnote-huawei-entry.h +++ b/libexif/huawei/mnote-huawei-entry.h @@ -38,37 +38,38 @@ struct _MnoteHuaweiEntry { }; /* - * This structure is used to store the initialization information for each tag. - * It is used to initialize the tag when the tag is created. + * This struct is used to store MnoteHuaweiTag and their associated initialization information. + * It defines the data format, component count, default values, and other initialization options for each tag. */ typedef struct { - /* - * Huawei custom tag type - */ - MnoteHuaweiTag tag; - - /* - * Exif format type - */ - ExifFormat format; - - /* - * Number of components - * For example, the number of components for the tag MNOTE_HUAWEI_SCENE_INFO is 1. - */ - unsigned int components; - - /* - * Default ASCII value - * For example, the default ASCII value for the tag MNOTE_HUAWEI_SCENE_INFO is "[None]". - */ - const char *default_ascii; - - /* - * Number of rational components - * false is 0, true is 1 - */ - int zero_initialize; + /* + * Huawei custom Exif tag type, representing specific metadata items. + */ + MnoteHuaweiTag tag; + + /* + * Exif data format, defining the data type of the tag, such as long integer or rational number. + */ + ExifFormat format; + + /* + * Number of components in the data, indicating how many basic units the data consists of. + * For example, MNOTE_HUAWEI_XTSTYLE_EXPOSUREPARAM_PARAM have three components. + */ + unsigned int components; + + /* + * Default ASCII string value for the tag, applicable only to ASCII format tags. + * If NULL, it indicates no default value. + */ + const char *default_ascii; + + /* + * Indicates whether to zero-initialize the data during initialization. + * If true, the data area will be set to zero after memory allocation. + * false is 0, true is 1. + */ + int zero_initialize; } HuaweiTagInitInfo; #ifdef __cplusplus diff --git a/libexif/huawei/mnote-huawei-tag.c b/libexif/huawei/mnote-huawei-tag.c index 77aa4f9..1c3512b 100644 --- a/libexif/huawei/mnote-huawei-tag.c +++ b/libexif/huawei/mnote-huawei-tag.c @@ -42,7 +42,8 @@ static const MnoteHuaweiTable huawei_table[] = { {MNOTE_HUAWEI_XMAGE_TOP, "HwMnoteXmageTop", N_("Xmage Top"), "XmageTop"}, {MNOTE_HUAWEI_XMAGE_RIGHT, "HwMnoteXmageRight", N_("Xmage Right"), "XmageRight"}, {MNOTE_HUAWEI_XMAGE_BOTTOM, "HwMnoteXmageBottom", N_("Xmage Bottom"), "XmageBottom"}, - {MNOTE_HUAWEI_CLOUD_ENHANCEMENT_MODE, "HwMnoteCloudEnhancementMode", N_("Cloud Enhancement Mode"), "CloudEnhancementMode"}, + {MNOTE_HUAWEI_CLOUD_ENHANCEMENT_MODE, "HwMnoteCloudEnhancementMode", + N_("Cloud Enhancement Mode"), "CloudEnhancementMode"}, {MNOTE_HUAWEI_FOCUS_MODE, "HwMnoteFocusMode", N_("Focus Mode"), "FocusMode"}, {MNOTE_HUAWEI_WIND_SNAPSHOT_MODE, "HwMnoteWindSnapshotMode", N_("Wind Snapshot Mode"), "WindSnapshotMode"}, {MNOTE_MOVING_PHOTO_VERSION, "MovingPhotoVersion", N_("Moving Photo Version"), @@ -51,7 +52,19 @@ static const MnoteHuaweiTable huawei_table[] = { N_("Video Presentation Timestamp US"), "VideoPresentationTimestampUS"}, {MNOTE_MOVING_PHOTO_ID, "MovingPhotoId", N_("Moving Photo Id"), "MovingPhotoId"}, {MNOTE_HUAWEI_AI_EDIT, "HwMnoteAiEdit", N_("AI Edit"), "AiEdit"}, - + {MNOTE_HUAWEI_XTSTYLE_TEMPLATE_NAME, "HwMnoteXtStyleTemplateName", + N_("XtStyle Template Name"), "XtStyleTemplateName"}, + {MNOTE_HUAWEI_XTSTYLE_CUSTOM_LIGHT_SHADOW, "HwMnoteXtStyleCustomLightAndShadow", + N_("XtStyle Custom Light And Shadow"), "XtStyleCustomLightAndShadow"}, + {MNOTE_HUAWEI_XTSTYLE_CUSTOM_SATURATION, "HwMnoteXtStyleCustomSaturation", + N_("XtStyle Custom Saturation"), "XtStyleCustomSaturation"}, + {MNOTE_HUAWEI_XTSTYLE_CUSTOM_HUE, "HwMnoteXtStyleCustomHue", + N_("XtStyle Custom Hue"), "XtStyleCustomHue"}, + {MNOTE_HUAWEI_XTSTYLE_EXPOSUREPARAM_PARAM, "HwMnoteXtStyleExposureParam", + N_("XtStyle Exposure Param"), "XtStyleExposureParam"}, + {MNOTE_HUAWEI_STARS_INFO, "HwMnoteStarsInfo", + N_("Stars Info"), "StarsInfo"}, + {0, "HwUnknow", N_("Unknow Tag"), "UnknowTag"}, }; diff --git a/libexif/huawei/mnote-huawei-tag.h b/libexif/huawei/mnote-huawei-tag.h index f0b0e78..ed0c93e 100644 --- a/libexif/huawei/mnote-huawei-tag.h +++ b/libexif/huawei/mnote-huawei-tag.h @@ -43,6 +43,12 @@ enum _MnoteHuaweiTag { MNOTE_MICRO_VIDEO_PRESENTATION_TIMESTAMP_US = 0x0210, MNOTE_MOVING_PHOTO_ID = 0x0211, MNOTE_HUAWEI_AI_EDIT = 0x0212, + MNOTE_HUAWEI_XTSTYLE_TEMPLATE_NAME = 0x0300, + MNOTE_HUAWEI_XTSTYLE_CUSTOM_LIGHT_SHADOW = 0x0301, + MNOTE_HUAWEI_XTSTYLE_CUSTOM_SATURATION = 0x0302, + MNOTE_HUAWEI_XTSTYLE_CUSTOM_HUE = 0x0303, + MNOTE_HUAWEI_XTSTYLE_EXPOSUREPARAM_PARAM = 0x0304, + MNOTE_HUAWEI_STARS_INFO = 0x0305, MNOTE_HUAWEI_SCENE_INFO = 0x0000, /* subtree */ MNOTE_HUAWEI_SCENE_VERSION = 0x0001,