diff options
author | Ton Roosendaal <ton@blender.org> | 2006-01-12 01:36:31 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2006-01-12 01:36:31 +0300 |
commit | 0665f0d64799e6a38c4ca0930df73271f246e422 (patch) | |
tree | fa488d33452f0bfc6ec91e5bbbec726afcbcb9f3 /source | |
parent | b92fa4151645d50e40faa8f4aaea4b7f6149947c (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')
-rw-r--r-- | source/blender/imbuf/IMB_imbuf.h | 2 | ||||
-rw-r--r-- | source/blender/imbuf/IMB_imbuf_types.h | 4 | ||||
-rw-r--r-- | source/blender/imbuf/intern/allocimbuf.c | 43 | ||||
-rw-r--r-- | source/blender/imbuf/intern/divers.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_api.cpp | 28 | ||||
-rw-r--r-- | source/blender/include/BIF_glutil.h | 2 | ||||
-rw-r--r-- | source/blender/render/extern/include/render_types.h | 3 | ||||
-rw-r--r-- | source/blender/render/intern/source/initrender.c | 49 | ||||
-rw-r--r-- | source/blender/render/intern/source/rendercore.c | 2 | ||||
-rw-r--r-- | source/blender/src/drawimage.c | 49 | ||||
-rw-r--r-- | source/blender/src/drawseq.c | 2 | ||||
-rw-r--r-- | source/blender/src/drawview.c | 2 | ||||
-rw-r--r-- | source/blender/src/editsima.c | 17 | ||||
-rw-r--r-- | source/blender/src/glutil.c | 30 | ||||
-rw-r--r-- | source/blender/src/header_image.c | 13 | ||||
-rw-r--r-- | source/blender/src/previewrender.c | 4 | ||||
-rw-r--r-- | source/blender/src/renderwin.c | 15 | ||||
-rw-r--r-- | source/blender/src/toets.c | 6 |
18 files changed, 203 insertions, 69 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); diff --git a/source/blender/include/BIF_glutil.h b/source/blender/include/BIF_glutil.h index b585f91ec3e..af231de66f8 100644 --- a/source/blender/include/BIF_glutil.h +++ b/source/blender/include/BIF_glutil.h @@ -125,7 +125,7 @@ void glaRasterPosSafe2f (float x, float y, float known_good_x, float known_good * to use the glScissor functionality if images are to be drawn * with an inset view matrix. */ -void glaDrawPixelsSafe (float x, float y, int img_w, int img_h, int format, void *rect); +void glaDrawPixelsSafe (float x, float y, int img_w, int img_h, int format, int type, void *rect); /** * Functions like a limited glDrawPixels, but actually draws the diff --git a/source/blender/render/extern/include/render_types.h b/source/blender/render/extern/include/render_types.h index efb0863b94a..8fad87c2707 100644 --- a/source/blender/render/extern/include/render_types.h +++ b/source/blender/render/extern/include/render_types.h @@ -161,7 +161,8 @@ typedef struct RE_Render struct MemArena *memArena; int *rectaccu; - int *rectz; /* z buffer: distance buffer */ + int *rectz; /* z buffer: distance buffer */ + float *rectzf; /* z distances, camera space */ unsigned int *rectf1, *rectf2; unsigned int *rectot; /* z buffer: face index buffer, recycled as colour buffer! */ unsigned int *rectspare; /* */ diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index c0c175709e1..948c1179b3b 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -501,10 +501,12 @@ void RE_free_render_data() if(R.rectot) MEM_freeN(R.rectot); if(R.rectftot) MEM_freeN(R.rectftot); if(R.rectz) MEM_freeN(R.rectz); + if(R.rectzf) MEM_freeN(R.rectzf); if(R.rectspare) MEM_freeN(R.rectspare); R.rectot= NULL; R.rectftot= NULL; R.rectz= NULL; + R.rectzf= NULL; R.rectspare= NULL; free_filt_mask(); @@ -805,6 +807,43 @@ static void addparttorect(Part *pa) } } +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +static void convert_zbuf_to_distbuf(void) +{ + float *rectzf, zco; + int a, *rectz; + + if(R.rectz==NULL) return; + if(R.rectzf) { + printf("called convert zbuf wrong...\n"); + MEM_freeN(R.rectzf); + } + + /* need to make sure winmat is OK */ + R.xstart= -R.afmx; + R.ystart= -R.afmy; + R.xend= R.xstart+R.rectx-1; + R.yend= R.ystart+R.recty-1; + + RE_setwindowclip(0, -1); + + rectzf= R.rectzf= MEM_mallocN(R.rectx*R.recty*sizeof(float), "rectzf"); + rectz= R.rectz; + + for(a=R.rectx*R.recty; a>0; a--, rectz++, rectzf++) { + if(*rectz==0x7FFFFFFF) + *rectzf= 10e10; + else { + zco= ((float)*rectz)/2147483647.0f; + *rectzf= R.winmat[3][2]/(R.winmat[2][2] - R.winmat[2][3]*zco); + } + } + + MEM_freeN(R.rectz); + R.rectz= NULL; +} + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -872,6 +911,9 @@ static void add_to_blurbuf(int blur) } +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + + /* yafray: main yafray render/export call */ static void yafrayRender(void) { @@ -889,6 +931,8 @@ static void yafrayRender(void) R.rectot = MEM_callocN(sizeof(int)*R.rectx*R.recty, "rectot"); /* zbuf */ if (R.rectz) MEM_freeN(R.rectz); + if (R.rectzf) MEM_freeN(R.rectzf); + R.rectzf= NULL; R.rectz = (unsigned int *)MEM_mallocN(sizeof(int)*R.rectx*R.recty, "rectz"); /* float rgba buf */ if (R.rectftot) MEM_freeN(R.rectftot); @@ -970,6 +1014,8 @@ static void mainRenderLoop(void) /* here the PART and FIELD loops */ if(R.rectz) MEM_freeN(R.rectz); R.rectz = NULL; + if(R.rectzf) MEM_freeN(R.rectzf); + R.rectzf = NULL; if(R.rectftot) MEM_freeN(R.rectftot); R.rectftot = NULL; @@ -1448,6 +1494,9 @@ void RE_initrender(struct View3D *ogl_render_view3d) /* grms... this is a nasty global */ do_gamma= 0; + /* for now, we do always */ + convert_zbuf_to_distbuf(); + /* these flags remain on, until reset in caller to render (renderwin.c) */ R.flag &= (R_RENDERING|R_ANIMRENDER|R_REDRAW_PRV); } diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 5ad6f4e84a9..24751c6a66f 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -2345,7 +2345,7 @@ void *shadepixel(float x, float y, int z, int facenr, int mask, float *col, floa float zco; /* inverse of zbuf calc: zbuf = MAXZ*hoco_z/hoco_w */ - zco= ((float)z)/(float)0x7FFFFFFF; + zco= ((float)z)/2147483647.0f; shi.co[2]= R.winmat[3][2]/( R.winmat[2][3]*zco - R.winmat[2][2] ); fac= zcor= shi.co[2]/shi.view[2]; diff --git a/source/blender/src/drawimage.c b/source/blender/src/drawimage.c index 6be938236ff..0f5edee1328 100644 --- a/source/blender/src/drawimage.c +++ b/source/blender/src/drawimage.c @@ -49,10 +49,12 @@ #include "IMB_imbuf_types.h" +#include "DNA_camera_types.h" #include "DNA_color_types.h" #include "DNA_image_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" +#include "DNA_object_types.h" #include "DNA_packedFile_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" @@ -1104,7 +1106,7 @@ static void sima_draw_alpha_pixels(float x1, float y1, int rectx, int recty, uns /* swap bytes, so alpha is most significant one, then just draw it as luminance int */ glPixelStorei(GL_UNPACK_SWAP_BYTES, 1); - glaDrawPixelsSafe(x1, y1, rectx, recty, GL_UNSIGNED_INT, recti); + glaDrawPixelsSafe(x1, y1, rectx, recty, GL_LUMINANCE, GL_UNSIGNED_INT, recti); glPixelStorei(GL_UNPACK_SWAP_BYTES, 0); } @@ -1112,7 +1114,7 @@ static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int { if(recti==NULL) return; - + /* zbuffer values are signed, so we need to shift color range */ glPixelTransferf(GL_RED_SCALE, 0.5f); glPixelTransferf(GL_GREEN_SCALE, 0.5f); @@ -1121,8 +1123,8 @@ static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int glPixelTransferf(GL_GREEN_BIAS, 0.5f); glPixelTransferf(GL_BLUE_BIAS, 0.5f); - glaDrawPixelsSafe(x1, y1, rectx, recty, GL_INT, recti); - + glaDrawPixelsSafe(x1, y1, rectx, recty, GL_LUMINANCE, GL_INT, recti); + glPixelTransferf(GL_RED_SCALE, 1.0f); glPixelTransferf(GL_GREEN_SCALE, 1.0f); glPixelTransferf(GL_BLUE_SCALE, 1.0f); @@ -1131,6 +1133,32 @@ static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int glPixelTransferf(GL_BLUE_BIAS, 0.0f); } +static void sima_draw_zbuffloat_pixels(float x1, float y1, int rectx, int recty, float *rect_float) +{ + float bias, scale, *rectf; + int a; + + if(rect_float==NULL) + return; + + if(G.scene->camera && G.scene->camera->type==OB_CAMERA) { + bias= ((Camera *)G.scene->camera->data)->clipsta; + scale= 1.0f/((Camera *)G.scene->camera->data)->clipend; + } + else { + bias= 0.1f; + scale= 0.01f; + } + + rectf= MEM_mallocN(rectx*recty*4, "temp"); + for(a= rectx*recty -1; a>=0; a--) + rectf[a]= (rect_float[a]-bias)*scale; + + glaDrawPixelsSafe(x1, y1, rectx, recty, GL_LUMINANCE, GL_FLOAT, rectf); + + MEM_freeN(rectf); +} + void drawimagespace(ScrArea *sa, void *spacedata) { SpaceImage *sima= spacedata; @@ -1188,7 +1216,7 @@ void drawimagespace(ScrArea *sa, void *spacedata) glPixelZoom((float)sima->zoom, (float)sima->zoom); if(sima->flag & SI_EDITTILE) { - glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect); + glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); glPixelZoom(1.0, 1.0); @@ -1233,7 +1261,7 @@ void drawimagespace(ScrArea *sa, void *spacedata) /* rect= ibuf->rect; */ for(sy= 0; sy+dy<=ibuf->y; sy+= dy) { for(sx= 0; sx+dx<=ibuf->x; sx+= dx) { - glaDrawPixelsSafe(x1+sx*sima->zoom, y1+sy*sima->zoom, dx, dy, GL_UNSIGNED_BYTE, rect); + glaDrawPixelsSafe(x1+sx*sima->zoom, y1+sy*sima->zoom, dx, dy, GL_RGBA, GL_UNSIGNED_BYTE, rect); } } @@ -1244,14 +1272,17 @@ void drawimagespace(ScrArea *sa, void *spacedata) sima_draw_alpha_pixels(x1, y1, ibuf->x, ibuf->y, ibuf->rect); } else if(sima->flag & SI_SHOW_ZBUF) { - sima_draw_zbuf_pixels(x1, y1, ibuf->x, ibuf->y, ibuf->zbuf); + if(ibuf->zbuf) + sima_draw_zbuf_pixels(x1, y1, ibuf->x, ibuf->y, ibuf->zbuf); + else + sima_draw_zbuffloat_pixels(x1, y1, ibuf->x, ibuf->y, ibuf->zbuf_float); } else { if(sima->flag & SI_USE_ALPHA) { sima_draw_alpha_backdrop(sima, x1, y1, (float)ibuf->x, (float)ibuf->y); glEnable(GL_BLEND); } - glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect); + glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); if(sima->flag & SI_USE_ALPHA) glDisable(GL_BLEND); @@ -1273,7 +1304,7 @@ void drawimagespace(ScrArea *sa, void *spacedata) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glaDrawPixelsSafe(x1 + offx, y1 + offy, w, h, GL_UNSIGNED_BYTE, clonerect); + glaDrawPixelsSafe(x1 + offx, y1 + offy, w, h, GL_RGBA, GL_UNSIGNED_BYTE, clonerect); glDisable(GL_BLEND); MEM_freeN(clonerect); diff --git a/source/blender/src/drawseq.c b/source/blender/src/drawseq.c index ea39e172d7e..36647ea5064 100644 --- a/source/blender/src/drawseq.c +++ b/source/blender/src/drawseq.c @@ -503,7 +503,7 @@ static void draw_image_seq(ScrArea *sa) glaDefine2DArea(&curarea->winrct); glPixelZoom(zoom, zoom); - glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect); + glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); glPixelZoom(1.0, 1.0); diff --git a/source/blender/src/drawview.c b/source/blender/src/drawview.c index b6007dad9e7..f065a052dd7 100644 --- a/source/blender/src/drawview.c +++ b/source/blender/src/drawview.c @@ -435,7 +435,7 @@ static void draw_bgpic(void) glaDefine2DArea(&curarea->winrct); glPixelZoom(zoomx, zoomy); - glaDrawPixelsSafe(x1, y1, ima->ibuf->x, ima->ibuf->y, GL_UNSIGNED_BYTE, bgpic->rect); + glaDrawPixelsSafe(x1, y1, ima->ibuf->x, ima->ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, bgpic->rect); glPixelZoom(1.0, 1.0); glMatrixMode(GL_PROJECTION); diff --git a/source/blender/src/editsima.c b/source/blender/src/editsima.c index 93dab74debc..72e1baa17f3 100644 --- a/source/blender/src/editsima.c +++ b/source/blender/src/editsima.c @@ -1398,7 +1398,7 @@ int minmax_tface_uv(float *min, float *max) return sel; } -static void sima_show_info(int x, int y, char *cp, float *fp, int *zp) +static void sima_show_info(int x, int y, char *cp, float *fp, int *zp, float *zpf) { short ofs; char str[256]; @@ -1410,6 +1410,8 @@ static void sima_show_info(int x, int y, char *cp, float *fp, int *zp) ofs+= sprintf(str+ofs, "| R: %.3f G: %.3f B: %.3f A: %.3f ", fp[0], fp[1], fp[2], fp[3]); if(zp) ofs+= sprintf(str+ofs, "| Z: %.4f ", 0.5+0.5*( ((float)*zp)/(float)0x7fffffff)); + if(zpf) + ofs+= sprintf(str+ofs, "| Z: %.3f ", *zpf); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); @@ -1446,7 +1448,7 @@ void sima_sample_color(void) areamouseco_to_ipoco(G.v2d, mval, &fx, &fy); if(fx>=0.0 && fy>=0.0 && fx<1.0 && fy<1.0) { - float *fp= NULL; + float *fp= NULL, *zpf= NULL; int *zp= NULL; char *cp= NULL; @@ -1456,12 +1458,13 @@ void sima_sample_color(void) if(x>=ibuf->x) x= ibuf->x-1; if(y>=ibuf->y) y= ibuf->y-1; - if(ibuf->rect) { + if(ibuf->rect) cp= (char *)(ibuf->rect + y*ibuf->x + x); - } - if(ibuf->zbuf) { + if(ibuf->zbuf) zp= ibuf->zbuf + y*ibuf->x + x; - } + if(ibuf->zbuf_float) + zpf= ibuf->zbuf_float + y*ibuf->x + x; + if(ibuf->rect_float) { fp= (ibuf->rect_float + 4*(y*ibuf->x + x)); @@ -1480,7 +1483,7 @@ void sima_sample_color(void) scrarea_do_windraw(curarea); myortho2(-0.375, curarea->winx-0.375, -0.375, curarea->winy-0.375); glLoadIdentity(); - sima_show_info(x, y, cp, fp, zp); + sima_show_info(x, y, cp, fp, zp, zpf); screen_swapbuffers(); } diff --git a/source/blender/src/glutil.c b/source/blender/src/glutil.c index cc5c2f3c9ec..a8e10f05b28 100644 --- a/source/blender/src/glutil.c +++ b/source/blender/src/glutil.c @@ -286,7 +286,7 @@ void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void * glPixelStorei(GL_UNPACK_ROW_LENGTH, lrowlength); } -void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int format, void *rect) +void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int format, int type, void *rect) { float xzoom= glaGetOneFloat(GL_ZOOM_X); float yzoom= glaGetOneFloat(GL_ZOOM_Y); @@ -339,17 +339,25 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int format, void } glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w); - if(format==GL_FLOAT) { - float *f_rect= (float *)rect; - glDrawPixels(draw_w, draw_h, GL_RGBA, GL_FLOAT, f_rect + (off_y*img_w + off_x)*4); - } - else if(format==GL_INT || format==GL_UNSIGNED_INT) { - int *i_rect= (int *)rect; - glDrawPixels(draw_w, draw_h, GL_LUMINANCE, format, i_rect + (off_y*img_w + off_x)); + if(format==GL_LUMINANCE || format==GL_RED) { + if(type==GL_FLOAT) { + float *f_rect= (float *)rect; + glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y*img_w + off_x)); + } + else if(type==GL_INT || type==GL_UNSIGNED_INT) { + int *i_rect= (int *)rect; + glDrawPixels(draw_w, draw_h, format, type, i_rect + (off_y*img_w + off_x)); + } } - else { - unsigned char *uc_rect= (unsigned char *) rect; - glDrawPixels(draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, uc_rect + (off_y*img_w + off_x)*4); + else { /* RGBA */ + if(type==GL_FLOAT) { + float *f_rect= (float *)rect; + glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y*img_w + off_x)*4); + } + else if(type==GL_UNSIGNED_BYTE) { + unsigned char *uc_rect= (unsigned char *) rect; + glDrawPixels(draw_w, draw_h, format, type, uc_rect + (off_y*img_w + off_x)*4); + } } glPixelStorei(GL_UNPACK_ROW_LENGTH, old_row_length); diff --git a/source/blender/src/header_image.c b/source/blender/src/header_image.c index 29546276fd8..22cd439f543 100644 --- a/source/blender/src/header_image.c +++ b/source/blender/src/header_image.c @@ -1186,12 +1186,13 @@ void image_buttons(void) xco+= XIC; uiDefIconButBitS(block, TOG, SI_SHOW_ALPHA, B_SIMA_SHOW_ALPHA, ICON_DOT, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws only alpha"); xco+= XIC; - if(G.sima->image->ibuf && G.sima->image->ibuf->zbuf) { - uiDefIconButBitS(block, TOG, SI_SHOW_ZBUF, B_SIMA_SHOW_ZBUF, ICON_SOLID, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws zbuffer values"); - xco+= XIC; - } - else G.sima->flag &= ~SI_SHOW_ZBUF; /* no confusing display for non-zbuf images */ - + if(G.sima->image->ibuf) { + if(G.sima->image->ibuf->zbuf || G.sima->image->ibuf->zbuf_float) { + uiDefIconButBitS(block, TOG, SI_SHOW_ZBUF, B_SIMA_SHOW_ZBUF, ICON_SOLID, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws zbuffer values"); + xco+= XIC; + } + else G.sima->flag &= ~SI_SHOW_ZBUF; /* no confusing display for non-zbuf images */ + } uiBlockEndAlign(block); xco+= 8; } diff --git a/source/blender/src/previewrender.c b/source/blender/src/previewrender.c index 6d9c327d2f0..a632eb6661e 100644 --- a/source/blender/src/previewrender.c +++ b/source/blender/src/previewrender.c @@ -316,11 +316,11 @@ static void display_pr_scanline(unsigned int *rect, int recty, short pr_rectx) if( (recty & 3)==3) { if(recty == 3) { - glaDrawPixelsSafe(prerect.xmin, prerect.ymin, pr_rectx, 4, GL_UNSIGNED_BYTE, rect); + glaDrawPixelsSafe(prerect.xmin, prerect.ymin, pr_rectx, 4, GL_RGBA, GL_UNSIGNED_BYTE, rect); } else { rect+= (recty-4)*pr_rectx; - glaDrawPixelsSafe(prerect.xmin, prerect.ymin + (((float)recty-4.0)*pr_facy), pr_rectx, 5, GL_UNSIGNED_BYTE, rect); + glaDrawPixelsSafe(prerect.xmin, prerect.ymin + (((float)recty-4.0)*pr_facy), pr_rectx, 5, GL_RGBA, GL_UNSIGNED_BYTE, rect); } } } diff --git a/source/blender/src/renderwin.c b/source/blender/src/renderwin.c index ca81ec97b6b..51ff8ea3219 100644 --- a/source/blender/src/renderwin.c +++ b/source/blender/src/renderwin.c @@ -328,11 +328,11 @@ static void renderwin_draw(RenderWin *rw, int just_clear) if(rw->flags & RW_FLAGS_ALPHA) { /* swap bytes, so alpha is most significant one, then just draw it as luminance int */ glPixelStorei(GL_UNPACK_SWAP_BYTES, 1); - glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_INT, R.rectot); + glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_LUMINANCE, GL_UNSIGNED_INT, R.rectot); glPixelStorei(GL_UNPACK_SWAP_BYTES, 0); } else { - glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_BYTE, R.rectot); + glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_RGBA, GL_UNSIGNED_BYTE, R.rectot); } glPixelZoom(1.0, 1.0); } @@ -363,7 +363,6 @@ static void renderwin_mouse_moved(RenderWin *rw) if (rw->flags & RW_FLAGS_PIXEL_EXAMINING) { int imgco[2], ofs; char buf[128]; - int *pxlz; // zbuffer is signed char *pxl; if (R.rectot && renderwin_win_to_image_co(rw, rw->lmouse, imgco)) { @@ -375,9 +374,9 @@ static void renderwin_mouse_moved(RenderWin *rw) float *pxlf= R.rectftot + 4*(R.rectx*imgco[1] + imgco[0]); ofs+= sprintf(buf+ofs, " | R: %.3f G: %.3f B: %.3f A: %.3f ", pxlf[0], pxlf[1], pxlf[2], pxlf[3]); } - if (R.rectz) { - pxlz= &R.rectz[R.rectx*imgco[1] + imgco[0]]; - sprintf(buf+ofs, "| Z: %f", 0.5+0.5*( ((float)*pxlz)/(float)INT_MAX) ); + if (R.rectzf) { + float *pxlz= &R.rectzf[R.rectx*imgco[1] + imgco[0]]; + sprintf(buf+ofs, "| Z: %.3f", *pxlz ); } renderwin_set_infotext(rw, buf); @@ -740,7 +739,7 @@ static void renderwin_progress(RenderWin *rw, int start_y, int nlines, int rect_ glDrawBuffer(GL_FRONT); glPixelZoom(rw->zoom, rw->zoom); - glaDrawPixelsSafe(disprect[0][0], disprect[0][1] + start_y*rw->zoom, rect_w, nlines, GL_UNSIGNED_BYTE, &rect[start_y*rect_w*4]); + glaDrawPixelsSafe(disprect[0][0], disprect[0][1] + start_y*rw->zoom, rect_w, nlines, GL_RGBA, GL_UNSIGNED_BYTE, &rect[start_y*rect_w*4]); glPixelZoom(1.0, 1.0); glFlush(); glDrawBuffer(GL_BACK); @@ -827,7 +826,7 @@ static void renderview_progress_display_cb(int y1, int y2, int w, int h, unsigne sy= vb.ymin + facy*y1; glPixelZoom(facx, facy); - glaDrawPixelsSafe(sx, sy, w, nlines, GL_UNSIGNED_BYTE, rect+w*y1); + glaDrawPixelsSafe(sx, sy, w, nlines, GL_RGBA, GL_UNSIGNED_BYTE, rect+w*y1); glPixelZoom(1.0, 1.0); glFlush(); diff --git a/source/blender/src/toets.c b/source/blender/src/toets.c index 62f31f7f585..8eba2c0acd8 100644 --- a/source/blender/src/toets.c +++ b/source/blender/src/toets.c @@ -217,8 +217,8 @@ void schrijfplaatje(char *name) ibuf->ftype |= (R.r.quality & OPENEXR_COMPRESS); - if(R.rectz && (R.r.subimtype & R_OPENEXR_ZBUF)) - ibuf->zbuf = (int *)R.rectz; + if(R.rectzf && (R.r.subimtype & R_OPENEXR_ZBUF)) + ibuf->zbuf_float = R.rectzf; } #endif else if((R.r.imtype==R_TARGA) || (R.r.imtype==R_PNG)) { @@ -241,7 +241,7 @@ void schrijfplaatje(char *name) RE_make_existing_file(name); - if(IMB_saveiff(ibuf, name, IB_rect | IB_zbuf)==0) { + if(IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat)==0) { perror(name); G.afbreek= 1; } |