Cleanup: use early return for imbuf image loader functions
Most imbuf loaders already did this, use early exit for the remaining loaders that didn't.
This commit is contained in:
@@ -198,11 +198,11 @@ ImBuf *imb_load_cineon(const unsigned char *mem,
|
|||||||
int flags,
|
int flags,
|
||||||
char colorspace[IM_MAX_SPACE])
|
char colorspace[IM_MAX_SPACE])
|
||||||
{
|
{
|
||||||
if (imb_is_a_cineon(mem, size)) {
|
if (!imb_is_a_cineon(mem, size)) {
|
||||||
return imb_load_dpx_cineon(mem, size, 1, flags, colorspace);
|
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return imb_load_dpx_cineon(mem, size, 1, flags, colorspace);
|
||||||
|
}
|
||||||
|
|
||||||
bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags)
|
bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags)
|
||||||
{
|
{
|
||||||
@@ -219,8 +219,8 @@ ImBuf *imb_load_dpx(const unsigned char *mem,
|
|||||||
int flags,
|
int flags,
|
||||||
char colorspace[IM_MAX_SPACE])
|
char colorspace[IM_MAX_SPACE])
|
||||||
{
|
{
|
||||||
if (imb_is_a_dpx(mem, size)) {
|
if (!imb_is_a_dpx(mem, size)) {
|
||||||
return imb_load_dpx_cineon(mem, size, 0, flags, colorspace);
|
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return imb_load_dpx_cineon(mem, size, 0, flags, colorspace);
|
||||||
|
}
|
||||||
|
|||||||
@@ -270,11 +270,13 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors
|
|||||||
ImBuf *ibuf = NULL;
|
ImBuf *ibuf = NULL;
|
||||||
uchar dirty_flag = 0;
|
uchar dirty_flag = 0;
|
||||||
|
|
||||||
if (size < HEADER_SIZE) {
|
if (!imb_is_a_iris(mem, size)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!imb_is_a_iris(mem, size)) {
|
/* Could pe part of the magic check above,
|
||||||
|
* by convention this check only requests the size needed to read it's magic though. */
|
||||||
|
if (size < HEADER_SIZE) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -229,7 +229,10 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem,
|
|||||||
const unsigned char *ptr, *mem_eof = mem + size;
|
const unsigned char *ptr, *mem_eof = mem + size;
|
||||||
char oriY[80], oriX[80];
|
char oriY[80], oriX[80];
|
||||||
|
|
||||||
if (imb_is_a_hdr(mem, size)) {
|
if (!imb_is_a_hdr(mem, size)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);
|
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);
|
||||||
|
|
||||||
/* find empty line, next line is resolution info */
|
/* find empty line, next line is resolution info */
|
||||||
@@ -240,8 +243,13 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found && (x < (size + 2))) {
|
|
||||||
if (sscanf((char *)&mem[x + 1],
|
if ((found && (x < (size + 2))) == 0) {
|
||||||
|
/* Data not found! */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sscanf((const char *)&mem[x + 1],
|
||||||
"%79s %d %79s %d",
|
"%79s %d %79s %d",
|
||||||
(char *)&oriY,
|
(char *)&oriY,
|
||||||
&height,
|
&height,
|
||||||
@@ -251,7 +259,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* find end of this line, data right behind it */
|
/* find end of this line, data right behind it */
|
||||||
ptr = (unsigned char *)strchr((char *)&mem[x + 1], '\n');
|
ptr = (const unsigned char *)strchr((const char *)&mem[x + 1], '\n');
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
if (flags & IB_test) {
|
if (flags & IB_test) {
|
||||||
@@ -264,6 +272,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem,
|
|||||||
if (UNLIKELY(ibuf == NULL)) {
|
if (UNLIKELY(ibuf == NULL)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ibuf->ftype = IMB_FTYPE_RADHDR;
|
ibuf->ftype = IMB_FTYPE_RADHDR;
|
||||||
|
|
||||||
if (flags & IB_alphamode_detect) {
|
if (flags & IB_alphamode_detect) {
|
||||||
@@ -281,8 +290,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem,
|
|||||||
for (size_t y = 0; y < height; y++) {
|
for (size_t y = 0; y < height; y++) {
|
||||||
ptr = freadcolrs(sline, ptr, width, mem_eof);
|
ptr = freadcolrs(sline, ptr, width, mem_eof);
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
printf(
|
printf("WARNING! HDR decode error, image may be just truncated, or completely wrong...\n");
|
||||||
"WARNING! HDR decode error, image may be just truncated, or completely wrong...\n");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (x = 0; x < width; x++) {
|
for (x = 0; x < width; x++) {
|
||||||
@@ -305,12 +313,6 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem,
|
|||||||
|
|
||||||
return ibuf;
|
return ibuf;
|
||||||
}
|
}
|
||||||
// else printf("Data not found!\n");
|
|
||||||
}
|
|
||||||
// else printf("Not a valid radiance HDR file!\n");
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ImBuf write */
|
/* ImBuf write */
|
||||||
static int fwritecolrs(
|
static int fwritecolrs(
|
||||||
|
|||||||
@@ -576,11 +576,7 @@ ImBuf *imb_loadtiff(const unsigned char *mem,
|
|||||||
int ib_depth;
|
int ib_depth;
|
||||||
int found;
|
int found;
|
||||||
|
|
||||||
/* check whether or not we have a TIFF file */
|
/* Check whether or not we have a TIFF file. */
|
||||||
if (size < IMB_TIFF_NCB) {
|
|
||||||
fprintf(stderr, "imb_loadtiff: size < IMB_TIFF_NCB\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (imb_is_a_tiff(mem, size) == 0) {
|
if (imb_is_a_tiff(mem, size) == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user