Orange: tested all EXR demo images from openexr.com, found two issues;
- images with a so-called "data window" (have negative start coordinate) did not read correctly - negative colors were not clamped yet in imbuf Now there's still some compliancy issues with zbuffers... you can save it either as unsigned int or as float, whilst blender renders zbuffer in signed int. :)
This commit is contained in:
@@ -166,6 +166,8 @@ void IMB_gamwarp(struct ImBuf *ibuf, double gamma)
|
||||
}
|
||||
}
|
||||
|
||||
#define FTOCHAR(val) val<=0.0f?0: (val>=1.0f?255: (char)(255.0f*val))
|
||||
|
||||
void IMB_rect_from_float(struct ImBuf *ibuf)
|
||||
{
|
||||
/* quick method to convert floatbuf to byte */
|
||||
@@ -181,12 +183,13 @@ void IMB_rect_from_float(struct ImBuf *ibuf)
|
||||
|
||||
for (i = ibuf->x * ibuf->y; i > 0; i--)
|
||||
{
|
||||
to[0] = tof[0] > 1.0 ? 255 : (unsigned char)(tof[0] * 255.0f);
|
||||
to[1] = tof[1] > 1.0 ? 255 : (unsigned char)(tof[1] * 255.0f);
|
||||
to[2] = tof[2] > 1.0 ? 255 : (unsigned char)(tof[2] * 255.0f);
|
||||
to[3] = tof[3] > 1.0 ? 255 : (unsigned char)(tof[3] * 255.0f);
|
||||
to[0] = FTOCHAR(tof[0]);
|
||||
to[1] = FTOCHAR(tof[1]);
|
||||
to[2] = FTOCHAR(tof[2]);
|
||||
to[3] = FTOCHAR(tof[3]);
|
||||
to += 4;
|
||||
tof += 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -375,10 +375,10 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags)
|
||||
int width = dw.max.x - dw.min.x + 1;
|
||||
int height = dw.max.y - dw.min.y + 1;
|
||||
|
||||
// printf("OpenEXR-load: image data window %d %d %d %d\n",
|
||||
// dw.min.x, dw.min.y, dw.max.x, dw.max.y);
|
||||
//printf("OpenEXR-load: image data window %d %d %d %d\n",
|
||||
// dw.min.x, dw.min.y, dw.max.x, dw.max.y);
|
||||
|
||||
// exr_print_filecontents(file);
|
||||
//exr_print_filecontents(file);
|
||||
|
||||
ibuf = IMB_allocImBuf(width, height, 32, 0, 0);
|
||||
|
||||
@@ -389,12 +389,16 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags)
|
||||
if (!(flags & IB_test))
|
||||
{
|
||||
FrameBuffer frameBuffer;
|
||||
float *first;
|
||||
int xstride = sizeof(float) * 4;
|
||||
int ystride = - xstride*width;
|
||||
|
||||
imb_addrectfloatImBuf(ibuf);
|
||||
|
||||
float *first= ibuf->rect_float + 4*(height-1)*width;
|
||||
int xstride = sizeof(float) * 4;
|
||||
int ystride = - xstride*width;
|
||||
/* inverse correct first pixel for datawindow coordinates (- dw.min.y because of y flip) */
|
||||
first= ibuf->rect_float - 4*(dw.min.x - dw.min.y*width);
|
||||
/* but, since we read y-flipped (negative y stride) we move to last scanline */
|
||||
first+= 4*(height-1)*width;
|
||||
|
||||
frameBuffer.insert ("R", Slice (FLOAT, (char *) first, xstride, ystride));
|
||||
frameBuffer.insert ("G", Slice (FLOAT, (char *) (first+1), xstride, ystride));
|
||||
@@ -406,7 +410,8 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags)
|
||||
int *firstz;
|
||||
|
||||
addzbufImBuf(ibuf);
|
||||
firstz= ibuf->zbuf + (height-1)*width;
|
||||
firstz= ibuf->zbuf - (dw.min.x - dw.min.y*width);
|
||||
firstz+= (height-1)*width;
|
||||
frameBuffer.insert ("Z", Slice (UINT, (char *)firstz , sizeof(int), -width*sizeof(int)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user