Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/metadata.c
| Show All 30 Lines | |||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BKE_idprop.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| #include "IMB_metadata.h" | #include "IMB_metadata.h" | ||||
| void IMB_metadata_free(struct ImBuf *img) | void IMB_metadata_free(struct ImBuf *img) | ||||
| { | { | ||||
| ImMetaData *info; | |||||
| if (!img) | if (!img) | ||||
| return; | return; | ||||
| if (!img->metadata) { | if (!img->metadata) { | ||||
| return; | return; | ||||
| } | } | ||||
| info = img->metadata; | |||||
| while (info) { | IDP_FreeProperty(img->metadata); | ||||
| ImMetaData *next = info->next; | MEM_freeN(img->metadata); | ||||
| MEM_freeN(info->key); | |||||
| MEM_freeN(info->value); | |||||
| MEM_freeN(info); | |||||
| info = next; | |||||
| } | |||||
| } | } | ||||
| bool IMB_metadata_get_field(struct ImBuf *img, const char *key, char *field, const size_t len) | bool IMB_metadata_get_field(struct ImBuf *img, const char *key, char *field, const size_t len) | ||||
| { | { | ||||
| ImMetaData *info; | IDProperty *prop; | ||||
| bool retval = false; | bool retval = false; | ||||
| if (!img) | if (!img) | ||||
| return false; | return false; | ||||
| if (!img->metadata) { | if (!img->metadata) | ||||
| return false; | return false; | ||||
| } | |||||
| info = img->metadata; | prop = IDP_GetPropertyFromGroup(img->metadata ,key); | ||||
| while (info) { | |||||
| if (strcmp(key, info->key) == 0) { | if( prop && prop->type == IDP_STRING){ | ||||
sergey: Spaces around braces are wrong. | |||||
| BLI_strncpy(field, info->value, len); | BLI_strncpy(field, IDP_String(prop), len); | ||||
| retval = true; | retval = true; | ||||
| break; | |||||
| } | |||||
| info = info->next; | |||||
| } | } | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| bool IMB_metadata_add_field(struct ImBuf *img, const char *key, const char *value) | bool IMB_metadata_add_field(struct ImBuf *img, const char *key, const char *value) | ||||
| { | { | ||||
| ImMetaData *info; | IDProperty *prop; | ||||
| ImMetaData *last; | |||||
| if (!img) | if (!img) | ||||
| return false; | return false; | ||||
| if (!img->metadata) { | if (!img->metadata) { | ||||
| img->metadata = MEM_callocN(sizeof(ImMetaData), "ImMetaData"); | IDPropertyTemplate val; | ||||
| info = img->metadata; | img->metadata = IDP_New(IDP_GROUP, &val, "metadata"); | ||||
| } | |||||
| else { | |||||
| info = img->metadata; | |||||
| last = info; | |||||
| while (info) { | |||||
| last = info; | |||||
| info = info->next; | |||||
| } | |||||
| info = MEM_callocN(sizeof(ImMetaData), "ImMetaData"); | |||||
| last->next = info; | |||||
| } | } | ||||
| info->key = BLI_strdup(key); | |||||
| info->value = BLI_strdup(value); | prop = IDP_NewString(value, key, 512); | ||||
| return true; | return IDP_AddToGroup(img->metadata, prop); | ||||
| } | } | ||||
| bool IMB_metadata_del_field(struct ImBuf *img, const char *key) | bool IMB_metadata_del_field(struct ImBuf *img, const char *key) | ||||
| { | { | ||||
| ImMetaData *p, *p1; | IDProperty *prop; | ||||
| if ((!img) || (!img->metadata)) | if ((!img) || (!img->metadata)) | ||||
| return false; | return false; | ||||
| p = img->metadata; | prop = IDP_GetPropertyFromGroup(img->metadata, key); | ||||
| p1 = NULL; | |||||
| while (p) { | if (prop) { | ||||
| if (!strcmp(key, p->key)) { | IDP_FreeFromGroup(img->metadata, prop); | ||||
| 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; | |||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field) | bool IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field) | ||||
| { | { | ||||
| ImMetaData *p; | IDProperty *prop; | ||||
| if (!img) | if (!img) | ||||
| return false; | return false; | ||||
| if (!img->metadata) | prop = (img->metadata) ? IDP_GetPropertyFromGroup(img->metadata, key) : NULL; | ||||
| return (IMB_metadata_add_field(img, key, field)); | |||||
| p = img->metadata; | if (!prop) { | ||||
| while (p) { | return (IMB_metadata_add_field(img, key, field)); | ||||
| if (!strcmp(key, p->key)) { | } | ||||
| MEM_freeN(p->value); | else if (prop->type == IDP_STRING) { | ||||
| p->value = BLI_strdup(field); | IDP_AssignString(prop, field, 1024); | ||||
| return true; | return true; | ||||
| } | } | ||||
| p = p->next; | else { | ||||
| return false; | |||||
| } | } | ||||
| return (IMB_metadata_add_field(img, key, field)); | |||||
| } | } | ||||
Spaces around braces are wrong.