[Bf-blender-cvs] [3c86a19] master: Code cleanup: add BLI_testextensie_n, replacing multuple calls to BLI_testextensie
Campbell Barton
noreply at git.blender.org
Thu Jan 30 17:31:55 CET 2014
Commit: 3c86a1932f848f694ba3a88bb1af35325f3f89a2
Author: Campbell Barton
Date: Fri Jan 31 03:09:01 2014 +1100
https://developer.blender.org/rB3c86a1932f848f694ba3a88bb1af35325f3f89a2
Code cleanup: add BLI_testextensie_n, replacing multuple calls to BLI_testextensie
also use attributes for BLI path functions
===================================================================
M source/blender/blenkernel/BKE_image.h
M source/blender/blenkernel/intern/idcode.c
M source/blender/blenkernel/intern/image.c
M source/blender/blenkernel/intern/sequencer.c
M source/blender/blenlib/BLI_path_util.h
M source/blender/blenlib/intern/path_util.c
M source/blender/blenloader/BLO_readfile.h
M source/blender/blenloader/intern/readfile.c
M source/blender/editors/space_file/filelist.c
M source/blender/imbuf/intern/util.c
M source/blender/quicktime/apple/qtkit_import.m
===================================================================
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index 65540d7..a44a9e0 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -153,6 +153,7 @@ struct ImBuf *BKE_image_pool_acquire_ibuf(struct Image *ima, struct ImageUser *i
void BKE_image_pool_release_ibuf(struct Image *ima, struct ImBuf *ibuf, struct ImagePool *pool);
/* set an alpha mode based on file extension */
+char BKE_image_alpha_mode_from_extension_ex(const char *filepath);
void BKE_image_alpha_mode_from_extension(struct Image *image);
/* returns a new image or NULL if it can't load */
diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c
index c64c261..c987e0b 100644
--- a/source/blender/blenkernel/intern/idcode.c
+++ b/source/blender/blenkernel/intern/idcode.c
@@ -129,6 +129,7 @@ bool BKE_idcode_is_valid(int code)
bool BKE_idcode_is_linkable(int code)
{
IDType *idt = idtype_from_code(code);
+ BLI_assert(idt);
return idt ? ((idt->flags & IDTYPE_FLAGS_ISLINKABLE) != 0) : false;
}
@@ -142,7 +143,7 @@ bool BKE_idcode_is_linkable(int code)
const char *BKE_idcode_to_name(int code)
{
IDType *idt = idtype_from_code(code);
-
+ BLI_assert(idt);
return idt ? idt->name : NULL;
}
@@ -155,7 +156,7 @@ const char *BKE_idcode_to_name(int code)
int BKE_idcode_from_name(const char *name)
{
IDType *idt = idtype_from_name(name);
-
+ BLI_assert(idt);
return idt ? idt->code : 0;
}
@@ -169,7 +170,7 @@ int BKE_idcode_from_name(const char *name)
const char *BKE_idcode_to_name_plural(int code)
{
IDType *idt = idtype_from_code(code);
-
+ BLI_assert(idt);
return idt ? idt->plural : NULL;
}
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 3e93ab0..322f09f 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -598,20 +598,21 @@ static void image_init_color_management(Image *ima)
}
}
-void BKE_image_alpha_mode_from_extension(Image *image)
+char BKE_image_alpha_mode_from_extension_ex(const char *filepath)
{
- if (BLI_testextensie(image->name, ".exr") ||
- BLI_testextensie(image->name, ".cin") ||
- BLI_testextensie(image->name, ".dpx") ||
- BLI_testextensie(image->name, ".hdr"))
- {
- image->alpha_mode = IMA_ALPHA_PREMUL;
+ if (BLI_testextensie_n(filepath, ".exr", ".cin", ".dpx", ".hdr", NULL)) {
+ return IMA_ALPHA_PREMUL;
}
else {
- image->alpha_mode = IMA_ALPHA_STRAIGHT;
+ return IMA_ALPHA_STRAIGHT;
}
}
+void BKE_image_alpha_mode_from_extension(Image *image)
+{
+ image->alpha_mode = BKE_image_alpha_mode_from_extension_ex(image->name);
+}
+
Image *BKE_image_load(Main *bmain, const char *filepath)
{
Image *ima;
@@ -1266,98 +1267,93 @@ char BKE_imtype_from_arg(const char *imtype_arg)
static int do_add_image_extension(char *string, const char imtype, const ImageFormatData *im_format)
{
const char *extension = NULL;
+ const char *extension_test;
(void)im_format; /* may be unused, depends on build options */
if (imtype == R_IMF_IMTYPE_IRIS) {
- if (!BLI_testextensie(string, ".rgb"))
- extension = ".rgb";
+ if (!BLI_testextensie(string, extension_test = ".rgb"))
+ extension = extension_test;
}
else if (imtype == R_IMF_IMTYPE_IRIZ) {
- if (!BLI_testextensie(string, ".rgb"))
- extension = ".rgb";
+ if (!BLI_testextensie(string, extension_test = ".rgb"))
+ extension = extension_test;
}
#ifdef WITH_HDR
else if (imtype == R_IMF_IMTYPE_RADHDR) {
- if (!BLI_testextensie(string, ".hdr"))
- extension = ".hdr";
+ if (!BLI_testextensie(string, extension_test = ".hdr"))
+ extension = extension_test;
}
#endif
else if (ELEM5(imtype, R_IMF_IMTYPE_PNG, R_IMF_IMTYPE_FFMPEG, R_IMF_IMTYPE_H264, R_IMF_IMTYPE_THEORA, R_IMF_IMTYPE_XVID)) {
- if (!BLI_testextensie(string, ".png"))
- extension = ".png";
+ if (!BLI_testextensie(string, extension_test = ".png"))
+ extension = extension_test;
}
#ifdef WITH_DDS
else if (imtype == R_IMF_IMTYPE_DDS) {
- if (!BLI_testextensie(string, ".dds"))
- extension = ".dds";
+ if (!BLI_testextensie(string, extension_test = ".dds"))
+ extension = extension_test;
}
#endif
- else if (imtype == R_IMF_IMTYPE_RAWTGA) {
- if (!BLI_testextensie(string, ".tga"))
- extension = ".tga";
+ else if (ELEM(imtype, R_IMF_IMTYPE_TARGA, R_IMF_IMTYPE_RAWTGA)) {
+ if (!BLI_testextensie(string, extension_test = ".tga"))
+ extension = extension_test;
}
else if (imtype == R_IMF_IMTYPE_BMP) {
- if (!BLI_testextensie(string, ".bmp"))
- extension = ".bmp";
+ if (!BLI_testextensie(string, extension_test = ".bmp"))
+ extension = extension_test;
}
#ifdef WITH_TIFF
else if (imtype == R_IMF_IMTYPE_TIFF) {
- if (!BLI_testextensie(string, ".tif") &&
- !BLI_testextensie(string, ".tiff"))
- {
- extension = ".tif";
+ if (!BLI_testextensie_n(string, extension_test = ".tif", ".tiff", NULL)) {
+ extension = extension_test;
}
}
#endif
#ifdef WITH_OPENIMAGEIO
else if (imtype == R_IMF_IMTYPE_PSD) {
- if (!BLI_testextensie(string, ".psd"))
- extension = ".psd";
+ if (!BLI_testextensie(string, extension_test = ".psd"))
+ extension = extension_test;
}
#endif
#ifdef WITH_OPENEXR
else if (ELEM(imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) {
- if (!BLI_testextensie(string, ".exr"))
- extension = ".exr";
+ if (!BLI_testextensie(string, extension_test = ".exr"))
+ extension = extension_test;
}
#endif
#ifdef WITH_CINEON
else if (imtype == R_IMF_IMTYPE_CINEON) {
- if (!BLI_testextensie(string, ".cin"))
- extension = ".cin";
+ if (!BLI_testextensie(string, extension_test = ".cin"))
+ extension = extension_test;
}
else if (imtype == R_IMF_IMTYPE_DPX) {
- if (!BLI_testextensie(string, ".dpx"))
- extension = ".dpx";
+ if (!BLI_testextensie(string, extension_test = ".dpx"))
+ extension = extension_test;
}
#endif
- else if (imtype == R_IMF_IMTYPE_TARGA) {
- if (!BLI_testextensie(string, ".tga"))
- extension = ".tga";
- }
#ifdef WITH_OPENJPEG
else if (imtype == R_IMF_IMTYPE_JP2) {
if (im_format) {
if (im_format->jp2_codec == R_IMF_JP2_CODEC_JP2) {
- if (!BLI_testextensie(string, ".jp2"))
- extension = ".jp2";
+ if (!BLI_testextensie(string, extension_test = ".jp2"))
+ extension = extension_test;
}
else if (im_format->jp2_codec == R_IMF_JP2_CODEC_J2K) {
- if (!BLI_testextensie(string, ".j2c"))
- extension = ".j2c";
+ if (!BLI_testextensie(string, extension_test = ".j2c"))
+ extension = extension_test;
}
else
BLI_assert(!"Unsupported jp2 codec was specified in im_format->jp2_codec");
}
else {
- if (!BLI_testextensie(string, ".jp2"))
- extension = ".jp2";
+ if (!BLI_testextensie(string, extension_test = ".jp2"))
+ extension = extension_test;
}
}
#endif
else { // R_IMF_IMTYPE_AVIRAW, R_IMF_IMTYPE_AVIJPEG, R_IMF_IMTYPE_JPEG90, R_IMF_IMTYPE_QUICKTIME etc
- if (!(BLI_testextensie(string, ".jpg") || BLI_testextensie(string, ".jpeg")))
- extension = ".jpg";
+ if (!(BLI_testextensie_n(string, extension_test = ".jpg", ".jpeg", NULL)))
+ extension = extension_test;
}
if (extension) {
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 4c32e3e..b261ad5 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -4165,18 +4165,8 @@ Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine)
void BKE_sequence_alpha_mode_from_extension(Sequence *seq)
{
if (seq->strip && seq->strip->stripdata) {
- char *name = seq->strip->stripdata->name;
-
- if (BLI_testextensie(name, ".exr") ||
- BLI_testextensie(name, ".cin") ||
- BLI_testextensie(name, ".dpx") ||
- BLI_testextensie(name, ".hdr"))
- {
- seq->alpha_mode = IMA_ALPHA_PREMUL;
- }
- else {
- seq->alpha_mode = IMA_ALPHA_STRAIGHT;
- }
+ const char *filename = seq->strip->stripdata->name;
+ seq->alpha_mode = BKE_image_alpha_mode_from_extension_ex(filename);
}
}
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index 0cffa28..2b06b8b 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -82,8 +82,8 @@ const char *BLI_get_folder_version(const int id, const int ver, const bool do_ch
#define ALTSEP '\\'
#endif
-void BLI_setenv(const char *env, const char *val);
-void BLI_setenv_if_new(const char *env, const char *val);
+void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1);
+void BLI_setenv_if_new(const char *env, const char *val) ATTR_NONNULL(1);
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
void BLI_make_exist(char *dir);
@@ -95,7 +95,7 @@ void BLI_path_append(char *__restrict dst, const size_t maxlen,
const char *__restrict file) ATTR_NONNULL();
void BLI_join_dirfile(char *__restrict string, const size_t maxlen,
const char *__restrict dir, const char *__restrict file) ATTR_NONNULL();
-const char *BLI_path_basename(const char *path);
+const char *BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
typedef enum bli_rebase_state {
BLI_REBASE_NO_SRCDIR = 0,
@@ -105,18 +105,19 @@ typedef enum bli_rebase_state {
int BLI_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir);
-const char *BLI_last_slash(const char *string);
-int BLI_add_slash(char *string);
-void BLI_del_slash(char *string);
-const char *BLI_first_slash(const char *string);
+const char *BLI_last_slash(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+int BLI_add_slash(char *string) ATTR_NONNULL();
+void BLI_del_slash(char *string) ATTR_NONNULL();
+const char *BLI_first_slash(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
void BLI_getlastdir(const char *dir, char *last, const size_t maxlen);
-bool BLI_testextensie(const char *str, const char *ext);
-bool BLI_testextensie_array(const char *str, con
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list