diff options
author | Martijn Berger <martijn.berger@gmail.com> | 2015-01-31 19:15:43 +0300 |
---|---|---|
committer | Martijn Berger <martijn.berger@gmail.com> | 2015-01-31 19:15:43 +0300 |
commit | 5ac7e23e886361f7d74d5d6367e63b688bcda361 (patch) | |
tree | debd7e0798338ecab16de51ebb94d89bbab096af /source/blender/imbuf/intern/metadata.c | |
parent | f90891d87e351ef1c9509007a18dc72ee5025809 (diff) |
Blender metadata changes to accommodate non string data
Work towards T42418
For now got rid of linked list holding key,value pairs for metadata in favour of ID properties.
Reviewers: campbellbarton, sergey
Reviewed By: sergey
Projects: #bf_blender
Differential Revision: https://developer.blender.org/D872
Diffstat (limited to 'source/blender/imbuf/intern/metadata.c')
-rw-r--r-- | source/blender/imbuf/intern/metadata.c | 105 |
1 files changed, 36 insertions, 69 deletions
diff --git a/source/blender/imbuf/intern/metadata.c b/source/blender/imbuf/intern/metadata.c index 35d921beabd..885823aa5fe 100644 --- a/source/blender/imbuf/intern/metadata.c +++ b/source/blender/imbuf/intern/metadata.c @@ -36,6 +36,8 @@ #include "BLI_utildefines.h" #include "BLI_string.h" +#include "BKE_idprop.h" + #include "MEM_guardedalloc.h" #include "IMB_imbuf_types.h" @@ -47,119 +49,84 @@ void IMB_metadata_free(struct ImBuf *img) { - ImMetaData *info; - if (!img) return; if (!img->metadata) { return; } - info = img->metadata; - while (info) { - ImMetaData *next = info->next; - MEM_freeN(info->key); - MEM_freeN(info->value); - MEM_freeN(info); - info = next; - } + + IDP_FreeProperty(img->metadata); + MEM_freeN(img->metadata); } bool IMB_metadata_get_field(struct ImBuf *img, const char *key, char *field, const size_t len) { - ImMetaData *info; + IDProperty *prop; + bool retval = false; if (!img) return false; - if (!img->metadata) { + if (!img->metadata) return false; - } - info = img->metadata; - while (info) { - if (STREQ(key, info->key)) { - BLI_strncpy(field, info->value, len); - retval = true; - break; - } - info = info->next; + + prop = IDP_GetPropertyFromGroup(img->metadata ,key); + + if(prop && prop->type == IDP_STRING){ + BLI_strncpy(field, IDP_String(prop), len); + retval = true; } return retval; } bool IMB_metadata_add_field(struct ImBuf *img, const char *key, const char *value) { - ImMetaData *info; - ImMetaData *last; + IDProperty *prop; if (!img) return false; if (!img->metadata) { - img->metadata = MEM_callocN(sizeof(ImMetaData), "ImMetaData"); - info = img->metadata; - } - else { - info = img->metadata; - last = info; - while (info) { - last = info; - info = info->next; - } - info = MEM_callocN(sizeof(ImMetaData), "ImMetaData"); - last->next = info; + IDPropertyTemplate val; + img->metadata = IDP_New(IDP_GROUP, &val, "metadata"); } - info->key = BLI_strdup(key); - info->value = BLI_strdup(value); - return true; + + prop = IDP_NewString(value, key, 512); + return IDP_AddToGroup(img->metadata, prop); } bool IMB_metadata_del_field(struct ImBuf *img, const char *key) { - ImMetaData *p, *p1; + IDProperty *prop; if ((!img) || (!img->metadata)) return false; - p = img->metadata; - p1 = NULL; - while (p) { - if (STREQ(key, p->key)) { - if (p1) - p1->next = p->next; - else - img->metadata = p->next; - - MEM_freeN(p->key); - MEM_freeN(p->value); - MEM_freeN(p); - return true; - } - p1 = p; - p = p->next; + prop = IDP_GetPropertyFromGroup(img->metadata, key); + + if (prop) { + IDP_FreeFromGroup(img->metadata, prop); } return false; } bool IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field) { - ImMetaData *p; + IDProperty *prop; if (!img) return false; - if (!img->metadata) - return (IMB_metadata_add_field(img, key, field)); + prop = (img->metadata) ? IDP_GetPropertyFromGroup(img->metadata, key) : NULL; - p = img->metadata; - while (p) { - if (STREQ(key, p->key)) { - MEM_freeN(p->value); - p->value = BLI_strdup(field); - return true; - } - p = p->next; + if (!prop) { + return (IMB_metadata_add_field(img, key, field)); + } + else if (prop->type == IDP_STRING) { + IDP_AssignString(prop, field, 1024); + return true; + } + else { + return false; } - - return (IMB_metadata_add_field(img, key, field)); } - |