2024-01-18 22:50:23 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2024 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup imbuf
|
2011-02-27 20:23:21 +00:00
|
|
|
*/
|
|
|
|
|
|
2023-07-22 11:27:25 +10:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2023-05-02 11:32:27 +02:00
|
|
|
#include "BLI_listbase.h"
|
2012-08-12 23:28:33 +00:00
|
|
|
#include "BLI_string.h"
|
|
|
|
|
|
2024-03-26 12:57:30 -04:00
|
|
|
#include "BKE_idprop.hh"
|
2015-01-31 17:15:43 +01:00
|
|
|
|
2020-12-15 10:47:58 +11:00
|
|
|
#include "DNA_ID.h" /* ID property definitions. */
|
|
|
|
|
|
2024-01-18 22:50:23 +02:00
|
|
|
#include "IMB_imbuf_types.hh"
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2024-01-18 22:50:23 +02:00
|
|
|
#include "IMB_metadata.hh"
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void IMB_metadata_ensure(IDProperty **metadata)
|
2007-09-02 17:25:03 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
if (*metadata != nullptr) {
|
2007-09-02 17:25:03 +00:00
|
|
|
return;
|
2018-04-05 16:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
2024-03-26 15:39:34 -04:00
|
|
|
*metadata = blender::bke::idprop::create_group("metadata").release();
|
2018-04-05 16:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void IMB_metadata_free(IDProperty *metadata)
|
2018-04-05 16:27:15 +02:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
if (metadata == nullptr) {
|
2007-09-02 17:25:03 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2015-01-31 17:15:43 +01:00
|
|
|
|
2018-04-05 16:27:15 +02:00
|
|
|
IDP_FreeProperty(metadata);
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
2024-03-09 16:37:40 +11:00
|
|
|
bool IMB_metadata_get_field(const IDProperty *metadata,
|
2018-04-05 16:27:15 +02:00
|
|
|
const char *key,
|
2023-05-13 17:34:23 +10:00
|
|
|
char *value,
|
|
|
|
|
const size_t value_maxncpy)
|
2007-09-02 17:25:03 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
if (metadata == nullptr) {
|
2013-09-10 01:00:03 +00:00
|
|
|
return false;
|
2018-04-05 16:27:15 +02:00
|
|
|
}
|
2015-01-31 17:15:43 +01:00
|
|
|
|
2024-03-09 16:37:40 +11:00
|
|
|
IDProperty *prop = IDP_GetPropertyFromGroup(metadata, key);
|
2015-01-31 17:15:43 +01:00
|
|
|
|
2015-02-01 04:19:43 +11:00
|
|
|
if (prop && prop->type == IDP_STRING) {
|
2023-05-13 17:34:23 +10:00
|
|
|
BLI_strncpy(value, IDP_String(prop), value_maxncpy);
|
2018-04-05 16:27:15 +02:00
|
|
|
return true;
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
2018-04-05 16:27:15 +02:00
|
|
|
return false;
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
2024-02-28 11:02:56 +11:00
|
|
|
void IMB_metadata_copy(ImBuf *ibuf_dst, const ImBuf *ibuf_src)
|
2015-04-20 19:57:57 +02:00
|
|
|
{
|
2024-02-28 11:02:56 +11:00
|
|
|
BLI_assert(ibuf_dst != ibuf_src);
|
|
|
|
|
if (ibuf_src->metadata) {
|
|
|
|
|
IMB_metadata_free(ibuf_dst->metadata);
|
|
|
|
|
ibuf_dst->metadata = IDP_CopyProperty(ibuf_src->metadata);
|
2015-04-20 19:57:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void IMB_metadata_set_field(IDProperty *metadata, const char *key, const char *value)
|
2007-09-02 17:25:03 +00:00
|
|
|
{
|
2018-04-05 16:27:15 +02:00
|
|
|
BLI_assert(metadata);
|
|
|
|
|
IDProperty *prop = IDP_GetPropertyFromGroup(metadata, key);
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2023-05-02 11:32:27 +02:00
|
|
|
if (prop != nullptr && prop->type != IDP_STRING) {
|
2018-04-05 16:27:15 +02:00
|
|
|
IDP_FreeFromGroup(metadata, prop);
|
2023-05-02 11:32:27 +02:00
|
|
|
prop = nullptr;
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
2015-01-31 17:15:43 +01:00
|
|
|
|
2023-05-02 14:11:40 +10:00
|
|
|
if (prop) {
|
2023-05-02 15:07:55 +10:00
|
|
|
IDP_AssignString(prop, value);
|
2023-05-02 14:11:40 +10:00
|
|
|
}
|
2024-03-09 16:37:40 +11:00
|
|
|
else {
|
2024-03-26 15:39:34 -04:00
|
|
|
prop = blender::bke::idprop::create(key, value).release();
|
2018-04-05 16:27:15 +02:00
|
|
|
IDP_AddToGroup(metadata, prop);
|
2007-10-20 16:17:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-02-06 11:49:41 +01:00
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void IMB_metadata_foreach(ImBuf *ibuf, IMBMetadataForeachCb callback, void *userdata)
|
2019-02-06 11:49:41 +01:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
if (ibuf->metadata == nullptr) {
|
2019-02-07 09:33:43 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2023-05-02 11:32:27 +02:00
|
|
|
LISTBASE_FOREACH (IDProperty *, prop, &ibuf->metadata->data.group) {
|
2019-02-06 11:49:41 +01:00
|
|
|
callback(prop->name, IDP_String(prop), userdata);
|
|
|
|
|
}
|
|
|
|
|
}
|