Fix for bug #8366, render color sampling bugs and inconsistencies:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 3 Mar 2008 16:38:27 +0000 (16:38 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 3 Mar 2008 16:38:27 +0000 (16:38 +0000)
- renderwindow didn't show values of previous buffer correct.
- renderwindow only showed floats and no char values like image editor.
- renderwindow didn't show x,y values.
- image editor didn't show z values.

Patch to fix these problems provided by Rob Hausauer, thanks!

source/blender/blenkernel/intern/image.c
source/blender/src/renderwin.c

index d9b76ac210bac0a6b7fcb67297e535b4c7626e29..094e35d6c8b0a8e0b728118a8f7e698558f29f64 100644 (file)
@@ -1770,6 +1770,8 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser)
                        ibuf->rect_float= rectf;
                        ibuf->flags |= IB_rectfloat;
                        ibuf->channels= channels;
+                       ibuf->zbuf_float= rres.rectz;
+                       ibuf->flags |= IB_zbuffloat;
                        
                        ima->ok= IMA_OK_LOADED;
                        return ibuf;
index 1bbe3f6d7b4b1fec246d62d75a58b761b16584f9..4510e72e659ceed86590b71d37c618d3278c2012 100644 (file)
@@ -352,6 +352,7 @@ static void renderwin_draw(RenderWin *rw, int just_clear)
                                rres.recty= rspare->ibuf->y;
                                rres.rect32= (int *)rspare->ibuf->rect;
                                rres.rectf= rspare->ibuf->rect_float;
+                               rres.rectz= rspare->ibuf->zbuf_float;
                        }
                        else
                                memset(&rres, 0, sizeof(rres));
@@ -429,11 +430,26 @@ static void renderwin_zoom(RenderWin *rw, int ZoomIn) {
        renderwin_queue_redraw(rw);
 }
 
+#define FTOCHAR(val) val<=0.0f? 0 : (val>=(1.0f-0.5f/255.0f)? 255 :(char)((255.0f*val)+0.5f))
+
 static void renderwin_mouse_moved(RenderWin *rw)
 {
        RenderResult rres;
-       
-       RE_GetResultImage(RE_GetRender(G.scene->id.name), &rres);
+       RenderSpare *rspare= render_spare;
+               
+       if(rspare && rspare->showspare) {
+               if(rspare->ibuf) {
+                       rres.rectx= rspare->ibuf->x;
+                       rres.recty= rspare->ibuf->y;
+                       rres.rect32= (int *)rspare->ibuf->rect;
+                       rres.rectf= rspare->ibuf->rect_float;
+                       rres.rectz= rspare->ibuf->zbuf_float;
+               }
+               else
+                       memset(&rres, 0, sizeof(rres));
+       }
+       else
+               RE_GetResultImage(RE_GetRender(G.scene->id.name), &rres);
 
        if (rw->flags & RW_FLAGS_PIXEL_EXAMINING) {
                int imgco[2], ofs=0;
@@ -441,12 +457,16 @@ static void renderwin_mouse_moved(RenderWin *rw)
                char *pxl;
 
                if (renderwin_win_to_image_co(rw, rw->lmouse, imgco)) {
+                       ofs= sprintf(buf, "X: %d Y: %d ", imgco[0], imgco[1]);
                        if (rres.rect32) {
                                pxl= (char*) &rres.rect32[rres.rectx*imgco[1] + imgco[0]];
-                               ofs= sprintf(buf, "R: %d G: %d B: %d A: %d", pxl[0], pxl[1], pxl[2], pxl[3]);   
+                               ofs+= sprintf(buf+ofs, " | R: %d G: %d B: %d A: %d", pxl[0], pxl[1], pxl[2], pxl[3]);   
                        }
                        if (rres.rectf) {
                                float *pxlf= rres.rectf + 4*(rres.rectx*imgco[1] + imgco[0]);
+                               if(!rres.rect32){
+                                       ofs+= sprintf(buf+ofs, " | R: %d G: %d B: %d A: %d", FTOCHAR(pxlf[0]), FTOCHAR(pxlf[1]), FTOCHAR(pxlf[2]), FTOCHAR(pxlf[3]));
+                               }
                                ofs+= sprintf(buf+ofs, " | R: %.3f G: %.3f B: %.3f A: %.3f ", pxlf[0], pxlf[1], pxlf[2], pxlf[3]);
                        }
                        if (rres.rectz) {
@@ -1159,11 +1179,16 @@ static int render_store_spare(void)
                rspare->ibuf->flags |= IB_rect;
                rspare->ibuf->mall |= IB_rect;
        }
-       else if(rres.rectf) {
+       if(rres.rectf) {
                rspare->ibuf->rect_float= MEM_dupallocN(rres.rectf);
                rspare->ibuf->flags |= IB_rectfloat;
                rspare->ibuf->mall |= IB_rectfloat;
        }
+       if(rres.rectz) {
+               rspare->ibuf->zbuf_float= MEM_dupallocN(rres.rectz);
+               rspare->ibuf->flags |= IB_zbuffloat;
+               rspare->ibuf->mall |= IB_zbuffloat;
+       }
 
        return 1;
 }