diff options
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/imbuf/IMB_imbuf.h | 16 | ||||
-rw-r--r-- | source/blender/imbuf/IMB_metadata.h (renamed from source/blender/imbuf/intern/IMB_metadata.h) | 40 | ||||
-rw-r--r-- | source/blender/imbuf/intern/IMB_anim.h | 3 | ||||
-rw-r--r-- | source/blender/imbuf/intern/allocimbuf.c | 2 | ||||
-rw-r--r-- | source/blender/imbuf/intern/anim_movie.c | 22 | ||||
-rw-r--r-- | source/blender/imbuf/intern/colormanagement.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/jpeg.c | 6 | ||||
-rw-r--r-- | source/blender/imbuf/intern/metadata.c | 90 | ||||
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_api.cpp | 3 | ||||
-rw-r--r-- | source/blender/imbuf/intern/png.c | 3 | ||||
-rw-r--r-- | source/blender/imbuf/intern/thumbs.c | 19 |
12 files changed, 103 insertions, 104 deletions
diff --git a/source/blender/imbuf/CMakeLists.txt b/source/blender/imbuf/CMakeLists.txt index c3950d8eb83..e73f227dec8 100644 --- a/source/blender/imbuf/CMakeLists.txt +++ b/source/blender/imbuf/CMakeLists.txt @@ -73,6 +73,7 @@ set(SRC IMB_colormanagement.h IMB_imbuf.h IMB_imbuf_types.h + IMB_metadata.h IMB_moviecache.h IMB_thumbs.h intern/IMB_allocimbuf.h @@ -81,7 +82,6 @@ set(SRC intern/IMB_filetype.h intern/IMB_filter.h intern/IMB_indexer.h - intern/IMB_metadata.h intern/imbuf.h # orphan include diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index a0fc273a746..e5cd21a3248 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -566,22 +566,6 @@ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, const float col[4], struct ColorManagedDisplay *display, int x1, int y1, int x2, int y2); -/** - * - * \attention Defined in metadata.c - */ -/** read the field from the image info into the field - * \param img - the ImBuf that contains the image data - * \param key - the key of the field - * \param value - the data in the field, first one found with key is returned, - * memory has to be allocated by user. - * \param len - length of value buffer allocated by user. - * \return - 1 (true) if ImageInfo present and value for the key found, 0 (false) otherwise - */ -bool IMB_metadata_get_field(struct ImBuf *img, const char *key, char *value, const size_t len); -bool IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field); -void IMB_metadata_copy(struct ImBuf *dimb, struct ImBuf *simb); - /* exported for image tools in blender, to quickly allocate 32 bits rect */ void *imb_alloc_pixels(unsigned int x, unsigned int y, diff --git a/source/blender/imbuf/intern/IMB_metadata.h b/source/blender/imbuf/IMB_metadata.h index bc0b2c70ecb..0a0d2c1faf6 100644 --- a/source/blender/imbuf/intern/IMB_metadata.h +++ b/source/blender/imbuf/IMB_metadata.h @@ -4,7 +4,7 @@ * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -33,7 +33,9 @@ #ifndef __IMB_METADATA_H__ #define __IMB_METADATA_H__ +struct anim; struct ImBuf; +struct IDProperty; /** The metadata is a list of key/value pairs (both char *) that can me * saved in the header of several image formats. @@ -41,26 +43,36 @@ struct ImBuf; * 'Software' and 'Description' (png standard) we'll use keys within the * Blender namespace, so should be called 'Blender::StampInfo' or 'Blender::FrameNum' * etc... + * + * The keys & values are stored in ID properties, in the group "metadata". */ +/** Ensure that the metadata property is a valid IDProperty object. + * This is a no-op when *metadata != NULL. + */ +void IMB_metadata_ensure(struct IDProperty **metadata); +void IMB_metadata_free(struct IDProperty *metadata); -/* free blender ImMetaData struct */ -void IMB_metadata_free(struct ImBuf *img); +/** Read the field from the image info into the field. + * \param metadata - the IDProperty that contains the metadata + * \param key - the key of the field + * \param value - the data in the field, first one found with key is returned, + * memory has to be allocated by user. + * \param len - length of value buffer allocated by user. + * \return - 1 (true) if metadata is present and value for the key found, 0 (false) otherwise + */ +bool IMB_metadata_get_field(struct IDProperty *metadata, const char *key, char *value, const size_t len); -/** set user data in the ImMetaData struct, which has to be allocated with IMB_metadata_create - * before calling this function. - * \param img - the ImBuf that contains the image data +/** Set user data in the metadata. + * If the field already exists its value is overwritten, otherwise the field + * will be added with the given value. + * \param metadata - the IDProperty that contains the metadata * \param key - the key of the field * \param value - the data to be written to the field. zero terminated string - * \return - 1 (true) if ImageInfo present, 0 (false) otherwise */ -bool IMB_metadata_add_field(struct ImBuf *img, const char *key, const char *value); +void IMB_metadata_set_field(struct IDProperty *metadata, const char *key, const char *value); -/** delete the key/field par in the ImMetaData struct. - * \param img - the ImBuf that contains the image data - * \param key - the key of the field - * \return - 1 (true) if delete the key/field, 0 (false) otherwise - */ -bool IMB_metadata_del_field(struct ImBuf *img, const char *key); +void IMB_metadata_copy(struct ImBuf *dimb, struct ImBuf *simb); +struct IDProperty *IMB_anim_load_metadata(struct anim *anim); #endif /* __IMB_METADATA_H__ */ diff --git a/source/blender/imbuf/intern/IMB_anim.h b/source/blender/imbuf/intern/IMB_anim.h index c4c4f4405a5..6fa31e122cc 100644 --- a/source/blender/imbuf/intern/IMB_anim.h +++ b/source/blender/imbuf/intern/IMB_anim.h @@ -93,6 +93,7 @@ struct _AviMovie; struct anim_index; +struct IDProperty; struct anim { int ib_flags; @@ -158,6 +159,8 @@ struct anim { char colorspace[64]; char suffix[64]; /* MAX_NAME - multiview */ + + struct IDProperty *metadata; }; #endif diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index 7fc4a65d8d7..faa0b5f7b6e 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -219,7 +219,7 @@ void IMB_freeImBuf(ImBuf *ibuf) IMB_freezbufImBuf(ibuf); IMB_freezbuffloatImBuf(ibuf); freeencodedbufferImBuf(ibuf); - IMB_metadata_free(ibuf); + IMB_metadata_free(ibuf->metadata); colormanage_cache_free(ibuf); if (ibuf->dds_data.data != NULL) { diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index cc8a38d5bf4..f842b69418e 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -80,6 +80,7 @@ #include "IMB_anim.h" #include "IMB_indexer.h" +#include "IMB_metadata.h" #ifdef WITH_FFMPEG # include "BKE_global.h" /* ENDIAN_ORDER */ @@ -220,6 +221,7 @@ void IMB_free_anim(struct anim *anim) free_anim_ffmpeg(anim); #endif IMB_free_indices(anim); + IMB_metadata_free(anim->metadata); MEM_freeN(anim); } @@ -239,6 +241,26 @@ void IMB_close_anim_proxies(struct anim *anim) IMB_free_indices(anim); } +struct IDProperty *IMB_anim_load_metadata(struct anim *anim) +{ +#ifdef WITH_FFMPEG + AVDictionaryEntry *entry = NULL; + + BLI_assert(anim->pFormatCtx != NULL); + av_log(anim->pFormatCtx, AV_LOG_DEBUG, "METADATA FETCH\n"); + + while (true) { + entry = av_dict_get(anim->pFormatCtx->metadata, "", entry, AV_DICT_IGNORE_SUFFIX); + if (entry == NULL) break; + + /* Delay creation of the property group until there is actual metadata to put in there. */ + IMB_metadata_ensure(&anim->metadata); + IMB_metadata_set_field(anim->metadata, entry->key, entry->value); + } +#endif + return anim->metadata; +} + struct anim *IMB_open_anim(const char *name, int ib_flags, int streamindex, char colorspace[IM_MAX_SPACE]) { struct anim *anim; diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index e28c8122006..b2197ecb3b5 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -49,6 +49,7 @@ #include "IMB_filetype.h" #include "IMB_filter.h" #include "IMB_moviecache.h" +#include "IMB_metadata.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index 35c7b6363a1..ef9217fbc8c 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -382,7 +382,8 @@ static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int fla * the information when we write * it back to disk. */ - IMB_metadata_add_field(ibuf, "None", str); + IMB_metadata_ensure(&ibuf->metadata); + IMB_metadata_set_field(ibuf->metadata, "None", str); ibuf->flags |= IB_metadata; MEM_freeN(str); goto next_stamp_marker; @@ -408,7 +409,8 @@ static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int fla *value = '\0'; /* need finish the key string */ value++; - IMB_metadata_add_field(ibuf, key, value); + IMB_metadata_ensure(&ibuf->metadata); + IMB_metadata_set_field(ibuf->metadata, key, value); ibuf->flags |= IB_metadata; MEM_freeN(str); next_stamp_marker: diff --git a/source/blender/imbuf/intern/metadata.c b/source/blender/imbuf/intern/metadata.c index da39967a4fe..ef103f7afcf 100644 --- a/source/blender/imbuf/intern/metadata.c +++ b/source/blender/imbuf/intern/metadata.c @@ -45,97 +45,69 @@ #include "IMB_metadata.h" +#define METADATA_MAX_VALUE_LENGTH 1024 -void IMB_metadata_free(struct ImBuf *img) +void IMB_metadata_ensure(struct IDProperty **metadata) { - if (!img) + if (*metadata != NULL) { return; - if (!img->metadata) { + } + + IDPropertyTemplate val; + *metadata = IDP_New(IDP_GROUP, &val, "metadata"); +} + +void IMB_metadata_free(struct IDProperty *metadata) +{ + if (metadata == NULL) { return; } - IDP_FreeProperty(img->metadata); - MEM_freeN(img->metadata); + IDP_FreeProperty(metadata); + MEM_freeN(metadata); } -bool IMB_metadata_get_field(struct ImBuf *img, const char *key, char *field, const size_t len) +bool IMB_metadata_get_field(struct IDProperty *metadata, const char *key, char *field, const size_t len) { IDProperty *prop; - bool retval = false; - - if (!img) - return false; - if (!img->metadata) + if (metadata == NULL) { return false; + } - prop = IDP_GetPropertyFromGroup(img->metadata, key); + prop = IDP_GetPropertyFromGroup(metadata, key); if (prop && prop->type == IDP_STRING) { BLI_strncpy(field, IDP_String(prop), len); - retval = true; + return true; } - return retval; + return false; } void IMB_metadata_copy(struct ImBuf *dimb, struct ImBuf *simb) { BLI_assert(dimb != simb); if (simb->metadata) { - IMB_metadata_free(dimb); + IMB_metadata_free(dimb->metadata); dimb->metadata = IDP_CopyProperty(simb->metadata); } } -bool IMB_metadata_add_field(struct ImBuf *img, const char *key, const char *value) +void IMB_metadata_set_field(struct IDProperty *metadata, const char *key, const char *value) { - IDProperty *prop; - - if (!img) - return false; + BLI_assert(metadata); + IDProperty *prop = IDP_GetPropertyFromGroup(metadata, key); - if (!img->metadata) { - IDPropertyTemplate val; - img->metadata = IDP_New(IDP_GROUP, &val, "metadata"); + if (prop != NULL && prop->type != IDP_STRING) { + IDP_FreeFromGroup(metadata, prop); + prop = NULL; } - prop = IDP_NewString(value, key, 512); - return IDP_AddToGroup(img->metadata, prop); -} - -bool IMB_metadata_del_field(struct ImBuf *img, const char *key) -{ - IDProperty *prop; - - if ((!img) || (!img->metadata)) - return false; - - prop = IDP_GetPropertyFromGroup(img->metadata, key); - - if (prop) { - IDP_FreeFromGroup(img->metadata, prop); + if (prop == NULL) { + prop = IDP_NewString(value, key, METADATA_MAX_VALUE_LENGTH); + IDP_AddToGroup(metadata, prop); } - return false; -} - -bool IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field) -{ - IDProperty *prop; - if (!img) - return false; - - prop = (img->metadata) ? IDP_GetPropertyFromGroup(img->metadata, key) : NULL; - - 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; - } + IDP_AssignString(prop, value, METADATA_MAX_VALUE_LENGTH); } diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index 4e85d70d382..ad04f1fb78d 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -1790,12 +1790,13 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem, size_t size, int flags, const Header & header = file->header(0); Header::ConstIterator iter; + IMB_metadata_ensure(&ibuf->metadata); for (iter = header.begin(); iter != header.end(); iter++) { const StringAttribute *attrib = file->header(0).findTypedAttribute <StringAttribute> (iter.name()); /* not all attributes are string attributes so we might get some NULLs here */ if (attrib) { - IMB_metadata_add_field(ibuf, iter.name(), attrib->value().c_str()); + IMB_metadata_set_field(ibuf->metadata, iter.name(), attrib->value().c_str()); ibuf->flags |= IB_metadata; } } diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 857f72e10eb..29fbe79d8db 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -759,8 +759,9 @@ ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, char colors if (flags & IB_metadata) { png_text *text_chunks; int count = png_get_text(png_ptr, info_ptr, &text_chunks, NULL); + IMB_metadata_ensure(&ibuf->metadata); for (int i = 0; i < count; i++) { - IMB_metadata_add_field(ibuf, text_chunks[i].key, text_chunks[i].text); + IMB_metadata_set_field(ibuf->metadata, text_chunks[i].key, text_chunks[i].text); ibuf->flags |= IB_metadata; } } diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index ba72decf44d..86e1fba9af7 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -430,16 +430,17 @@ static ImBuf *thumb_create_ex( IMB_scaleImBuf(img, ex, ey); } BLI_snprintf(desc, sizeof(desc), "Thumbnail for %s", uri); - IMB_metadata_change_field(img, "Description", desc); - IMB_metadata_change_field(img, "Software", "Blender"); - IMB_metadata_change_field(img, "Thumb::URI", uri); - IMB_metadata_change_field(img, "Thumb::MTime", mtime); + IMB_metadata_ensure(&img->metadata); + IMB_metadata_set_field(img->metadata, "Software", "Blender"); + IMB_metadata_set_field(img->metadata, "Thumb::URI", uri); + IMB_metadata_set_field(img->metadata, "Description", desc); + IMB_metadata_set_field(img->metadata, "Thumb::MTime", mtime); if (use_hash) { - IMB_metadata_change_field(img, "X-Blender::Hash", hash); + IMB_metadata_set_field(img->metadata, "X-Blender::Hash", hash); } if (ELEM(source, THB_SOURCE_IMAGE, THB_SOURCE_BLEND, THB_SOURCE_FONT)) { - IMB_metadata_change_field(img, "Thumb::Image::Width", cwidth); - IMB_metadata_change_field(img, "Thumb::Image::Height", cheight); + IMB_metadata_set_field(img->metadata, "Thumb::Image::Width", cwidth); + IMB_metadata_set_field(img->metadata, "Thumb::Image::Height", cheight); } img->ftype = IMB_FTYPE_PNG; img->planes = 32; @@ -589,7 +590,7 @@ ImBuf *IMB_thumb_manage(const char *org_path, ThumbSize size, ThumbSource source const bool use_hash = thumbhash_from_path(file_path, source, thumb_hash); - if (IMB_metadata_get_field(img, "Thumb::MTime", mtime, sizeof(mtime))) { + if (IMB_metadata_get_field(img->metadata, "Thumb::MTime", mtime, sizeof(mtime))) { regenerate = (st.st_mtime != atol(mtime)); } else { @@ -598,7 +599,7 @@ ImBuf *IMB_thumb_manage(const char *org_path, ThumbSize size, ThumbSource source } if (use_hash && !regenerate) { - if (IMB_metadata_get_field(img, "X-Blender::Hash", thumb_hash_curr, sizeof(thumb_hash_curr))) { + if (IMB_metadata_get_field(img->metadata, "X-Blender::Hash", thumb_hash_curr, sizeof(thumb_hash_curr))) { regenerate = !STREQ(thumb_hash, thumb_hash_curr); } else { |