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:
parent
e7f890aa59
commit
b547ac32d9
|
@ -198,10 +198,10 @@ ImBuf *imb_load_cineon(const unsigned char *mem,
|
|||
int flags,
|
||||
char colorspace[IM_MAX_SPACE])
|
||||
{
|
||||
if (imb_is_a_cineon(mem, size)) {
|
||||
return imb_load_dpx_cineon(mem, size, 1, flags, colorspace);
|
||||
if (!imb_is_a_cineon(mem, size)) {
|
||||
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)
|
||||
|
@ -219,8 +219,8 @@ ImBuf *imb_load_dpx(const unsigned char *mem,
|
|||
int flags,
|
||||
char colorspace[IM_MAX_SPACE])
|
||||
{
|
||||
if (imb_is_a_dpx(mem, size)) {
|
||||
return imb_load_dpx_cineon(mem, size, 0, flags, colorspace);
|
||||
if (!imb_is_a_dpx(mem, size)) {
|
||||
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;
|
||||
uchar dirty_flag = 0;
|
||||
|
||||
if (size < HEADER_SIZE) {
|
||||
if (!imb_is_a_iris(mem, size)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -229,87 +229,89 @@ 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(mem, size)) {
|
||||
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);
|
||||
|
||||
/* find empty line, next line is resolution info */
|
||||
size_t x;
|
||||
for (x = 1; x < size; x++) {
|
||||
if ((mem[x - 1] == '\n') && (mem[x] == '\n')) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found && (x < (size + 2))) {
|
||||
if (sscanf((char *)&mem[x + 1],
|
||||
"%79s %d %79s %d",
|
||||
(char *)&oriY,
|
||||
&height,
|
||||
(char *)&oriX,
|
||||
&width) != 4) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* find end of this line, data right behind it */
|
||||
ptr = (unsigned char *)strchr((char *)&mem[x + 1], '\n');
|
||||
ptr++;
|
||||
|
||||
if (flags & IB_test) {
|
||||
ibuf = IMB_allocImBuf(width, height, 32, 0);
|
||||
}
|
||||
else {
|
||||
ibuf = IMB_allocImBuf(width, height, 32, (flags & IB_rect) | IB_rectfloat);
|
||||
}
|
||||
|
||||
if (UNLIKELY(ibuf == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
ibuf->ftype = IMB_FTYPE_RADHDR;
|
||||
|
||||
if (flags & IB_alphamode_detect) {
|
||||
ibuf->flags |= IB_alphamode_premul;
|
||||
}
|
||||
|
||||
if (flags & IB_test) {
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
/* read in and decode the actual data */
|
||||
sline = (RGBE *)MEM_mallocN(sizeof(*sline) * width, __func__);
|
||||
rect_float = ibuf->rect_float;
|
||||
|
||||
for (size_t y = 0; y < height; y++) {
|
||||
ptr = freadcolrs(sline, ptr, width, mem_eof);
|
||||
if (ptr == NULL) {
|
||||
printf(
|
||||
"WARNING! HDR decode error, image may be just truncated, or completely wrong...\n");
|
||||
break;
|
||||
}
|
||||
for (x = 0; x < width; x++) {
|
||||
/* convert to ldr */
|
||||
RGBE2FLOAT(sline[x], fcol);
|
||||
*rect_float++ = fcol[RED];
|
||||
*rect_float++ = fcol[GRN];
|
||||
*rect_float++ = fcol[BLU];
|
||||
*rect_float++ = 1.0f;
|
||||
}
|
||||
}
|
||||
MEM_freeN(sline);
|
||||
if (oriY[0] == '-') {
|
||||
IMB_flipy(ibuf);
|
||||
}
|
||||
|
||||
if (flags & IB_rect) {
|
||||
IMB_rect_from_float(ibuf);
|
||||
}
|
||||
|
||||
return ibuf;
|
||||
}
|
||||
// else printf("Data not found!\n");
|
||||
if (!imb_is_a_hdr(mem, size)) {
|
||||
return NULL;
|
||||
}
|
||||
// else printf("Not a valid radiance HDR file!\n");
|
||||
|
||||
return NULL;
|
||||
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);
|
||||
|
||||
/* find empty line, next line is resolution info */
|
||||
size_t x;
|
||||
for (x = 1; x < size; x++) {
|
||||
if ((mem[x - 1] == '\n') && (mem[x] == '\n')) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((found && (x < (size + 2))) == 0) {
|
||||
/* Data not found! */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (sscanf((const char *)&mem[x + 1],
|
||||
"%79s %d %79s %d",
|
||||
(char *)&oriY,
|
||||
&height,
|
||||
(char *)&oriX,
|
||||
&width) != 4) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* find end of this line, data right behind it */
|
||||
ptr = (const unsigned char *)strchr((const char *)&mem[x + 1], '\n');
|
||||
ptr++;
|
||||
|
||||
if (flags & IB_test) {
|
||||
ibuf = IMB_allocImBuf(width, height, 32, 0);
|
||||
}
|
||||
else {
|
||||
ibuf = IMB_allocImBuf(width, height, 32, (flags & IB_rect) | IB_rectfloat);
|
||||
}
|
||||
|
||||
if (UNLIKELY(ibuf == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ibuf->ftype = IMB_FTYPE_RADHDR;
|
||||
|
||||
if (flags & IB_alphamode_detect) {
|
||||
ibuf->flags |= IB_alphamode_premul;
|
||||
}
|
||||
|
||||
if (flags & IB_test) {
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
/* read in and decode the actual data */
|
||||
sline = (RGBE *)MEM_mallocN(sizeof(*sline) * width, __func__);
|
||||
rect_float = ibuf->rect_float;
|
||||
|
||||
for (size_t y = 0; y < height; y++) {
|
||||
ptr = freadcolrs(sline, ptr, width, mem_eof);
|
||||
if (ptr == NULL) {
|
||||
printf("WARNING! HDR decode error, image may be just truncated, or completely wrong...\n");
|
||||
break;
|
||||
}
|
||||
for (x = 0; x < width; x++) {
|
||||
/* convert to ldr */
|
||||
RGBE2FLOAT(sline[x], fcol);
|
||||
*rect_float++ = fcol[RED];
|
||||
*rect_float++ = fcol[GRN];
|
||||
*rect_float++ = fcol[BLU];
|
||||
*rect_float++ = 1.0f;
|
||||
}
|
||||
}
|
||||
MEM_freeN(sline);
|
||||
if (oriY[0] == '-') {
|
||||
IMB_flipy(ibuf);
|
||||
}
|
||||
|
||||
if (flags & IB_rect) {
|
||||
IMB_rect_from_float(ibuf);
|
||||
}
|
||||
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
/* ImBuf write */
|
||||
|
|
|
@ -576,11 +576,7 @@ ImBuf *imb_loadtiff(const unsigned char *mem,
|
|||
int ib_depth;
|
||||
int found;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
/* Check whether or not we have a TIFF file. */
|
||||
if (imb_is_a_tiff(mem, size) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue