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:
authorTon Roosendaal <ton@blender.org>2006-01-12 01:36:31 +0300
committerTon Roosendaal <ton@blender.org>2006-01-12 01:36:31 +0300
commit0665f0d64799e6a38c4ca0930df73271f246e422 (patch)
treefa488d33452f0bfc6ec91e5bbbec726afcbcb9f3 /source/blender/imbuf
parentb92fa4151645d50e40faa8f4aaea4b7f6149947c (diff)
Orange;
Until now, the zbuffer was written straight from the internal zbuffer, which has values that are inverse-proportional (like 1.0/z) which makes it very hard to use it for postprocess, like zblur or other composit effects that require Z. Based on info from ILM, the values stored for Z in exr files is the actual distance from a camera. I think that's about time to migrate to that convention! By default now, after render, the z values are converted to floats. This saves in exr files now, but not in the Iris Z files. That latter was a blender-only anyway, so might be not a real hassle to drop. :) You can see the difference in the image window, but notice the range now is linear mapped from camera clipstart to clipend. Note; I just discover that ortho Z values need a different correction...
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/IMB_imbuf.h2
-rw-r--r--source/blender/imbuf/IMB_imbuf_types.h4
-rw-r--r--source/blender/imbuf/intern/allocimbuf.c43
-rw-r--r--source/blender/imbuf/intern/divers.c1
-rw-r--r--source/blender/imbuf/intern/openexr/openexr_api.cpp28
5 files changed, 60 insertions, 18 deletions
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index 63ffeb02603..20a31f5de28 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -185,6 +185,7 @@ struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1);
* @attention Defined in allocimbuf.c
*/
short addzbufImBuf(struct ImBuf * ibuf);
+short addzbuffloatImBuf(struct ImBuf * ibuf);
/**
*
@@ -468,6 +469,7 @@ void IMB_cspace(struct ImBuf *ibuf, float mat[][4]);
* @attention Defined in allocimbuf.c
*/
void IMB_freezbufImBuf(struct ImBuf * ibuf);
+void IMB_freezbuffloatImBuf(struct ImBuf * ibuf);
/**
*
diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h
index 652c15afdd3..ef1aa631fc6 100644
--- a/source/blender/imbuf/IMB_imbuf_types.h
+++ b/source/blender/imbuf/IMB_imbuf_types.h
@@ -88,7 +88,8 @@ typedef struct ImBuf{
char name[1023]; /**< The file name assocated with this image */
char namenull; /**< Unused don't want to remove it thought messes things up */
int userflags; /**< Used to set imbuf to Dirty and other stuff */
- int *zbuf; /**< z buffer data */
+ int *zbuf; /**< z buffer data, original zbuffer */
+ float *zbuf_float; /**< z buffer data, camera coordinates */
void *userdata;
unsigned char *encodedbuffer; /**< Compressed image only used with png currently */
unsigned int encodedsize; /**< Size of data written to encodedbuffer */
@@ -133,6 +134,7 @@ typedef enum {
#define IB_mem (1 << 14)
#define IB_rectfloat (1 << 15)
+#define IB_zbuffloat (1 << 16)
/*
* The bit flag is stored in the ImBuf.ftype variable.
diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c
index 51d294d2d26..0c1d182f4b2 100644
--- a/source/blender/imbuf/intern/allocimbuf.c
+++ b/source/blender/imbuf/intern/allocimbuf.c
@@ -112,6 +112,16 @@ void IMB_freezbufImBuf(struct ImBuf * ibuf)
ibuf->mall &= ~IB_zbuf;
}
+void IMB_freezbuffloatImBuf(struct ImBuf * ibuf)
+{
+ if (ibuf==NULL) return;
+ if (ibuf->zbuf_float){
+ if (ibuf->mall & IB_zbuffloat) MEM_freeN(ibuf->zbuf_float);
+ }
+ ibuf->zbuf_float= NULL;
+ ibuf->mall &= ~IB_zbuffloat;
+}
+
void IMB_freecmapImBuf(struct ImBuf * ibuf)
{
if (ibuf==NULL) return;
@@ -129,6 +139,7 @@ void IMB_freeImBuf(struct ImBuf * ibuf)
imb_freerectImBuf(ibuf);
imb_freerectfloatImBuf(ibuf);
IMB_freezbufImBuf(ibuf);
+ IMB_freezbuffloatImBuf(ibuf);
IMB_freecmapImBuf(ibuf);
freeencodedbufferImBuf(ibuf);
MEM_freeN(ibuf);
@@ -138,18 +149,36 @@ void IMB_freeImBuf(struct ImBuf * ibuf)
short addzbufImBuf(struct ImBuf * ibuf)
{
int size;
-
+
if (ibuf==NULL) return(FALSE);
IMB_freezbufImBuf(ibuf);
-
+
size = ibuf->x * ibuf->y * sizeof(unsigned int);
if ( (ibuf->zbuf = MEM_mallocN(size, "addzbufImBuf")) ){
ibuf->mall |= IB_zbuf;
ibuf->flags |= IB_zbuf;
return (TRUE);
}
+
+ return (FALSE);
+}
+short addzbuffloatImBuf(struct ImBuf * ibuf)
+{
+ int size;
+
+ if (ibuf==NULL) return(FALSE);
+
+ IMB_freezbuffloatImBuf(ibuf);
+
+ size = ibuf->x * ibuf->y * sizeof(float);
+ if ( (ibuf->zbuf_float = MEM_mallocN(size, "addzbuffloatImBuf")) ){
+ ibuf->mall |= IB_zbuffloat;
+ ibuf->flags |= IB_zbuffloat;
+ return (TRUE);
+ }
+
return (FALSE);
}
@@ -345,6 +374,13 @@ struct ImBuf *IMB_allocImBuf(short x, short y, uchar d, unsigned int flags, ucha
}
}
+ if (flags & IB_zbuffloat){
+ if (addzbuffloatImBuf(ibuf)==FALSE){
+ IMB_freeImBuf(ibuf);
+ return NULL;
+ }
+ }
+
if (flags & IB_planes){
if (imb_addplanesImBuf(ibuf)==FALSE){
IMB_freeImBuf(ibuf);
@@ -355,6 +391,7 @@ struct ImBuf *IMB_allocImBuf(short x, short y, uchar d, unsigned int flags, ucha
return (ibuf);
}
+/* does no zbuffers? */
struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1)
{
struct ImBuf *ibuf2, tbuf;
@@ -402,6 +439,8 @@ struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1)
tbuf.planes = ibuf2->planes;
tbuf.cmap = ibuf2->cmap;
tbuf.encodedbuffer = ibuf2->encodedbuffer;
+ tbuf.zbuf= NULL;
+ tbuf.zbuf_float= NULL;
// set malloc flag
tbuf.mall = ibuf2->mall;
diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c
index cca92741275..f73431cb28e 100644
--- a/source/blender/imbuf/intern/divers.c
+++ b/source/blender/imbuf/intern/divers.c
@@ -190,6 +190,5 @@ void IMB_rect_from_float(struct ImBuf *ibuf)
to += 4;
tof += 4;
}
-
}
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp
index 1fefe48c227..b310f128d8e 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp
@@ -167,7 +167,7 @@ static short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
int width = ibuf->x;
int height = ibuf->y;
- int write_zbuf = (flags & IB_zbuf) && ibuf->zbuf != NULL; // summarize
+ int write_zbuf = (flags & IB_zbuffloat) && ibuf->zbuf_float != NULL; // summarize
try
{
@@ -179,8 +179,8 @@ static short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
header.channels().insert ("G", Channel (HALF));
header.channels().insert ("B", Channel (HALF));
header.channels().insert ("A", Channel (HALF));
- if (write_zbuf) // z we do as uint always
- header.channels().insert ("Z", Channel (UINT));
+ if (write_zbuf) // z we do as float always
+ header.channels().insert ("Z", Channel (FLOAT));
FrameBuffer frameBuffer;
OutputFile *file = new OutputFile(name, header);
@@ -198,8 +198,8 @@ static short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
frameBuffer.insert ("A", Slice (HALF, (char *) &pixels[0].a, xstride, ystride));
if (write_zbuf)
- frameBuffer.insert ("Z", Slice (UINT, (char *) ibuf->zbuf + 4*(height-1)*width,
- sizeof(int), sizeof(int) * -width));
+ frameBuffer.insert ("Z", Slice (FLOAT, (char *) ibuf->zbuf_float + 4*(height-1)*width,
+ sizeof(float), sizeof(float) * -width));
if(ibuf->rect_float) {
float *from;
@@ -257,8 +257,8 @@ static short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
int width = ibuf->x;
int height = ibuf->y;
- int write_zbuf = (flags & IB_zbuf) && ibuf->zbuf != NULL; // summarize
-
+ int write_zbuf = (flags & IB_zbuffloat) && ibuf->zbuf_float != NULL; // summarize
+
try
{
Header header (width, height);
@@ -270,7 +270,7 @@ static short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
header.channels().insert ("B", Channel (FLOAT));
header.channels().insert ("A", Channel (FLOAT));
if (write_zbuf)
- header.channels().insert ("Z", Channel (UINT));
+ header.channels().insert ("Z", Channel (FLOAT));
FrameBuffer frameBuffer;
OutputFile *file = new OutputFile(name, header);
@@ -284,8 +284,8 @@ static short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
frameBuffer.insert ("A", Slice (FLOAT, (char *) (first+3), xstride, ystride));
if (write_zbuf)
- frameBuffer.insert ("Z", Slice (UINT, (char *) ibuf->zbuf + 4*(height-1)*width,
- sizeof(int), sizeof(int) * -width));
+ frameBuffer.insert ("Z", Slice (FLOAT, (char *) ibuf->zbuf_float + 4*(height-1)*width,
+ sizeof(float), sizeof(float) * -width));
file->setFrameBuffer (frameBuffer);
file->writePixels (height);
delete file;
@@ -407,12 +407,12 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags)
frameBuffer.insert ("A", Slice (FLOAT, (char *) (first+3), xstride, ystride, 1, 1, 1.0f));
if(exr_has_zbuffer(file)) {
- int *firstz;
+ float *firstz;
- addzbufImBuf(ibuf);
- firstz= ibuf->zbuf - (dw.min.x - dw.min.y*width);
+ addzbuffloatImBuf(ibuf);
+ firstz= ibuf->zbuf_float - (dw.min.x - dw.min.y*width);
firstz+= (height-1)*width;
- frameBuffer.insert ("Z", Slice (UINT, (char *)firstz , sizeof(int), -width*sizeof(int)));
+ frameBuffer.insert ("Z", Slice (FLOAT, (char *)firstz , sizeof(float), -width*sizeof(float)));
}
file->setFrameBuffer (frameBuffer);