Fix for bug #11128: render window shows undithered image.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 12 May 2008 17:41:03 +0000 (17:41 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 12 May 2008 17:41:03 +0000 (17:41 +0000)
source/blender/blenkernel/intern/image.c
source/blender/src/renderwin.c

index ff0b2e6db0a4c6df216fb28d1c22907694feb7d0..bc44bfa988df74a1998cb5ecac7c38046f0e6359 100644 (file)
@@ -1728,31 +1728,38 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser)
 {
        RenderResult *rr= RE_GetResult(RE_GetRender(G.scene->id.name));
        
-       if(rr && iuser) {
+       if(rr) {
                RenderResult rres;
                float *rectf;
                unsigned int *rect;
-               int channels= 4, layer= iuser->layer;
+               float dither;
+               int channels, layer, pass;
+
+               channels= 4;
+               layer= (iuser)? iuser->layer: 0;
+               pass= (iuser)? iuser->pass: 0;
                
                /* this gives active layer, composite or seqence result */
                RE_GetResultImage(RE_GetRender(G.scene->id.name), &rres);
                rect= (unsigned int *)rres.rect32;
                rectf= rres.rectf;
-               
+               dither= G.scene->r.dither_intensity;
+
                /* get compo/seq result by default */
                if(rr->rectf && layer==0);
                else if(rr->layers.first) {
-                       RenderLayer *rl= BLI_findlink(&rr->layers, iuser->layer-(rr->rectf?1:0));
+                       RenderLayer *rl= BLI_findlink(&rr->layers, layer-(rr->rectf?1:0));
                        if(rl) {
                                /* there's no combined pass, is in renderlayer itself */
-                               if(iuser->pass==0) {
+                               if(pass==0) {
                                        rectf= rl->rectf;
                                }
                                else {
-                                       RenderPass *rpass= BLI_findlink(&rl->passes, iuser->pass-1);
+                                       RenderPass *rpass= BLI_findlink(&rl->passes, pass-1);
                                        if(rpass) {
                                                channels= rpass->channels;
                                                rectf= rpass->rect;
+                                               dither= 0.0f; /* don't dither passes */
                                        }
                                }
                        }
@@ -1779,6 +1786,7 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser)
                        ibuf->channels= channels;
                        ibuf->zbuf_float= rres.rectz;
                        ibuf->flags |= IB_zbuffloat;
+                       ibuf->dither= dither;
                        
                        ima->ok= IMA_OK_LOADED;
                        return ibuf;
index 7699de4138160b4283ba8b1d4d57bbfc54c0e7b7..6c150f3d30f237dd67e19644934aa34409a5ca05 100644 (file)
@@ -311,6 +311,8 @@ static void renderwin_draw_render_info(RenderWin *rw)
 
 static void renderwin_draw(RenderWin *rw, int just_clear)
 {
+       Image *ima;
+       ImBuf *ibuf;
        float fullrect[2][2];
        int set_back_mainwindow;
        rcti rect;
@@ -340,50 +342,45 @@ static void renderwin_draw(RenderWin *rw, int just_clear)
                glColor3ub(0, 0, 0);
                glRectfv(fullrect[0], fullrect[1]);
        } else {
-               RenderResult 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));
+                       ibuf= rspare->ibuf;
+               }
+               else {
+                       ima= BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result");
+                       ibuf= BKE_image_get_ibuf(ima, NULL);
                }
-               else
-                       RE_GetResultImage(RE_GetRender(G.scene->id.name), &rres);
                
-               if(rres.rectf || rres.rect32) {
+               if(ibuf) {
+                       if(!ibuf->rect)
+                               IMB_rect_from_float(ibuf);
                        
                        glPixelZoom(rw->zoom, rw->zoom);
                        if(rw->flags & RW_FLAGS_ALPHA) {
-                               if(rres.rect32) {
+                               if(ibuf->rect) {
                                        /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
                                        if(G.order==B_ENDIAN)
                                                glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
-                                       glaDrawPixelsSafe(fullrect[0][0], fullrect[0][1], rres.rectx, rres.recty, rres.rectx, GL_LUMINANCE, GL_UNSIGNED_INT, rres.rect32);
+                                       glaDrawPixelsSafe(fullrect[0][0], fullrect[0][1], ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, ibuf->rect);
                                        glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
                                }
                                else {
-                                       float *trectf= MEM_mallocN(rres.rectx*rres.recty*4, "temp");
+                                       float *trectf= MEM_mallocN(ibuf->x*ibuf->y*4, "temp");
                                        int a, b;
                                        
-                                       for(a= rres.rectx*rres.recty -1, b= 4*a+3; a>=0; a--, b-=4)
-                                               trectf[a]= rres.rectf[b];
+                                       for(a= ibuf->x*ibuf->y -1, b= 4*a+3; a>=0; a--, b-=4)
+                                               trectf[a]= ibuf->rect_float[b];
                                        
-                                       glaDrawPixelsSafe(fullrect[0][0], fullrect[0][1], rres.rectx, rres.recty, rres.rectx, GL_LUMINANCE, GL_FLOAT, trectf);
+                                       glaDrawPixelsSafe(fullrect[0][0], fullrect[0][1], ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_FLOAT, trectf);
                                        MEM_freeN(trectf);
                                }
                        }
                        else {
-                               if(rres.rect32)
-                                       glaDrawPixelsSafe(fullrect[0][0], fullrect[0][1], rres.rectx, rres.recty, rres.rectx, GL_RGBA, GL_UNSIGNED_BYTE, rres.rect32);
-                               else if(rres.rectf)
-                                       glaDrawPixelsSafe_to32(fullrect[0][0], fullrect[0][1], rres.rectx, rres.recty, rres.rectx, rres.rectf);
+                               if(ibuf->rect)
+                                       glaDrawPixelsSafe(fullrect[0][0], fullrect[0][1], ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+                               else if(ibuf->rect_float)
+                                       glaDrawPixelsSafe_to32(fullrect[0][0], fullrect[0][1], ibuf->x, ibuf->y, ibuf->x, ibuf->rect_float);
                        }
                        glPixelZoom(1.0, 1.0);
                }
@@ -431,22 +428,20 @@ static void renderwin_zoom(RenderWin *rw, int ZoomIn) {
 
 static void renderwin_mouse_moved(RenderWin *rw)
 {
-       RenderResult rres;
+       Image *ima;
+       ImBuf *ibuf;
        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));
+               ibuf= rspare->ibuf;
        }
-       else
-               RE_GetResultImage(RE_GetRender(G.scene->id.name), &rres);
+       else {
+               ima= BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result");
+               ibuf= BKE_image_get_ibuf(ima, NULL);
+       }
+
+       if(!ibuf)
+               return;
 
        if (rw->flags & RW_FLAGS_PIXEL_EXAMINING) {
                int imgco[2], ofs=0;
@@ -455,19 +450,19 @@ static void renderwin_mouse_moved(RenderWin *rw)
 
                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]];
+                       if (ibuf->rect) {
+                               pxl= (char*) &ibuf->rect[ibuf->x*imgco[1] + imgco[0]];
                                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){
+                       if (ibuf->rect_float) {
+                               float *pxlf= ibuf->rect_float + 4*(ibuf->x*imgco[1] + imgco[0]);
+                               if(!ibuf->rect) {
                                        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) {
-                               float *pxlz= &rres.rectz[rres.rectx*imgco[1] + imgco[0]];                       
+                       if (ibuf->zbuf_float) {
+                               float *pxlz= &ibuf->zbuf_float[ibuf->x*imgco[1] + imgco[0]];                    
                                sprintf(buf+ofs, "| Z: %.3f", *pxlz );
                        }
 
@@ -484,8 +479,8 @@ static void renderwin_mouse_moved(RenderWin *rw)
        
                rw->zoomofs[0]= rw->pan_ofs_start[0] - delta_x/rw->zoom;
                rw->zoomofs[1]= rw->pan_ofs_start[1] - delta_y/rw->zoom;
-               rw->zoomofs[0]= CLAMPIS(rw->zoomofs[0], -rres.rectx/2, rres.rectx/2);
-               rw->zoomofs[1]= CLAMPIS(rw->zoomofs[1], -rres.recty/2, rres.recty/2);
+               rw->zoomofs[0]= CLAMPIS(rw->zoomofs[0], -ibuf->x/2, ibuf->x/2);
+               rw->zoomofs[1]= CLAMPIS(rw->zoomofs[1], -ibuf->y/2, ibuf->y/2);
 
                renderwin_queue_redraw(rw);
        } 
@@ -497,8 +492,8 @@ static void renderwin_mouse_moved(RenderWin *rw)
                h-= RW_HEADERY;
                renderwin_win_to_ndc(rw, rw->lmouse, ndc);
 
-               rw->zoomofs[0]= -0.5*ndc[0]*(w-rres.rectx*rw->zoom)/rw->zoom;
-               rw->zoomofs[1]= -0.5*ndc[1]*(h-rres.recty*rw->zoom)/rw->zoom;
+               rw->zoomofs[0]= -0.5*ndc[0]*(w-ibuf->x*rw->zoom)/rw->zoom;
+               rw->zoomofs[1]= -0.5*ndc[1]*(h-ibuf->y*rw->zoom)/rw->zoom;
 
                renderwin_queue_redraw(rw);
        }
@@ -1186,6 +1181,7 @@ static int render_store_spare(void)
        RE_GetResultImage(RE_GetRender(G.scene->id.name), &rres);
 
        rspare->ibuf= IMB_allocImBuf(rres.rectx, rres.recty, 32, 0, 0);
+       rspare->ibuf->dither= G.scene->r.dither_intensity;
        
        if(rres.rect32) {
                rspare->ibuf->rect= MEM_dupallocN(rres.rect32);
@@ -1291,6 +1287,8 @@ void BIF_do_render(int anim)
                allqueue(REDRAWNODE, 1);
                allqueue(REDRAWIMAGE, 1);
        }
+       if(G.scene->r.dither_intensity != 0.0f)
+               BIF_redraw_render_rect();
        if (slink_flag) G.f |= G_DOSCRIPTLINKS;
        if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_POSTRENDER);
 }