[Bf-blender-cvs] [b0a767b85b0] master: IMB_metadata improvements

Sybren A. Stüvel noreply at git.blender.org
Thu Apr 5 16:51:05 CEST 2018


Commit: b0a767b85b0acacc40a414dd3f961b206a6b22f0
Author: Sybren A. Stüvel
Date:   Thu Apr 5 16:27:15 2018 +0200
Branches: master
https://developer.blender.org/rBb0a767b85b0acacc40a414dd3f961b206a6b22f0

IMB_metadata improvements

- Metadata handling is now separate from `ImBuf *`, allowing it to be
  used with a generic `IDProperty *`.
- Merged `IMB_metadata_add_field()` and `IMB_metadata_change_field()`
  into a more robust `IMB_metadata_set_field()`. This new function
  doesn't return any status (it now always succeeds, and the previously
  existing return value was never checked anyway).
- Removed `IMB_metadata_del_field()` as it was never actually used
  anywhere.
- Use `IMB_metadata_ensure()` instead of having
  `IMB_metadata_set_field()` create the containing `IDProperty` for
  you.
- Deduplicated function declarations, moved `intern/IMB_metadata.h` out
  of `intern/`. Note that this does mean that we have some extra
  `#include "IMB_metadata.h"` lines now, as the metadata functions are
  no longer declared in `IMB_imbuf.h`.
- Deduplicated function declarations, all metadata-related declarations
  are now in imbuf/IMB_metadata.h.

Part of: https://developer.blender.org/D2273

Reviewed by: @campbellbarton

===================================================================

M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/seqeffects.c
M	source/blender/blenkernel/intern/sequencer.c
M	source/blender/editors/screen/area.c
M	source/blender/imbuf/CMakeLists.txt
M	source/blender/imbuf/IMB_imbuf.h
R054	source/blender/imbuf/intern/IMB_metadata.h	source/blender/imbuf/IMB_metadata.h
M	source/blender/imbuf/intern/allocimbuf.c
M	source/blender/imbuf/intern/colormanagement.c
M	source/blender/imbuf/intern/jpeg.c
M	source/blender/imbuf/intern/metadata.c
M	source/blender/imbuf/intern/openexr/openexr_api.cpp
M	source/blender/imbuf/intern/png.c
M	source/blender/imbuf/intern/thumbs.c
M	source/blender/render/intern/source/pipeline.c

===================================================================

diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index f0b9afa15fa..e65692fb1b4 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -46,6 +46,7 @@
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 #include "IMB_moviecache.h"
+#include "IMB_metadata.h"
 
 #ifdef WITH_OPENEXR
 #  include "intern/openexr/openexr_multi.h"
@@ -2172,27 +2173,31 @@ void BKE_stamp_data_free(struct StampData *stamp_data)
 }
 
 /* wrap for callback only */
-static void metadata_change_field(void *data, const char *propname, char *propvalue, int UNUSED(len))
+static void metadata_set_field(void *data, const char *propname, char *propvalue, int UNUSED(len))
 {
-	IMB_metadata_change_field(data, propname, propvalue);
+	/* We know it is an ImBuf* because that's what we pass to BKE_stamp_info_callback. */
+	struct ImBuf *imbuf = data;
+	IMB_metadata_set_field(imbuf->metadata, propname, propvalue);
 }
 
 static void metadata_get_field(void *data, const char *propname, char *propvalue, int len)
 {
-	IMB_metadata_get_field(data, propname, propvalue, len);
+	/* We know it is an ImBuf* because that's what we pass to BKE_stamp_info_callback. */
+	struct ImBuf *imbuf = data;
+	IMB_metadata_get_field(imbuf->metadata, propname, propvalue, len);
 }
 
 void BKE_imbuf_stamp_info(RenderResult *rr, struct ImBuf *ibuf)
 {
 	struct StampData *stamp_data = rr->stamp_data;
-
-	BKE_stamp_info_callback(ibuf, stamp_data, metadata_change_field, false);
+	IMB_metadata_ensure(&ibuf->metadata);
+	BKE_stamp_info_callback(ibuf, stamp_data, metadata_set_field, false);
 }
 
 void BKE_stamp_info_from_imbuf(RenderResult *rr, struct ImBuf *ibuf)
 {
 	struct StampData *stamp_data = rr->stamp_data;
-
+	IMB_metadata_ensure(&ibuf->metadata);
 	BKE_stamp_info_callback(ibuf, stamp_data, metadata_get_field, true);
 }
 
diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c
index ee80438db64..49f120de250 100644
--- a/source/blender/blenkernel/intern/seqeffects.c
+++ b/source/blender/blenkernel/intern/seqeffects.c
@@ -52,6 +52,7 @@
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 #include "IMB_colormanagement.h"
+#include "IMB_metadata.h"
 
 #include "BLI_math_color_blend.h"
 
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 095a8621191..1e61ff526ef 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -84,6 +84,7 @@
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 #include "IMB_colormanagement.h"
+#include "IMB_metadata.h"
 
 #include "BKE_context.h"
 #include "BKE_sound.h"
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index fc0922c7b7c..caae803100b 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -63,6 +63,7 @@
 
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
+#include "IMB_metadata.h"
 
 #include "UI_interface.h"
 #include "UI_interface_icons.h"
@@ -2138,7 +2139,7 @@ static const char *meta_data_list[] =
 
 BLI_INLINE bool metadata_is_valid(ImBuf *ibuf, char *r_str, short index, int offset)
 {
-	return (IMB_metadata_get_field(ibuf, meta_data_list[index], r_str + offset, MAX_METADATA_STR - offset) && r_str[0]);
+	return (IMB_metadata_get_field(ibuf->metadata, meta_data_list[index], r_str + offset, MAX_METADATA_STR - offset) && r_str[0]);
 }
 
 static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const bool is_top)
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
similarity index 54%
rename from source/blender/imbuf/intern/IMB_metadata.h
rename to source/blender/imbuf/IMB_metadata.h
index bc0b2c70ecb..258d6bb1c5a 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,35 @@ 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);
 
 #endif /* __IMB_METADATA_H__ */
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/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_fie

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list