Blender V4.3
metadata.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstdlib>
10#include <cstring>
11
12#include "BLI_listbase.h"
13#include "BLI_string.h"
14#include "BLI_utildefines.h"
15
16#include "BKE_idprop.hh"
17
18#include "DNA_ID.h" /* ID property definitions. */
19
20#include "IMB_imbuf_types.hh"
21
22#include "IMB_metadata.hh"
23
25{
26 if (*metadata != nullptr) {
27 return;
28 }
29
30 *metadata = blender::bke::idprop::create_group("metadata").release();
31}
32
34{
35 if (metadata == nullptr) {
36 return;
37 }
38
39 IDP_FreeProperty(metadata);
40}
41
43 const char *key,
44 char *value,
45 const size_t value_maxncpy)
46{
47 if (metadata == nullptr) {
48 return false;
49 }
50
51 IDProperty *prop = IDP_GetPropertyFromGroup(metadata, key);
52
53 if (prop && prop->type == IDP_STRING) {
54 BLI_strncpy(value, IDP_String(prop), value_maxncpy);
55 return true;
56 }
57 return false;
58}
59
60void IMB_metadata_copy(ImBuf *ibuf_dst, const ImBuf *ibuf_src)
61{
62 BLI_assert(ibuf_dst != ibuf_src);
63 if (ibuf_src->metadata) {
64 IMB_metadata_free(ibuf_dst->metadata);
65 ibuf_dst->metadata = IDP_CopyProperty(ibuf_src->metadata);
66 }
67}
68
69void IMB_metadata_set_field(IDProperty *metadata, const char *key, const char *value)
70{
71 BLI_assert(metadata);
72 IDProperty *prop = IDP_GetPropertyFromGroup(metadata, key);
73
74 if (prop != nullptr && prop->type != IDP_STRING) {
75 IDP_FreeFromGroup(metadata, prop);
76 prop = nullptr;
77 }
78
79 if (prop) {
80 IDP_AssignString(prop, value);
81 }
82 else {
83 prop = blender::bke::idprop::create(key, value).release();
84 IDP_AddToGroup(metadata, prop);
85 }
86}
87
89{
90 if (ibuf->metadata == nullptr) {
91 return;
92 }
93 LISTBASE_FOREACH (IDProperty *, prop, &ibuf->metadata->data.group) {
94 callback(prop->name, IDP_String(prop), userdata);
95 }
96}
void IDP_FreeFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:757
void IDP_AssignString(IDProperty *prop, const char *st) ATTR_NONNULL()
Definition idprop.cc:431
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:763
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1227
#define IDP_String(prop)
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:722
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:861
#define BLI_assert(a)
Definition BLI_assert.h:50
#define LISTBASE_FOREACH(type, var, list)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
ID and Library types, which are fundamental for SDNA.
@ IDP_STRING
Contains defines and structs used throughout the imbuf module.
void(*)(const char *field, const char *value, void *userdata) IMBMetadataForeachCb
DEGForeachIDComponentCallback callback
void IMB_metadata_set_field(IDProperty *metadata, const char *key, const char *value)
Definition metadata.cc:69
void IMB_metadata_foreach(ImBuf *ibuf, IMBMetadataForeachCb callback, void *userdata)
Definition metadata.cc:88
void IMB_metadata_ensure(IDProperty **metadata)
Definition metadata.cc:24
void IMB_metadata_free(IDProperty *metadata)
Definition metadata.cc:33
bool IMB_metadata_get_field(const IDProperty *metadata, const char *key, char *value, const size_t value_maxncpy)
Definition metadata.cc:42
void IMB_metadata_copy(ImBuf *ibuf_dst, const ImBuf *ibuf_src)
Definition metadata.cc:60
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRefNull prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
ListBase group
Definition DNA_ID.h:146
IDPropertyData data
Definition DNA_ID.h:168
char type
Definition DNA_ID.h:154
IDProperty * metadata