Blender metadata changes to accommodate non string data
Work towards T42418 For now got rid of linked list holding key,value pairs for metadata in favour of ID properties. Reviewers: campbellbarton, sergey Reviewed By: sergey Projects: #bf_blender Differential Revision: https://developer.blender.org/D872
This commit is contained in:
@@ -47,8 +47,6 @@
|
||||
* contains an Amiga-format file).
|
||||
*/
|
||||
|
||||
struct ImMetaData;
|
||||
|
||||
#define IB_MIPMAP_LEVELS 20
|
||||
#define IB_FILENAME_SIZE 1024
|
||||
|
||||
@@ -111,7 +109,7 @@ typedef struct ImBuf {
|
||||
/* externally used data */
|
||||
int index; /* reference index for ImBuf lists */
|
||||
int userflags; /* used to set imbuf to dirty and other stuff */
|
||||
struct ImMetaData *metadata; /* image metadata */
|
||||
struct IDProperty *metadata; /* image metadata */
|
||||
void *userdata; /* temporary storage, only used by baking at the moment */
|
||||
|
||||
/* file information */
|
||||
|
||||
@@ -35,13 +35,6 @@
|
||||
|
||||
struct ImBuf;
|
||||
|
||||
typedef struct ImMetaData {
|
||||
struct ImMetaData *next, *prev;
|
||||
char *key;
|
||||
char *value;
|
||||
int len;
|
||||
} ImMetaData;
|
||||
|
||||
/** The metadata is a list of key/value pairs (both char *) that can me
|
||||
* saved in the header of several image formats.
|
||||
* Apart from some common keys like
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_fileops.h"
|
||||
|
||||
#include "BKE_idprop.h"
|
||||
|
||||
#include "imbuf.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
#include "IMB_imbuf.h"
|
||||
@@ -479,7 +481,6 @@ static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
|
||||
uchar *rect;
|
||||
int x, y;
|
||||
char neogeo[128];
|
||||
ImMetaData *iptr;
|
||||
char *text;
|
||||
|
||||
jpeg_start_compress(cinfo, true);
|
||||
@@ -491,28 +492,28 @@ static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
|
||||
jpeg_write_marker(cinfo, 0xe1, (JOCTET *) neogeo, 10);
|
||||
|
||||
if (ibuf->metadata) {
|
||||
IDProperty *prop;
|
||||
/* key + max value + "Blender" */
|
||||
text = MEM_mallocN(530, "stamp info read");
|
||||
iptr = ibuf->metadata;
|
||||
while (iptr) {
|
||||
if (STREQ(iptr->key, "None")) {
|
||||
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) iptr->value, strlen(iptr->value) + 1);
|
||||
goto next_stamp_info;
|
||||
}
|
||||
for (prop = ibuf->metadata->data.group.first; prop; prop = prop->next) {
|
||||
if (prop->type == IDP_STRING) {
|
||||
int text_len;
|
||||
if (!strcmp(prop->name, "None")) {
|
||||
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) IDP_String(prop), prop->len + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* The JPEG format don't support a pair "key/value"
|
||||
* like PNG, so we "encode" the stamp in a
|
||||
* single string:
|
||||
* "Blender:key:value"
|
||||
*
|
||||
* The first "Blender" is a simple identify to help
|
||||
* in the read process.
|
||||
*/
|
||||
sprintf(text, "Blender:%s:%s", iptr->key, iptr->value);
|
||||
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) text, strlen(text) + 1);
|
||||
next_stamp_info:
|
||||
iptr = iptr->next;
|
||||
/*
|
||||
* The JPEG format don't support a pair "key/value"
|
||||
* like PNG, so we "encode" the stamp in a
|
||||
* single string:
|
||||
* "Blender:key:value"
|
||||
*
|
||||
* The first "Blender" is a simple identify to help
|
||||
* in the read process.
|
||||
*/
|
||||
text_len = sprintf(text, "Blender:%s:%s", prop->name, IDP_String(prop));
|
||||
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) text, text_len + 1);
|
||||
}
|
||||
}
|
||||
MEM_freeN(text);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_string.h"
|
||||
|
||||
#include "BKE_idprop.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "IMB_imbuf_types.h"
|
||||
@@ -47,119 +49,84 @@
|
||||
|
||||
void IMB_metadata_free(struct ImBuf *img)
|
||||
{
|
||||
ImMetaData *info;
|
||||
|
||||
if (!img)
|
||||
return;
|
||||
if (!img->metadata) {
|
||||
return;
|
||||
}
|
||||
info = img->metadata;
|
||||
while (info) {
|
||||
ImMetaData *next = info->next;
|
||||
MEM_freeN(info->key);
|
||||
MEM_freeN(info->value);
|
||||
MEM_freeN(info);
|
||||
info = next;
|
||||
}
|
||||
|
||||
IDP_FreeProperty(img->metadata);
|
||||
MEM_freeN(img->metadata);
|
||||
}
|
||||
|
||||
bool IMB_metadata_get_field(struct ImBuf *img, const char *key, char *field, const size_t len)
|
||||
{
|
||||
ImMetaData *info;
|
||||
IDProperty *prop;
|
||||
|
||||
bool retval = false;
|
||||
|
||||
if (!img)
|
||||
return false;
|
||||
if (!img->metadata) {
|
||||
if (!img->metadata)
|
||||
return false;
|
||||
}
|
||||
info = img->metadata;
|
||||
while (info) {
|
||||
if (STREQ(key, info->key)) {
|
||||
BLI_strncpy(field, info->value, len);
|
||||
retval = true;
|
||||
break;
|
||||
}
|
||||
info = info->next;
|
||||
|
||||
prop = IDP_GetPropertyFromGroup(img->metadata ,key);
|
||||
|
||||
if(prop && prop->type == IDP_STRING){
|
||||
BLI_strncpy(field, IDP_String(prop), len);
|
||||
retval = true;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool IMB_metadata_add_field(struct ImBuf *img, const char *key, const char *value)
|
||||
{
|
||||
ImMetaData *info;
|
||||
ImMetaData *last;
|
||||
IDProperty *prop;
|
||||
|
||||
if (!img)
|
||||
return false;
|
||||
|
||||
if (!img->metadata) {
|
||||
img->metadata = MEM_callocN(sizeof(ImMetaData), "ImMetaData");
|
||||
info = img->metadata;
|
||||
IDPropertyTemplate val;
|
||||
img->metadata = IDP_New(IDP_GROUP, &val, "metadata");
|
||||
}
|
||||
else {
|
||||
info = img->metadata;
|
||||
last = info;
|
||||
while (info) {
|
||||
last = info;
|
||||
info = info->next;
|
||||
}
|
||||
info = MEM_callocN(sizeof(ImMetaData), "ImMetaData");
|
||||
last->next = info;
|
||||
}
|
||||
info->key = BLI_strdup(key);
|
||||
info->value = BLI_strdup(value);
|
||||
return true;
|
||||
|
||||
prop = IDP_NewString(value, key, 512);
|
||||
return IDP_AddToGroup(img->metadata, prop);
|
||||
}
|
||||
|
||||
bool IMB_metadata_del_field(struct ImBuf *img, const char *key)
|
||||
{
|
||||
ImMetaData *p, *p1;
|
||||
IDProperty *prop;
|
||||
|
||||
if ((!img) || (!img->metadata))
|
||||
return false;
|
||||
|
||||
p = img->metadata;
|
||||
p1 = NULL;
|
||||
while (p) {
|
||||
if (STREQ(key, p->key)) {
|
||||
if (p1)
|
||||
p1->next = p->next;
|
||||
else
|
||||
img->metadata = p->next;
|
||||
prop = IDP_GetPropertyFromGroup(img->metadata, key);
|
||||
|
||||
MEM_freeN(p->key);
|
||||
MEM_freeN(p->value);
|
||||
MEM_freeN(p);
|
||||
return true;
|
||||
}
|
||||
p1 = p;
|
||||
p = p->next;
|
||||
if (prop) {
|
||||
IDP_FreeFromGroup(img->metadata, prop);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field)
|
||||
{
|
||||
ImMetaData *p;
|
||||
IDProperty *prop;
|
||||
|
||||
if (!img)
|
||||
return false;
|
||||
|
||||
if (!img->metadata)
|
||||
prop = (img->metadata) ? IDP_GetPropertyFromGroup(img->metadata, key) : NULL;
|
||||
|
||||
if (!prop) {
|
||||
return (IMB_metadata_add_field(img, key, field));
|
||||
|
||||
p = img->metadata;
|
||||
while (p) {
|
||||
if (STREQ(key, p->key)) {
|
||||
MEM_freeN(p->value);
|
||||
p->value = BLI_strdup(field);
|
||||
return true;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
return (IMB_metadata_add_field(img, key, field));
|
||||
else if (prop->type == IDP_STRING) {
|
||||
IDP_AssignString(prop, field, 1024);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ _CRTIMP void __cdecl _invalid_parameter_noinfo(void)
|
||||
#include "BLI_math_color.h"
|
||||
#include "BLI_threads.h"
|
||||
|
||||
#include "BKE_idprop.h"
|
||||
|
||||
#include "IMB_imbuf_types.h"
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_allocimbuf.h"
|
||||
@@ -305,10 +307,15 @@ static void openexr_header_compression(Header *header, int compression)
|
||||
|
||||
static void openexr_header_metadata(Header *header, struct ImBuf *ibuf)
|
||||
{
|
||||
ImMetaData *info;
|
||||
if (ibuf->metadata) {
|
||||
IDProperty *prop;
|
||||
|
||||
for (info = ibuf->metadata; info; info = info->next)
|
||||
header->insert(info->key, StringAttribute(info->value));
|
||||
for (prop = (IDProperty *)ibuf->metadata->data.group.first; prop; prop = prop->next) {
|
||||
if (prop->type == IDP_STRING) {
|
||||
header->insert(prop->name, StringAttribute(IDP_String(prop)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ibuf->ppm[0] > 0.0)
|
||||
addXDensity(*header, ibuf->ppm[0] / 39.3700787); /* 1 meter = 39.3700787 inches */
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "BLI_math.h"
|
||||
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_idprop.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
@@ -397,24 +398,25 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
|
||||
/* image text info */
|
||||
if (ibuf->metadata) {
|
||||
png_text *metadata;
|
||||
ImMetaData *iptr;
|
||||
IDProperty *prop;
|
||||
|
||||
int num_text = 0;
|
||||
iptr = ibuf->metadata;
|
||||
while (iptr) {
|
||||
num_text++;
|
||||
iptr = iptr->next;
|
||||
|
||||
for (prop = ibuf->metadata->data.group.first; prop; prop = prop->next) {
|
||||
if (prop->type == IDP_STRING){
|
||||
num_text++;
|
||||
}
|
||||
}
|
||||
|
||||
metadata = MEM_callocN(num_text * sizeof(png_text), "png_metadata");
|
||||
iptr = ibuf->metadata;
|
||||
num_text = 0;
|
||||
while (iptr) {
|
||||
|
||||
metadata[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
metadata[num_text].key = iptr->key;
|
||||
metadata[num_text].text = iptr->value;
|
||||
num_text++;
|
||||
iptr = iptr->next;
|
||||
for (prop = ibuf->metadata->data.group.first; prop; prop = prop->next) {
|
||||
if (prop->type == IDP_STRING){
|
||||
metadata[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
metadata[num_text].key = prop->name;
|
||||
metadata[num_text].text = IDP_String(prop);
|
||||
num_text++;
|
||||
}
|
||||
}
|
||||
|
||||
png_set_text(png_ptr, info_ptr, metadata, num_text);
|
||||
|
||||
Reference in New Issue
Block a user