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:
Diffstat (limited to 'source/blender/imbuf/intern/radiance_hdr.c')
-rw-r--r--source/blender/imbuf/intern/radiance_hdr.c138
1 files changed, 70 insertions, 68 deletions
diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c
index 285b18595f7..94b2a62aa26 100644
--- a/source/blender/imbuf/intern/radiance_hdr.c
+++ b/source/blender/imbuf/intern/radiance_hdr.c
@@ -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 (!imb_is_a_hdr(mem, size)) {
+ 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))) {
- 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 ((found && (x < (size + 2))) == 0) {
+ /* Data not found! */
+ return NULL;
+ }
- if (flags & IB_test) {
- ibuf = IMB_allocImBuf(width, height, 32, 0);
- }
- else {
- ibuf = IMB_allocImBuf(width, height, 32, (flags & IB_rect) | IB_rectfloat);
- }
+ if (sscanf((const char *)&mem[x + 1],
+ "%79s %d %79s %d",
+ (char *)&oriY,
+ &height,
+ (char *)&oriX,
+ &width) != 4) {
+ return NULL;
+ }
- if (UNLIKELY(ibuf == NULL)) {
- return NULL;
- }
- ibuf->ftype = IMB_FTYPE_RADHDR;
+ /* find end of this line, data right behind it */
+ ptr = (const unsigned char *)strchr((const char *)&mem[x + 1], '\n');
+ ptr++;
- if (flags & IB_alphamode_detect) {
- ibuf->flags |= IB_alphamode_premul;
- }
+ if (flags & IB_test) {
+ ibuf = IMB_allocImBuf(width, height, 32, 0);
+ }
+ else {
+ ibuf = IMB_allocImBuf(width, height, 32, (flags & IB_rect) | IB_rectfloat);
+ }
- if (flags & IB_test) {
- return ibuf;
- }
+ if (UNLIKELY(ibuf == NULL)) {
+ return NULL;
+ }
- /* read in and decode the actual data */
- sline = (RGBE *)MEM_mallocN(sizeof(*sline) * width, __func__);
- rect_float = ibuf->rect_float;
+ ibuf->ftype = IMB_FTYPE_RADHDR;
- 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_alphamode_detect) {
+ ibuf->flags |= IB_alphamode_premul;
+ }
- if (flags & IB_rect) {
- IMB_rect_from_float(ibuf);
- }
+ if (flags & IB_test) {
+ return ibuf;
+ }
- 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;
}
- // else printf("Data not found!\n");
+ 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);
}
- // else printf("Not a valid radiance HDR file!\n");
- return NULL;
+ return ibuf;
}
/* ImBuf write */