Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/imbuf/intern')
-rw-r--r--source/blender/imbuf/intern/IMB_metadata.h7
-rw-r--r--source/blender/imbuf/intern/anim_movie.c24
-rw-r--r--source/blender/imbuf/intern/bmp.c90
-rw-r--r--source/blender/imbuf/intern/cineon/dpxlib.c6
-rw-r--r--source/blender/imbuf/intern/colormanagement.c18
-rw-r--r--source/blender/imbuf/intern/divers.c10
-rw-r--r--source/blender/imbuf/intern/indexer.c69
-rw-r--r--source/blender/imbuf/intern/jpeg.c46
-rw-r--r--source/blender/imbuf/intern/metadata.c105
-rw-r--r--source/blender/imbuf/intern/moviecache.c45
-rw-r--r--source/blender/imbuf/intern/openexr/openexr_api.cpp17
-rw-r--r--source/blender/imbuf/intern/png.c30
-rw-r--r--source/blender/imbuf/intern/thumbs_blend.c2
-rw-r--r--source/blender/imbuf/intern/tiff.c6
14 files changed, 258 insertions, 217 deletions
diff --git a/source/blender/imbuf/intern/IMB_metadata.h b/source/blender/imbuf/intern/IMB_metadata.h
index a717764b44f..5d4a0028ee1 100644
--- a/source/blender/imbuf/intern/IMB_metadata.h
+++ b/source/blender/imbuf/intern/IMB_metadata.h
@@ -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
diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c
index b8f6e66adfe..ffdecb793aa 100644
--- a/source/blender/imbuf/intern/anim_movie.c
+++ b/source/blender/imbuf/intern/anim_movie.c
@@ -1314,25 +1314,27 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim, int position,
filter_y = (anim->ib_flags & IB_animdeinterlace);
- if (anim->curtype == 0) {
- ibuf = anim_getnew(anim);
- if (ibuf == NULL) {
- return(NULL);
+ if (preview_size == IMB_PROXY_NONE) {
+ if (anim->curtype == 0) {
+ ibuf = anim_getnew(anim);
+ if (ibuf == NULL) {
+ return(NULL);
+ }
+
+ IMB_freeImBuf(ibuf); /* ???? */
+ ibuf = NULL;
}
- IMB_freeImBuf(ibuf); /* ???? */
- ibuf = NULL;
+ if (position < 0) return(NULL);
+ if (position >= anim->duration) return(NULL);
}
-
- if (position < 0) return(NULL);
- if (position >= anim->duration) return(NULL);
-
- if (preview_size != IMB_PROXY_NONE) {
+ else {
struct anim *proxy = IMB_anim_open_proxy(anim, preview_size);
if (proxy) {
position = IMB_anim_index_get_frame_index(
anim, tc, position);
+
return IMB_anim_absolute(
proxy, position,
IMB_TC_NONE, IMB_PROXY_NONE);
diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c
index 8853fe449ba..f8cf1164e4f 100644
--- a/source/blender/imbuf/intern/bmp.c
+++ b/source/blender/imbuf/intern/bmp.c
@@ -72,22 +72,24 @@ typedef struct BMPHEADER {
#define BMP_FILEHEADER_SIZE 14
+#define CHECK_HEADER_FIELD(_mem, _field) ((_mem[0] == _field[0]) && (_mem[1] == _field[1]))
+#define CHECK_HEADER_FIELD_BMP(_mem) \
+ (CHECK_HEADER_FIELD(_mem, "BM") || \
+ CHECK_HEADER_FIELD(_mem, "BA") || \
+ CHECK_HEADER_FIELD(_mem, "CI") || \
+ CHECK_HEADER_FIELD(_mem, "CP") || \
+ CHECK_HEADER_FIELD(_mem, "IC") || \
+ CHECK_HEADER_FIELD(_mem, "PT"))
+
static int checkbmp(unsigned char *mem)
{
-#define CHECK_HEADER_FIELD(mem, field) ((mem[0] == field[0]) && (mem[1] == field[1]))
int ret_val = 0;
BMPINFOHEADER bmi;
unsigned int u;
if (mem) {
- if (CHECK_HEADER_FIELD(mem, "BM") ||
- CHECK_HEADER_FIELD(mem, "BA") ||
- CHECK_HEADER_FIELD(mem, "CI") ||
- CHECK_HEADER_FIELD(mem, "CP") ||
- CHECK_HEADER_FIELD(mem, "IC") ||
- CHECK_HEADER_FIELD(mem, "PT"))
- {
+ if (CHECK_HEADER_FIELD_BMP(mem)) {
/* skip fileheader */
mem += BMP_FILEHEADER_SIZE;
}
@@ -111,8 +113,6 @@ static int checkbmp(unsigned char *mem)
}
return(ret_val);
-
-#undef CHECK_HEADER_FIELD
}
int imb_is_a_bmp(unsigned char *buf)
@@ -124,10 +124,11 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags, char co
{
struct ImBuf *ibuf = NULL;
BMPINFOHEADER bmi;
- int x, y, depth, ibuf_depth, skip, i;
+ int x, y, depth, ibuf_depth, skip, i, j;
unsigned char *bmp, *rect;
unsigned short col;
double xppm, yppm;
+ bool top_to_bottom = false;
(void)size; /* unused */
@@ -135,7 +136,7 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags, char co
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
- if ((mem[0] == 'B') && (mem[1] == 'M')) {
+ if (CHECK_HEADER_FIELD_BMP(mem)) {
/* skip fileheader */
mem += BMP_FILEHEADER_SIZE;
}
@@ -157,11 +158,14 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags, char co
ibuf_depth = depth;
}
+ if (y < 0) {
+ /* Negative height means bitmap is stored top-to-bottom... */
+ y = -y;
+ top_to_bottom = true;
+ }
+
#if 0
- printf("skip: %d, x: %d y: %d, depth: %d (%x)\n", skip, x, y,
- depth, bmi.biBitCount);
- printf("skip: %d, x: %d y: %d, depth: %d (%x)\n", skip, x, y,
- depth, bmi.biBitCount);
+ printf("skip: %d, x: %d y: %d, depth: %d (%x)\n", skip, x, y, depth, bmi.biBitCount);
#endif
if (flags & IB_test) {
@@ -177,7 +181,9 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags, char co
const char (*palette)[4] = (void *)bmp;
bmp += bmi.biClrUsed * 4;
for (i = y; i > 0; i--) {
- int j;
+ if (top_to_bottom) {
+ rect = (unsigned char *) &ibuf->rect[(i - 1) * x];
+ }
for (j = x; j > 0; j--) {
const char *pcol = palette[bmp[0]];
rect[0] = pcol[0];
@@ -192,21 +198,27 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags, char co
}
}
else if (depth == 16) {
- for (i = x * y; i > 0; i--) {
- col = bmp[0] + (bmp[1] << 8);
- rect[0] = ((col >> 10) & 0x1f) << 3;
- rect[1] = ((col >> 5) & 0x1f) << 3;
- rect[2] = ((col >> 0) & 0x1f) << 3;
-
- rect[3] = 255;
- rect += 4; bmp += 2;
- }
+ for (i = y; i > 0; i--) {
+ if (top_to_bottom) {
+ rect = (unsigned char *) &ibuf->rect[(i - 1) * x];
+ }
+ for (j = x; j > 0; j--) {
+ col = bmp[0] + (bmp[1] << 8);
+ rect[0] = ((col >> 10) & 0x1f) << 3;
+ rect[1] = ((col >> 5) & 0x1f) << 3;
+ rect[2] = ((col >> 0) & 0x1f) << 3;
+ rect[3] = 255;
+ rect += 4; bmp += 2;
+ }
+ }
}
else if (depth == 24) {
const int x_pad = x % 4;
for (i = y; i > 0; i--) {
- int j;
+ if (top_to_bottom) {
+ rect = (unsigned char *) &ibuf->rect[(i - 1) * x];
+ }
for (j = x; j > 0; j--) {
rect[0] = bmp[2];
rect[1] = bmp[1];
@@ -220,12 +232,17 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags, char co
}
}
else if (depth == 32) {
- for (i = x * y; i > 0; i--) {
- rect[0] = bmp[2];
- rect[1] = bmp[1];
- rect[2] = bmp[0];
- rect[3] = bmp[3];
- rect += 4; bmp += 4;
+ for (i = y; i > 0; i--) {
+ if (top_to_bottom) {
+ rect = (unsigned char *) &ibuf->rect[(i - 1) * x];
+ }
+ for (j = x; j > 0; j--) {
+ rect[0] = bmp[2];
+ rect[1] = bmp[1];
+ rect[2] = bmp[0];
+ rect[3] = bmp[3];
+ rect += 4; bmp += 4;
+ }
}
}
}
@@ -239,6 +256,9 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags, char co
return(ibuf);
}
+#undef CHECK_HEADER_FIELD_BMP
+#undef CHECK_HEADER_FIELD
+
/* Couple of helper functions for writing our data */
static int putIntLSB(unsigned int ui, FILE *ofile)
{
@@ -298,7 +318,9 @@ int imb_savebmp(struct ImBuf *ibuf, const char *name, int flags)
if (putc(data[ptr], ofile) == EOF) return 0;
}
/* add padding here */
- for (t = 0; t < extrabytes; t++) if (putc(0, ofile) == EOF) return 0;
+ for (t = 0; t < extrabytes; t++) {
+ if (putc(0, ofile) == EOF) return 0;
+ }
}
if (ofile) {
fflush(ofile);
diff --git a/source/blender/imbuf/intern/cineon/dpxlib.c b/source/blender/imbuf/intern/cineon/dpxlib.c
index f7362d76913..23e5517bb09 100644
--- a/source/blender/imbuf/intern/cineon/dpxlib.c
+++ b/source/blender/imbuf/intern/cineon/dpxlib.c
@@ -183,8 +183,10 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
if (verbose) printf("DPX: File is LSB.\n");
}
else {
- if (verbose) printf("DPX: Bad magic number %lu in \"%s\".\n",
- (uintptr_t)header.fileHeader.magic_num, byteStuff);
+ if (verbose) {
+ printf("DPX: Bad magic number %lu in \"%s\".\n",
+ (uintptr_t)header.fileHeader.magic_num, byteStuff);
+ }
logImageClose(dpx);
return NULL;
}
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
index 049d8bdcff1..95e166b2f8b 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -1141,7 +1141,7 @@ void IMB_colormanagement_validate_settings(ColorManagedDisplaySettings *display_
for (view_link = display->views.first; view_link; view_link = view_link->next) {
ColorManagedView *view = view_link->data;
- if (!strcmp(view->name, view_settings->view_transform))
+ if (STREQ(view->name, view_settings->view_transform))
break;
}
@@ -1496,7 +1496,7 @@ static bool is_ibuf_rect_in_display_space(ImBuf *ibuf, const ColorManagedViewSet
const char *from_colorspace = ibuf->rect_colorspace->name;
const char *to_colorspace = IMB_colormanagement_get_display_colorspace_name(view_settings, display_settings);
- if (to_colorspace && !strcmp(from_colorspace, to_colorspace))
+ if (to_colorspace && STREQ(from_colorspace, to_colorspace))
return true;
}
@@ -1625,7 +1625,7 @@ static void colormanagement_transform_ex(float *buffer, int width, int height, i
return;
}
- if (!strcmp(from_colorspace, to_colorspace)) {
+ if (STREQ(from_colorspace, to_colorspace)) {
/* if source and destination color spaces are identical, skip
* threading overhead and simply do nothing
*/
@@ -1666,7 +1666,7 @@ void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspac
return;
}
- if (!strcmp(from_colorspace, to_colorspace)) {
+ if (STREQ(from_colorspace, to_colorspace)) {
/* if source and destination color spaces are identical, skip
* threading overhead and simply do nothing
*/
@@ -1918,7 +1918,7 @@ ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf, bool save_as_render, boo
* should be pretty safe since this image buffer is supposed to be used for
* saving only and ftype would be overwritten a bit later by BKE_imbuf_write
*/
- colormanaged_ibuf->ftype = BKE_imtype_to_ftype(image_format_data->imtype);
+ colormanaged_ibuf->ftype = BKE_image_imtype_to_ftype(image_format_data->imtype);
/* if file format isn't able to handle float buffer itself,
* we need to allocate byte buffer and store color managed
@@ -2152,7 +2152,7 @@ ColorManagedDisplay *colormanage_display_get_named(const char *name)
ColorManagedDisplay *display;
for (display = global_displays.first; display; display = display->next) {
- if (!strcmp(display->name, name))
+ if (STREQ(display->name, name))
return display;
}
@@ -2257,7 +2257,7 @@ ColorManagedView *colormanage_view_get_named(const char *name)
ColorManagedView *view;
for (view = global_views.first; view; view = view->next) {
- if (!strcmp(view->name, name))
+ if (STREQ(view->name, name))
return view;
}
@@ -2373,7 +2373,7 @@ ColorSpace *colormanage_colorspace_get_named(const char *name)
ColorSpace *colorspace;
for (colorspace = global_colorspaces.first; colorspace; colorspace = colorspace->next) {
- if (!strcmp(colorspace->name, name))
+ if (STREQ(colorspace->name, name))
return colorspace;
}
@@ -2459,7 +2459,7 @@ ColorManagedLook *colormanage_look_get_named(const char *name)
ColorManagedLook *look;
for (look = global_looks.first; look; look = look->next) {
- if (!strcmp(look->name, name)) {
+ if (STREQ(look->name, name)) {
return look;
}
}
diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c
index 81aef4ac6e4..59d08128e5f 100644
--- a/source/blender/imbuf/intern/divers.c
+++ b/source/blender/imbuf/intern/divers.c
@@ -122,16 +122,6 @@ static void clear_dither_context(DitherContext *di)
MEM_freeN(di);
}
-MINLINE float dither_random_value(float s, float t)
-{
- static float vec[2] = {12.9898f, 78.233f};
- float st[2];
- float value;
- copy_v2_fl2(st, s, t);
-
- value = sinf(dot_v2v2(st, vec)) * 43758.5453f;
- return value - floorf(value);
-}
/************************* Generic Buffer Conversion *************************/
diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c
index e66be77ecaf..d0281744830 100644
--- a/source/blender/imbuf/intern/indexer.c
+++ b/source/blender/imbuf/intern/indexer.c
@@ -35,6 +35,7 @@
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_fileops.h"
+#include "BLI_ghash.h"
#include "IMB_indexer.h"
#include "IMB_anim.h"
@@ -1148,19 +1149,64 @@ static void index_rebuild_fallback(FallbackIndexBuilderContext *context,
* ---------------------------------------------------------------------- */
IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim, IMB_Timecode_Type tcs_in_use,
- IMB_Proxy_Size proxy_sizes_in_use, int quality)
+ IMB_Proxy_Size proxy_sizes_in_use, int quality,
+ const bool overwrite, GSet *file_list)
{
IndexBuildContext *context = NULL;
+ IMB_Proxy_Size proxy_sizes_to_build = proxy_sizes_in_use;
+ int i;
+
+ /* Don't generate the same file twice! */
+ if (file_list) {
+ for (i = 0; i < IMB_PROXY_MAX_SLOT; ++i) {
+ IMB_Proxy_Size proxy_size = proxy_sizes[i];
+ if (proxy_size & proxy_sizes_to_build) {
+ char filename[FILE_MAX];
+ get_proxy_filename(anim, proxy_size, filename, false);
+
+ if (BLI_gset_haskey(file_list, filename)) {
+ proxy_sizes_to_build &= ~proxy_size;
+ printf("Proxy: %s already registered for generation, skipping\n", filename);
+ }
+ else {
+ BLI_gset_insert(file_list, BLI_strdup(filename));
+ }
+ }
+ }
+ }
+
+ if (!overwrite) {
+ IMB_Proxy_Size built_proxies = IMB_anim_proxy_get_existing(anim);
+ if (built_proxies != 0) {
+
+ for (i = 0; i < IMB_PROXY_MAX_SLOT; ++i) {
+ IMB_Proxy_Size proxy_size = proxy_sizes[i];
+ if (proxy_size & built_proxies) {
+ char filename[FILE_MAX];
+ get_proxy_filename(anim, proxy_size, filename, false);
+ printf("Skipping proxy: %s\n", filename);
+ }
+ }
+ }
+ proxy_sizes_to_build &= ~built_proxies;
+ }
+
+ fflush(stdout);
+
+ if (proxy_sizes_to_build == 0) {
+ return NULL;
+ }
+
switch (anim->curtype) {
#ifdef WITH_FFMPEG
case ANIM_FFMPEG:
- context = index_ffmpeg_create_context(anim, tcs_in_use, proxy_sizes_in_use, quality);
+ context = index_ffmpeg_create_context(anim, tcs_in_use, proxy_sizes_to_build, quality);
break;
#endif
#ifdef WITH_AVI
default:
- context = index_fallback_create_context(anim, tcs_in_use, proxy_sizes_in_use, quality);
+ context = index_fallback_create_context(anim, tcs_in_use, proxy_sizes_to_build, quality);
break;
#endif
}
@@ -1237,7 +1283,7 @@ void IMB_free_indices(struct anim *anim)
void IMB_anim_set_index_dir(struct anim *anim, const char *dir)
{
- if (strcmp(anim->index_dir, dir) == 0) {
+ if (STREQ(anim->index_dir, dir)) {
return;
}
BLI_strncpy(anim->index_dir, dir, sizeof(anim->index_dir));
@@ -1304,3 +1350,18 @@ int IMB_anim_index_get_frame_index(struct anim *anim, IMB_Timecode_Type tc,
return IMB_indexer_get_frame_index(idx, position);
}
+IMB_Proxy_Size IMB_anim_proxy_get_existing(struct anim *anim)
+{
+ const int num_proxy_sizes = IMB_PROXY_MAX_SLOT;
+ IMB_Proxy_Size existing = 0;
+ int i;
+ for (i = 0; i < num_proxy_sizes; ++i) {
+ IMB_Proxy_Size proxy_size = proxy_sizes[i];
+ char filename[FILE_MAX];
+ get_proxy_filename(anim, proxy_size, filename, false);
+ if (BLI_exists(filename)) {
+ existing |= proxy_size;
+ }
+ }
+ return existing;
+}
diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c
index f4b5f987869..310e517e38d 100644
--- a/source/blender/imbuf/intern/jpeg.c
+++ b/source/blender/imbuf/intern/jpeg.c
@@ -37,9 +37,12 @@
#include "MEM_guardedalloc.h"
+#include "BLI_utildefines.h"
#include "BLI_string.h"
#include "BLI_fileops.h"
+#include "BKE_idprop.h"
+
#include "imbuf.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
@@ -267,7 +270,7 @@ handle_app1(j_decompress_ptr cinfo)
if (length < 16) {
for (i = 0; i < length; i++) INPUT_BYTE(cinfo, neogeo[i], return false);
length = 0;
- if (strncmp(neogeo, "NeoGeo", 6) == 0) memcpy(&ibuf_ftype, neogeo + 6, 4);
+ if (STREQLEN(neogeo, "NeoGeo", 6)) memcpy(&ibuf_ftype, neogeo + 6, 4);
ibuf_ftype = BIG_LONG(ibuf_ftype);
}
INPUT_SYNC(cinfo); /* do before skip_input_data */
@@ -385,7 +388,7 @@ static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int fla
* That is why we need split it to the
* common key/value here.
*/
- if (strncmp(str, "Blender", 7)) {
+ if (!STREQLEN(str, "Blender", 7)) {
/*
* Maybe the file have text that
* we don't know "what it's", in that
@@ -478,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);
@@ -490,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 (!strcmp(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);
}
diff --git a/source/blender/imbuf/intern/metadata.c b/source/blender/imbuf/intern/metadata.c
index 797d34d118b..8cb5070dd62 100644
--- a/source/blender/imbuf/intern/metadata.c
+++ b/source/blender/imbuf/intern/metadata.c
@@ -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 (strcmp(key, info->key) == 0) {
- 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;
- }
- else {
- info = img->metadata;
- last = info;
- while (info) {
- last = info;
- info = info->next;
- }
- info = MEM_callocN(sizeof(ImMetaData), "ImMetaData");
- last->next = info;
+ IDPropertyTemplate val;
+ img->metadata = IDP_New(IDP_GROUP, &val, "metadata");
}
- 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 (!strcmp(key, p->key)) {
- if (p1)
- p1->next = p->next;
- else
- img->metadata = p->next;
-
- MEM_freeN(p->key);
- MEM_freeN(p->value);
- MEM_freeN(p);
- return true;
- }
- p1 = p;
- p = p->next;
+ prop = IDP_GetPropertyFromGroup(img->metadata, key);
+
+ 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)
- return (IMB_metadata_add_field(img, key, field));
+ prop = (img->metadata) ? IDP_GetPropertyFromGroup(img->metadata, key) : NULL;
- p = img->metadata;
- while (p) {
- if (!strcmp(key, p->key)) {
- MEM_freeN(p->value);
- p->value = BLI_strdup(field);
- return true;
- }
- p = p->next;
+ if (!prop) {
+ return (IMB_metadata_add_field(img, key, field));
+ }
+ else if (prop->type == IDP_STRING) {
+ IDP_AssignString(prop, field, 1024);
+ return true;
+ }
+ else {
+ return false;
}
-
- return (IMB_metadata_add_field(img, key, field));
}
-
diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c
index cb789cc8491..29bb35986e8 100644
--- a/source/blender/imbuf/intern/moviecache.c
+++ b/source/blender/imbuf/intern/moviecache.c
@@ -142,15 +142,16 @@ static void moviecache_valfree(void *val)
static void check_unused_keys(MovieCache *cache)
{
- GHashIterator *iter;
+ GHashIterator gh_iter;
- iter = BLI_ghashIterator_new(cache->hash);
- while (!BLI_ghashIterator_done(iter)) {
- MovieCacheKey *key = BLI_ghashIterator_getKey(iter);
- MovieCacheItem *item = BLI_ghashIterator_getValue(iter);
- int remove = 0;
+ BLI_ghashIterator_init(&gh_iter, cache->hash);
+
+ while (!BLI_ghashIterator_done(&gh_iter)) {
+ MovieCacheKey *key = BLI_ghashIterator_getKey(&gh_iter);
+ MovieCacheItem *item = BLI_ghashIterator_getValue(&gh_iter);
+ bool remove;
- BLI_ghashIterator_step(iter);
+ BLI_ghashIterator_step(&gh_iter);
remove = !item->ibuf;
@@ -161,8 +162,6 @@ static void check_unused_keys(MovieCache *cache)
if (remove)
BLI_ghash_remove(cache->hash, key, moviecache_keyfree, moviecache_valfree);
}
-
- BLI_ghashIterator_free(iter);
}
static int compare_int(const void *av, const void *bv)
@@ -473,16 +472,17 @@ void IMB_moviecache_free(MovieCache *cache)
void IMB_moviecache_cleanup(MovieCache *cache, bool (cleanup_check_cb) (ImBuf *ibuf, void *userkey, void *userdata), void *userdata)
{
- GHashIterator *iter;
+ GHashIterator gh_iter;
check_unused_keys(cache);
- iter = BLI_ghashIterator_new(cache->hash);
- while (!BLI_ghashIterator_done(iter)) {
- MovieCacheKey *key = BLI_ghashIterator_getKey(iter);
- MovieCacheItem *item = BLI_ghashIterator_getValue(iter);
+ BLI_ghashIterator_init(&gh_iter, cache->hash);
+
+ while (!BLI_ghashIterator_done(&gh_iter)) {
+ MovieCacheKey *key = BLI_ghashIterator_getKey(&gh_iter);
+ MovieCacheItem *item = BLI_ghashIterator_getValue(&gh_iter);
- BLI_ghashIterator_step(iter);
+ BLI_ghashIterator_step(&gh_iter);
if (cleanup_check_cb(item->ibuf, key->userkey, userdata)) {
PRINT("%s: cache '%s' remove item %p\n", __func__, cache->name, item);
@@ -490,8 +490,6 @@ void IMB_moviecache_cleanup(MovieCache *cache, bool (cleanup_check_cb) (ImBuf *i
BLI_ghash_remove(cache->hash, key, moviecache_keyfree, moviecache_valfree);
}
}
-
- BLI_ghashIterator_free(iter);
}
/* get segments of cached frames. useful for debugging cache policies */
@@ -518,13 +516,12 @@ void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_
int totframe = BLI_ghash_size(cache->hash);
int *frames = MEM_callocN(totframe * sizeof(int), "movieclip cache frames");
int a, totseg = 0;
- GHashIterator *iter;
+ GHashIterator gh_iter;
- iter = BLI_ghashIterator_new(cache->hash);
a = 0;
- while (!BLI_ghashIterator_done(iter)) {
- MovieCacheKey *key = BLI_ghashIterator_getKey(iter);
- MovieCacheItem *item = BLI_ghashIterator_getValue(iter);
+ GHASH_ITER(gh_iter, cache->hash) {
+ MovieCacheKey *key = BLI_ghashIterator_getKey(&gh_iter);
+ MovieCacheItem *item = BLI_ghashIterator_getValue(&gh_iter);
int framenr, curproxy, curflags;
if (item->ibuf) {
@@ -533,12 +530,8 @@ void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_
if (curproxy == proxy && curflags == render_flags)
frames[a++] = framenr;
}
-
- BLI_ghashIterator_step(iter);
}
- BLI_ghashIterator_free(iter);
-
qsort(frames, totframe, sizeof(int), compare_int);
/* count */
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp
index ba1bda640a6..5de243845a4 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp
@@ -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 */
@@ -784,7 +791,7 @@ void IMB_exr_read_channels(void *handle)
/* check if exr was saved with previous versions of blender which flipped images */
const StringAttribute *ta = data->ifile->header().findTypedAttribute <StringAttribute> ("BlenderMultiChannel");
- short flip = (ta && strncmp(ta->value().c_str(), "Blender V2.43", 13) == 0); /* 'previous multilayer attribute, flipped */
+ short flip = (ta && STREQLEN(ta->value().c_str(), "Blender V2.43", 13)); /* 'previous multilayer attribute, flipped */
for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) {
@@ -982,7 +989,7 @@ static ExrPass *imb_exr_get_pass(ListBase *lb, char *passname)
if (pass == NULL) {
pass = (ExrPass *)MEM_callocN(sizeof(ExrPass), "exr pass");
- if (strcmp(passname, "Combined") == 0)
+ if (STREQ(passname, "Combined"))
BLI_addhead(lb, pass);
else
BLI_addtail(lb, pass);
diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c
index 3266dc97c78..683bdabcd6c 100644
--- a/source/blender/imbuf/intern/png.c
+++ b/source/blender/imbuf/intern/png.c
@@ -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);
@@ -490,7 +492,7 @@ static void imb_png_warning(png_structp UNUSED(png_ptr), png_const_charp message
* and with new libpng it became too much picky, giving a warning on
* the splash screen even.
*/
- if ((G.debug & G_DEBUG) == 0 && !strncmp(message, "iCCP", 4)) {
+ if ((G.debug & G_DEBUG) == 0 && STREQLEN(message, "iCCP", 4)) {
return;
}
fprintf(stderr, "libpng warning: %s\n", message);
diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c
index af353461f1f..aee465c49cc 100644
--- a/source/blender/imbuf/intern/thumbs_blend.c
+++ b/source/blender/imbuf/intern/thumbs_blend.c
@@ -55,7 +55,7 @@ static ImBuf *loadblend_thumb(gzFile gzfile)
/* read the blend file header */
if (gzread(gzfile, buf, 12) != 12)
return NULL;
- if (strncmp(buf, "BLENDER", 7))
+ if (!STREQLEN(buf, "BLENDER", 7))
return NULL;
if (buf[7] == '-')
diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c
index e3b8e271387..4d58642e9c4 100644
--- a/source/blender/imbuf/intern/tiff.c
+++ b/source/blender/imbuf/intern/tiff.c
@@ -309,8 +309,8 @@ int imb_is_a_tiff(unsigned char *mem)
char big_endian[IMB_TIFF_NCB] = { 0x4d, 0x4d, 0x00, 0x2a };
char lil_endian[IMB_TIFF_NCB] = { 0x49, 0x49, 0x2a, 0x00 };
- return ( (memcmp(big_endian, mem, IMB_TIFF_NCB) == 0) ||
- (memcmp(lil_endian, mem, IMB_TIFF_NCB) == 0) );
+ return ((memcmp(big_endian, mem, IMB_TIFF_NCB) == 0) ||
+ (memcmp(lil_endian, mem, IMB_TIFF_NCB) == 0));
}
static void scanline_contig_16bit(float *rectf, const unsigned short *sbuf, int scanline_w, int spp)
@@ -594,7 +594,7 @@ ImBuf *imb_loadtiff(unsigned char *mem, size_t size, int flags, char colorspace[
format = NULL;
TIFFGetField(image, TIFFTAG_PIXAR_TEXTUREFORMAT, &format);
- if (format && strcmp(format, "Plain Texture") == 0 && TIFFIsTiled(image)) {
+ if (format && STREQ(format, "Plain Texture") && TIFFIsTiled(image)) {
int numlevel = TIFFNumberOfDirectories(image);
/* create empty mipmap levels in advance */