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 | |
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')
-rw-r--r-- | source/blender/imbuf/intern/IMB_metadata.h | 7 | ||||
-rw-r--r-- | source/blender/imbuf/intern/jpeg.c | 41 | ||||
-rw-r--r-- | source/blender/imbuf/intern/metadata.c | 105 | ||||
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_api.cpp | 13 | ||||
-rw-r--r-- | source/blender/imbuf/intern/png.c | 28 |
5 files changed, 82 insertions, 112 deletions
diff --git a/source/blender/imbuf/intern/IMB_metadata.h b/source/blender/imbuf/intern/IMB_metadata.h index a717764b44f..5d4a0028ee1 100644 --- a/source/blender/imbuf/intern/IMB_metadata.h +++ b/source/blender/imbuf/intern/IMB_metadata.h @@ -35,13 +35,6 @@ struct ImBuf; -typedef struct ImMetaData { - struct ImMetaData *next, *prev; - char *key; - char *value; - int len; -} ImMetaData; - /** The metadata is a list of key/value pairs (both char *) that can me * saved in the header of several image formats. * Apart from some common keys like diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index 6093a1477ce..310e517e38d 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -41,6 +41,8 @@ #include "BLI_string.h" #include "BLI_fileops.h" +#include "BKE_idprop.h" + #include "imbuf.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -479,7 +481,6 @@ static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf) uchar *rect; int x, y; char neogeo[128]; - ImMetaData *iptr; char *text; jpeg_start_compress(cinfo, true); @@ -491,28 +492,28 @@ static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf) jpeg_write_marker(cinfo, 0xe1, (JOCTET *) neogeo, 10); if (ibuf->metadata) { + IDProperty *prop; /* key + max value + "Blender" */ text = MEM_mallocN(530, "stamp info read"); - iptr = ibuf->metadata; - while (iptr) { - if (STREQ(iptr->key, "None")) { - jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) iptr->value, strlen(iptr->value) + 1); - goto next_stamp_info; - } + for (prop = ibuf->metadata->data.group.first; prop; prop = prop->next) { + if (prop->type == IDP_STRING) { + int text_len; + if (!strcmp(prop->name, "None")) { + jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) IDP_String(prop), prop->len + 1); + } - /* - * The JPEG format don't support a pair "key/value" - * like PNG, so we "encode" the stamp in a - * single string: - * "Blender:key:value" - * - * The first "Blender" is a simple identify to help - * in the read process. - */ - sprintf(text, "Blender:%s:%s", iptr->key, iptr->value); - jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) text, strlen(text) + 1); -next_stamp_info: - iptr = iptr->next; + /* + * The JPEG format don't support a pair "key/value" + * like PNG, so we "encode" the stamp in a + * single string: + * "Blender:key:value" + * + * The first "Blender" is a simple identify to help + * in the read process. + */ + text_len = sprintf(text, "Blender:%s:%s", prop->name, IDP_String(prop)); + jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) text, text_len + 1); + } } MEM_freeN(text); } 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)); } - diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index ad19c547db3..5de243845a4 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -60,6 +60,8 @@ _CRTIMP void __cdecl _invalid_parameter_noinfo(void) #include "BLI_math_color.h" #include "BLI_threads.h" +#include "BKE_idprop.h" + #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "IMB_allocimbuf.h" @@ -305,10 +307,15 @@ static void openexr_header_compression(Header *header, int compression) static void openexr_header_metadata(Header *header, struct ImBuf *ibuf) { - ImMetaData *info; + if (ibuf->metadata) { + IDProperty *prop; - for (info = ibuf->metadata; info; info = info->next) - header->insert(info->key, StringAttribute(info->value)); + for (prop = (IDProperty *)ibuf->metadata->data.group.first; prop; prop = prop->next) { + if (prop->type == IDP_STRING) { + header->insert(prop->name, StringAttribute(IDP_String(prop))); + } + } + } if (ibuf->ppm[0] > 0.0) addXDensity(*header, ibuf->ppm[0] / 39.3700787); /* 1 meter = 39.3700787 inches */ diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 94914db3a1a..6b31b3e965b 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -38,6 +38,7 @@ #include "BLI_math.h" #include "BKE_global.h" +#include "BKE_idprop.h" #include "MEM_guardedalloc.h" @@ -397,24 +398,25 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) /* image text info */ if (ibuf->metadata) { png_text *metadata; - ImMetaData *iptr; + IDProperty *prop; + int num_text = 0; - iptr = ibuf->metadata; - while (iptr) { - num_text++; - iptr = iptr->next; + + for (prop = ibuf->metadata->data.group.first; prop; prop = prop->next) { + if (prop->type == IDP_STRING){ + num_text++; + } } metadata = MEM_callocN(num_text * sizeof(png_text), "png_metadata"); - iptr = ibuf->metadata; num_text = 0; - while (iptr) { - - metadata[num_text].compression = PNG_TEXT_COMPRESSION_NONE; - metadata[num_text].key = iptr->key; - metadata[num_text].text = iptr->value; - num_text++; - iptr = iptr->next; + for (prop = ibuf->metadata->data.group.first; prop; prop = prop->next) { + if (prop->type == IDP_STRING){ + metadata[num_text].compression = PNG_TEXT_COMPRESSION_NONE; + metadata[num_text].key = prop->name; + metadata[num_text].text = IDP_String(prop); + num_text++; + } } png_set_text(png_ptr, info_ptr, metadata, num_text); |