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:
authorCampbell Barton <ideasman42@gmail.com>2020-11-13 12:25:21 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-11-13 12:32:15 +0300
commita8f9a2493915bf9384553b3933593a5296e70a1c (patch)
treeb92994b73297c1f9bb439c1d38dae373985065b7
parent4a3b26dd5e7fc0fb0d95271859ee7b780add2a88 (diff)
Cleanup: use IMB_FTYPE_NONE instead of 0 for imbuf format comparison
Image format code checked the file type against an enum except for zero which is used when the format can't be detected. Also add doc-strings to some of the image file type callbacks.
-rw-r--r--source/blender/blenkernel/intern/image.c2
-rw-r--r--source/blender/blenkernel/intern/packedFile.c4
-rw-r--r--source/blender/imbuf/IMB_imbuf_types.h7
-rw-r--r--source/blender/imbuf/intern/IMB_filetype.h14
-rw-r--r--source/blender/imbuf/intern/util.c6
-rw-r--r--source/blender/makesrna/intern/rna_image.c3
-rw-r--r--source/blender/windowmanager/intern/wm_playanim.c2
7 files changed, 28 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 9010c846954..cd2ed32cd4f 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1341,7 +1341,7 @@ int BKE_image_imtype_to_ftype(const char imtype, ImbFormatOptions *r_options)
char BKE_image_ftype_to_imtype(const int ftype, const ImbFormatOptions *options)
{
- if (ftype == 0) {
+ if (ftype == IMB_FTYPE_NONE) {
return R_IMF_IMTYPE_TARGA;
}
if (ftype == IMB_FTYPE_IMAGIC) {
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c
index e99dd77005b..87239d160b4 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -536,8 +536,8 @@ static void unpack_generate_paths(const char *name,
ImagePackedFile *imapf = ((Image *)id)->packedfiles.last;
if (imapf != NULL && imapf->packedfile != NULL) {
const PackedFile *pf = imapf->packedfile;
- const int ftype = IMB_ispic_type_from_memory((const uchar *)pf->data, pf->size);
- if (ftype != 0) {
+ enum eImbFileType ftype = IMB_ispic_type_from_memory((const uchar *)pf->data, pf->size);
+ if (ftype != IMB_FTYPE_NONE) {
const int imtype = BKE_image_ftype_to_imtype(ftype, NULL);
BKE_image_path_ensure_ext_from_imtype(tempname, imtype);
}
diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h
index 98e9c34a4ff..4bb3ea500fa 100644
--- a/source/blender/imbuf/IMB_imbuf_types.h
+++ b/source/blender/imbuf/IMB_imbuf_types.h
@@ -69,7 +69,7 @@ typedef struct DDSData {
* See T46524. */
/** #ImBuf.ftype flag, main image types. */
-enum eImbTypes {
+enum eImbFileType {
IMB_FTYPE_PNG = 1,
IMB_FTYPE_TGA = 2,
IMB_FTYPE_JPG = 3,
@@ -98,6 +98,9 @@ enum eImbTypes {
#endif
};
+/* Only for readability. */
+#define IMB_FTYPE_NONE 0
+
/* ibuf->foptions flag, type specific options.
* Some formats include compression rations on some bits */
@@ -243,7 +246,7 @@ typedef struct ImBuf {
/* file information */
/** file type we are going to save as */
- enum eImbTypes ftype;
+ enum eImbFileType ftype;
/** file format specific flags */
ImbFormatOptions foptions;
/** filename associated with this image */
diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h
index 175d973de9a..c8f6135f330 100644
--- a/source/blender/imbuf/intern/IMB_filetype.h
+++ b/source/blender/imbuf/intern/IMB_filetype.h
@@ -29,15 +29,26 @@ struct ImBuf;
#define IM_FTYPE_FLOAT 1
typedef struct ImFileType {
+ /** Optional, called once when initializing. */
void (*init)(void);
+ /** Optional, called once when exiting. */
void (*exit)(void);
+ /**
+ * Check if the data matches this file types 'magic',
+ * \note that this may only read in a small part of the files header,
+ * see: #IMB_ispic_type for details.
+ */
bool (*is_a)(const unsigned char *buf, const size_t size);
+
+ /** Load an image from memory. */
struct ImBuf *(*load)(const unsigned char *mem,
size_t size,
int flags,
char colorspace[IM_MAX_SPACE]);
+ /** Load an image from a file. */
struct ImBuf *(*load_filepath)(const char *filepath, int flags, char colorspace[IM_MAX_SPACE]);
+ /** Save to a file (or memory if #IB_mem is set in `flags` and the format supports it). */
bool (*save)(struct ImBuf *ibuf, const char *filepath, int flags);
void (*load_tile)(struct ImBuf *ibuf,
const unsigned char *mem,
@@ -47,7 +58,10 @@ typedef struct ImFileType {
unsigned int *rect);
int flag;
+
+ /** #eImbFileType */
int filetype;
+
int default_save_role;
} ImFileType;
diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c
index c18321ae2fe..64dad5de902 100644
--- a/source/blender/imbuf/intern/util.c
+++ b/source/blender/imbuf/intern/util.c
@@ -159,7 +159,7 @@ int IMB_ispic_type_from_memory(const unsigned char *buf, const size_t buf_size)
}
}
- return 0;
+ return IMB_FTYPE_NONE;
}
int IMB_ispic_type(const char *filepath)
@@ -167,7 +167,7 @@ int IMB_ispic_type(const char *filepath)
unsigned char buf[HEADER_SIZE];
const ssize_t buf_size = imb_ispic_read_header_from_filepath(filepath, buf);
if (buf_size <= 0) {
- return 0;
+ return IMB_FTYPE_NONE;
}
return IMB_ispic_type_from_memory(buf, (size_t)buf_size);
}
@@ -196,7 +196,7 @@ bool IMB_ispic_type_matches(const char *filepath, int filetype)
bool IMB_ispic(const char *filepath)
{
- return (IMB_ispic_type(filepath) != 0);
+ return (IMB_ispic_type(filepath) != IMB_FTYPE_NONE);
}
static bool isavi(const char *filepath)
diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c
index ea36289d361..504a4a6bdf3 100644
--- a/source/blender/makesrna/intern/rna_image.c
+++ b/source/blender/makesrna/intern/rna_image.c
@@ -235,7 +235,8 @@ static int rna_Image_file_format_get(PointerRNA *ptr)
{
Image *image = (Image *)ptr->data;
ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
- int imtype = BKE_image_ftype_to_imtype(ibuf ? ibuf->ftype : 0, ibuf ? &ibuf->foptions : NULL);
+ int imtype = BKE_image_ftype_to_imtype(ibuf ? ibuf->ftype : IMB_FTYPE_NONE,
+ ibuf ? &ibuf->foptions : NULL);
BKE_image_release_ibuf(image, ibuf, NULL);
diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c
index ee6aee1fb7a..60bcb687dbf 100644
--- a/source/blender/windowmanager/intern/wm_playanim.c
+++ b/source/blender/windowmanager/intern/wm_playanim.c
@@ -1391,7 +1391,7 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
while (ps.picture) {
int hasevent;
#ifndef USE_IMB_CACHE
- if (ibuf != NULL && ibuf->ftype == 0) {
+ if (ibuf != NULL && ibuf->ftype == IMB_FTYPE_NONE) {
IMB_freeImBuf(ibuf);
}
#endif