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-11 06:46:32 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-11-11 06:54:04 +0300
commit75c18b989c566d24c76f9f7a44271654bc07a02c (patch)
tree6abb42e2f30a50ff3c17b8a23ce6ac3ea758902b /source/blender/imbuf
parent36e5c9e026a49d0ead2290ae8c1d3ec27205b4a5 (diff)
Cleanup: remove redundant NULL checks in ImFileType.is_a callback
Most of these callbacks don't do a NULL check, so there is no need to do this for bmp/png. Also correct radiance_hdr comments.
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/intern/bmp.c32
-rw-r--r--source/blender/imbuf/intern/png.c9
-rw-r--r--source/blender/imbuf/intern/radiance_hdr.c22
-rw-r--r--source/blender/imbuf/intern/targa.c2
4 files changed, 31 insertions, 34 deletions
diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c
index f897b1c6df3..f7fdc7a8e80 100644
--- a/source/blender/imbuf/intern/bmp.c
+++ b/source/blender/imbuf/intern/bmp.c
@@ -74,31 +74,27 @@ typedef struct BMPHEADER {
static int checkbmp(const uchar *mem)
{
+ if (!CHECK_HEADER_FIELD_BMP(mem)) {
+ return 0;
+ }
int ret_val = 0;
BMPINFOHEADER bmi;
uint u;
- if (mem) {
- if (CHECK_HEADER_FIELD_BMP(mem)) {
- /* skip fileheader */
- mem += BMP_FILEHEADER_SIZE;
- }
- else {
- return 0;
- }
+ /* skip fileheader */
+ mem += BMP_FILEHEADER_SIZE;
- /* for systems where an int needs to be 4 bytes aligned */
- memcpy(&bmi, mem, sizeof(bmi));
+ /* for systems where an int needs to be 4 bytes aligned */
+ memcpy(&bmi, mem, sizeof(bmi));
- u = LITTLE_LONG(bmi.biSize);
- /* we only support uncompressed images for now. */
- if (u >= sizeof(BMPINFOHEADER)) {
- if (bmi.biCompression == 0) {
- u = LITTLE_SHORT(bmi.biBitCount);
- if (u > 0 && u <= 32) {
- ret_val = 1;
- }
+ u = LITTLE_LONG(bmi.biSize);
+ /* we only support uncompressed images for now. */
+ if (u >= sizeof(BMPINFOHEADER)) {
+ if (bmi.biCompression == 0) {
+ u = LITTLE_SHORT(bmi.biBitCount);
+ if (u > 0 && u <= 32) {
+ ret_val = 1;
}
}
}
diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c
index c4fbd3f7563..5b3311e5dd0 100644
--- a/source/blender/imbuf/intern/png.c
+++ b/source/blender/imbuf/intern/png.c
@@ -63,14 +63,13 @@ int imb_is_a_png(const unsigned char *mem)
{
int ret_val = 0;
- if (mem) {
#if (PNG_LIBPNG_VER_MAJOR == 1) && (PNG_LIBPNG_VER_MINOR == 2)
- /* Older version of libpng doesn't use const pointer to memory. */
- ret_val = !png_sig_cmp((png_bytep)mem, 0, 8);
+ /* Older version of libpng doesn't use const pointer to memory. */
+ ret_val = !png_sig_cmp((png_bytep)mem, 0, 8);
#else
- ret_val = !png_sig_cmp(mem, 0, 8);
+ ret_val = !png_sig_cmp(mem, 0, 8);
#endif
- }
+
return ret_val;
}
diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c
index 599388442ca..8de243e52bc 100644
--- a/source/blender/imbuf/intern/radiance_hdr.c
+++ b/source/blender/imbuf/intern/radiance_hdr.c
@@ -199,15 +199,17 @@ static void FLOAT2RGBE(const fCOLOR fcol, RGBE rgbe)
int imb_is_a_hdr(const unsigned char *buf)
{
- /* For recognition, Blender only loads first 32 bytes, so use #?RADIANCE id instead */
- /* update: actually, the 'RADIANCE' part is just an optional program name,
- * the magic word is really only the '#?' part */
- // if (strstr((char *)buf, "#?RADIANCE")) return 1;
- if (memcmp((char *)buf, "#?", 2) == 0) {
- return 1;
- }
- // if (strstr((char *)buf, "32-bit_rle_rgbe")) return 1;
- return 0;
+ /* NOTE: `#?RADIANCE` is used by other programs such as `ImageMagik`,
+ * Although there are some files in the wild that only use `#?` (from looking online).
+ * If this is ever a problem we could check for the longer header since this is part of the spec.
+ *
+ * We could check `32-bit_rle_rgbe` or `32-bit_rle_xyze` too since this is part of the format.
+ * Currently this isn't needed.
+ *
+ * See: http://paulbourke.net/dataformats/pic/
+ */
+ const unsigned char magic[2] = {'#', '?'};
+ return memcmp(buf, magic, sizeof(magic)) == 0;
}
struct ImBuf *imb_loadhdr(const unsigned char *mem,
@@ -224,7 +226,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem,
const unsigned char *ptr, *mem_eof = mem + size;
char oriY[80], oriX[80];
- if (imb_is_a_hdr((void *)mem)) {
+ if (imb_is_a_hdr(mem)) {
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);
/* find empty line, next line is resolution info */
diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c
index 5a3cbd375b6..cb549fb43f2 100644
--- a/source/blender/imbuf/intern/targa.c
+++ b/source/blender/imbuf/intern/targa.c
@@ -288,7 +288,7 @@ static bool dumptarga(struct ImBuf *ibuf, FILE *file)
int imb_savetarga(struct ImBuf *ibuf, const char *filepath, int flags)
{
- char buf[20] = {0};
+ char buf[18] = {0};
FILE *fildes;
bool ok = false;