Fix for bug #11128: render window shows undithered image.
[blender.git] / source / blender / blenkernel / intern / image.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;