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.
This commit is contained in:
parent
36e5c9e026
commit
75c18b989c
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue