bugfix [#23706] SEGFAULT: File Load of EXR

image node was modifying the original buffer color management, now only modify a copy.
This commit is contained in:
Campbell Barton 2010-09-18 07:19:32 +00:00
parent c853c23267
commit d81315e9d2

@ -62,38 +62,55 @@ static CompBuf *node_composit_get_image(RenderData *rd, Image *ima, ImageUser *i
ImBuf *ibuf; ImBuf *ibuf;
CompBuf *stackbuf; CompBuf *stackbuf;
int type; int type;
ibuf= BKE_image_get_ibuf(ima, iuser);
if(ibuf==NULL)
return NULL;
if (!(rd->color_mgt_flag & R_COLOR_MANAGEMENT)) { float *rect;
int profile = IB_PROFILE_NONE; int alloc= FALSE;
/* temporarily set profile to none to not disturb actual */ ibuf= BKE_image_get_ibuf(ima, iuser);
SWAP(int, ibuf->profile, profile); if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL)) {
return NULL;
if (ibuf->rect_float != NULL) {
imb_freerectfloatImBuf(ibuf);
}
IMB_float_from_rect(ibuf);
SWAP(int, ibuf->profile, profile);
} }
if (ibuf->rect_float == NULL) { if (ibuf->rect_float == NULL) {
IMB_float_from_rect(ibuf); IMB_float_from_rect(ibuf);
} }
/* now we need a float buffer from the image
* with matching color management */
if(rd->color_mgt_flag & R_COLOR_MANAGEMENT) {
if(ibuf->profile == IB_PROFILE_LINEAR_RGB) {
rect= ibuf->rect_float;
}
else {
rect= MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image");
srgb_to_linearrgb_rgba_rgba_buf(rect, ibuf->rect_float, ibuf->x * ibuf->y);
alloc= TRUE;
}
}
else {
if(ibuf->profile != IB_PROFILE_LINEAR_RGB) {
rect= ibuf->rect_float;
}
else {
rect= MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image");
linearrgb_to_srgb_rgba_rgba_buf(rect, ibuf->rect_float, ibuf->x * ibuf->y);
alloc= TRUE;
}
}
/* done coercing into the correct color management */
type= ibuf->channels; type= ibuf->channels;
if(rd->scemode & R_COMP_CROP) { if(rd->scemode & R_COMP_CROP) {
stackbuf= get_cropped_compbuf(&rd->disprect, ibuf->rect_float, ibuf->x, ibuf->y, type); stackbuf= get_cropped_compbuf(&rd->disprect, rect, ibuf->x, ibuf->y, type);
if(alloc)
MEM_freeN(rect);
} }
else { else {
/* we put imbuf copy on stack, cbuf knows rect is from other ibuf when freed! */ /* we put imbuf copy on stack, cbuf knows rect is from other ibuf when freed! */
stackbuf= alloc_compbuf(ibuf->x, ibuf->y, type, 0); stackbuf= alloc_compbuf(ibuf->x, ibuf->y, type, alloc);
stackbuf->rect= ibuf->rect_float; stackbuf->rect= rect;
} }
/*code to respect the premul flag of images; I'm /*code to respect the premul flag of images; I'm