2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2007-09-02 17:25:03 +00:00
|
|
|
* 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
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2007-09-02 17:25:03 +00:00
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-09-02 17:25:03 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup imbuf
|
2011-02-27 20:23:21 +00:00
|
|
|
*/
|
|
|
|
|
|
2007-09-02 17:25:03 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2012-08-12 23:28:33 +00:00
|
|
|
#include "BLI_string.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2012-08-12 23:28:33 +00:00
|
|
|
|
2015-01-31 17:15:43 +01:00
|
|
|
#include "BKE_idprop.h"
|
|
|
|
|
|
2007-09-02 17:25:03 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "IMB_imbuf.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "IMB_imbuf_types.h"
|
2007-09-02 17:25:03 +00:00
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
#include "IMB_metadata.h"
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2018-04-05 16:27:15 +02:00
|
|
|
#define METADATA_MAX_VALUE_LENGTH 1024
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2018-04-05 16:27:15 +02:00
|
|
|
void IMB_metadata_ensure(struct IDProperty **metadata)
|
2007-09-02 17:25:03 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (*metadata != NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-05 16:27:15 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IDPropertyTemplate val;
|
|
|
|
|
*metadata = IDP_New(IDP_GROUP, &val, "metadata");
|
2018-04-05 16:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IMB_metadata_free(struct IDProperty *metadata)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (metadata == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-01-31 17:15:43 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IDP_FreeProperty(metadata);
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool IMB_metadata_get_field(struct IDProperty *metadata,
|
|
|
|
|
const char *key,
|
|
|
|
|
char *field,
|
|
|
|
|
const size_t len)
|
2007-09-02 17:25:03 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *prop;
|
2015-01-31 17:15:43 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (metadata == NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-01-31 17:15:43 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
prop = IDP_GetPropertyFromGroup(metadata, key);
|
2015-01-31 17:15:43 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (prop && prop->type == IDP_STRING) {
|
|
|
|
|
BLI_strncpy(field, IDP_String(prop), len);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2007-09-02 17:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-20 19:57:57 +02:00
|
|
|
void IMB_metadata_copy(struct ImBuf *dimb, struct ImBuf *simb)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(dimb != simb);
|
|
|
|
|
if (simb->metadata) {
|
|
|
|
|
IMB_metadata_free(dimb->metadata);
|
|
|
|
|
dimb->metadata = IDP_CopyProperty(simb->metadata);
|
|
|
|
|
}
|
2015-04-20 19:57:57 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 16:27:15 +02:00
|
|
|
void IMB_metadata_set_field(struct IDProperty *metadata, const char *key, const char *value)
|
2007-09-02 17:25:03 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(metadata);
|
|
|
|
|
IDProperty *prop = IDP_GetPropertyFromGroup(metadata, key);
|
2007-09-02 17:25:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (prop != NULL && prop->type != IDP_STRING) {
|
|
|
|
|
IDP_FreeFromGroup(metadata, prop);
|
|
|
|
|
prop = NULL;
|
|
|
|
|
}
|
2015-01-31 17:15:43 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (prop == NULL) {
|
|
|
|
|
prop = IDP_NewString(value, key, METADATA_MAX_VALUE_LENGTH);
|
|
|
|
|
IDP_AddToGroup(metadata, prop);
|
|
|
|
|
}
|
2007-10-20 16:17:27 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IDP_AssignString(prop, value, METADATA_MAX_VALUE_LENGTH);
|
2007-10-20 16:17:27 +00:00
|
|
|
}
|
2019-02-06 11:49:41 +01:00
|
|
|
|
|
|
|
|
void IMB_metadata_foreach(struct ImBuf *ibuf, IMBMetadataForeachCb callback, void *userdata)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ibuf->metadata == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (IDProperty *prop = ibuf->metadata->data.group.first; prop != NULL; prop = prop->next) {
|
|
|
|
|
callback(prop->name, IDP_String(prop), userdata);
|
|
|
|
|
}
|
2019-02-06 11:49:41 +01:00
|
|
|
}
|