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 /source/blender/imbuf
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.
Diffstat (limited to 'source/blender/imbuf')
-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
3 files changed, 22 insertions, 5 deletions
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)