=Reversion of premul bugfix=
authorJoseph Eagar <joeedh@gmail.com>
Fri, 22 Feb 2008 22:23:58 +0000 (22:23 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Fri, 22 Feb 2008 22:23:58 +0000 (22:23 +0000)
Reversion of premul bugfix, as it was apparently not
working all that well.

Note that this brings back the bug where the erase alpha
paint tool won't display correctly, since the UV image
editor just draws images in key alpha now.

source/blender/blenkernel/intern/image.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_image_types.h
source/blender/nodes/intern/CMP_nodes/CMP_image.c
source/blender/render/intern/source/texture.c
source/blender/src/buttons_shading.c
source/blender/src/drawimage.c
source/blender/src/drawnode.c

index 56744224449a807a195ac340b6024dc2449be2f0..d9b76ac210bac0a6b7fcb67297e535b4c7626e29 100644 (file)
@@ -1668,11 +1668,8 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra)
                                ima->packedfile = newPackedFile(str);
                }
                
-               /*ok, this is *not* what a user expects when he clicks the premul
-                 button, that his image is actually changed.  This should be a
-                 render-time option, not a modification to the image! - joeedh*/
-               /*if(ima->flag & IMA_DO_PREMUL)
-                       converttopremul(ibuf);*/
+               if(ima->flag & IMA_DO_PREMUL)
+                       converttopremul(ibuf);
        }
        else
                ima->ok= 0;
index 7621603b5700752cc5497241752391a8bde2ebf0..f9a5c419adc3db6377bb2dca0f954911f0890c1a 100644 (file)
@@ -2419,7 +2419,6 @@ static void lib_link_texture(FileData *fd, Main *main)
                if(tex->id.flag & LIB_NEEDLINK) {
 
                        tex->ima= newlibadr_us(fd, tex->id.lib, tex->ima);
-
                        tex->ipo= newlibadr_us(fd, tex->id.lib, tex->ipo);
                        if(tex->env) tex->env->object= newlibadr(fd, tex->id.lib, tex->env->object);
 
@@ -7451,58 +7450,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       /*version patch to migrate premul flag from images to image users*/
-       if (main->versionfile < 245 || (main->versionfile == 245 && main->subversionfile < 15)) {
-               Tex *tex;
-               Image *image;
-               ImageUser *iuser;
-               Scene *scene;
-               bNode *node;
-               bNodeTree *ntree;
-               
-               /*handle image textures*/
-               for (tex=main->tex.first; tex; tex=tex->id.next) {
-                       if (tex->ima) {
-                               image = newlibadr(fd, lib, tex->ima);
-                               if(image)
-                                       if (image->flag & IMA_OLDFLAG) 
-                                               tex->iuser.flag |= IMA_DO_PREMUL;
-                       }
-               }
-
-               /*handle composite node trees*/
-               for (scene=main->scene.first; scene; scene=scene->id.next) {
-                       if (scene->nodetree) {
-                               for (node=scene->nodetree->nodes.first; node; node=node->next) {
-                                       ID *nodeid = newlibadr(fd, lib, node->id);
-                                       if (node->storage && nodeid && GS(nodeid->name) == ID_IM) {
-                                               image = (Image*) nodeid;
-                                               iuser = node->storage;
-                                               if (image->flag & IMA_OLDFLAG) iuser->flag |= IMA_DO_PREMUL;
-                                       }
-                               }
-                       }
-               }
-
-               /*handle node groups*/
-               for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
-                       if (ntree->type == NTREE_COMPOSIT) {
-                               for (node=ntree->nodes.first; node; node=node->next) {
-                                       ID *nodeid = newlibadr(fd, lib, node->id);
-                                       if (node->storage && nodeid && GS(nodeid->name) == ID_IM) {
-                                               image = (Image*) nodeid;
-                                               iuser = node->storage;
-                                               if (image->flag & IMA_OLDFLAG) iuser->flag |= IMA_DO_PREMUL;
-                                       }
-                               }
-                       }
-               }
-
-               /*finally, remove the flag from all images*/
-               for (image=main->image.first; image; image=image->id.next) {
-                       if (image->flag & IMA_OLDFLAG) image->flag &= ~IMA_OLDFLAG;
-               }
-       }
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */
 
index bc94f807baa2c6d0f079c92753ec3eb018e11dae..d5e4b7a11420bc844670300ab9e9f0ac0f560a52 100644 (file)
@@ -58,7 +58,6 @@ typedef struct ImageUser {
 /* iuser->flag */
 #define        IMA_ANIM_ALWAYS         1
 #define IMA_ANIM_REFRESHED     2
-#define IMA_DO_PREMUL          4
 
 typedef struct Image {
        ID id;
@@ -109,12 +108,7 @@ typedef struct Image {
 #define        IMA_REFLECT             16
 #define IMA_NOCOLLECT   32
 #define IMA_ANTIALI            64
-
-/*used to be IMA_DO_PREMUL.  Note that
-  in theory, in should be possible
-  to use this flag position if necassary,
-  since this is only used in do_versions.*/
-#define IMA_OLDFLAG            128 
+#define IMA_DO_PREMUL  128
 
 /* tpageflag */
 #define IMA_TILES                      1
index 5df649d6808ff4ccc8fd8ae22c8fe83ed37bdce9..6a82e8a92547a459f639a07279bf773694757015 100644 (file)
@@ -58,7 +58,7 @@ static bNodeSocketType cmp_node_rlayers_out[]= {
 static CompBuf *node_composit_get_image(RenderData *rd, Image *ima, ImageUser *iuser)
 {
        ImBuf *ibuf;
-       CompBuf *stackbuf, *old;
+       CompBuf *stackbuf;
        int type;
        
        ibuf= BKE_image_get_ibuf(ima, iuser);
@@ -79,11 +79,10 @@ static CompBuf *node_composit_get_image(RenderData *rd, Image *ima, ImageUser *i
                stackbuf->rect= ibuf->rect_float;
        }
        
-       old = stackbuf;
-       stackbuf = dupalloc_compbuf(stackbuf);
-       free_compbuf(old);      
-
-       if (type==CB_RGBA && iuser && (iuser->flag & IMA_DO_PREMUL)) {
+       /*code to respect the premul flag of images; I'm
+         not sure if this is a good idea for multilayer images,
+         since it never worked before for them.
+       if (type==CB_RGBA && ima->flag & IMA_DO_PREMUL) {
                //premul the image
                int i;
                float *pixel = stackbuf->rect;
@@ -94,7 +93,7 @@ static CompBuf *node_composit_get_image(RenderData *rd, Image *ima, ImageUser *i
                        pixel[2] *= pixel[3];
                }
        }
-       
+       */
        return stackbuf;
 };
 
@@ -203,6 +202,25 @@ static void node_composit_exec_image(void *data, bNode *node, bNodeStack **in, b
                else {
                        stackbuf= node_composit_get_image(rd, ima, iuser);
                        
+                       /*respect image premul option*/
+                       if (stackbuf->type==CB_RGBA && ima->flag & IMA_DO_PREMUL) {
+                               int i;
+                               float *pixel;
+                       
+                               /*first duplicate stackbuf->rect, since it's just a pointer
+                                 to the source imbuf, and we don't want to change that.*/
+                               stackbuf->rect = MEM_dupallocN(stackbuf->rect);
+                               
+                               /*premul the image*/
+                               
+                               pixel = stackbuf->rect;
+                               for (i=0; i<stackbuf->x*stackbuf->y; i++, pixel += 4) {
+                                       pixel[0] *= pixel[3];
+                                       pixel[1] *= pixel[3];
+                                       pixel[2] *= pixel[3];
+                               }
+                       }
+                       
                        /* put image on stack */        
                        out[0]->data= stackbuf;
                        
index b77e30a777f5d09cb92c5a55cc9310ad0c3b0bee..831fe5dcc0bf173bd8b6230ae13d1b8a4be00fb4 100644 (file)
@@ -1138,13 +1138,6 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex,
                if(osatex) retval= imagewraposa(tex, tex->ima, NULL, texvec, dxt, dyt, texres); 
                else retval= imagewrap(tex, tex->ima, NULL, texvec, texres); 
                tag_image_time(tex->ima); /* tag image as having being used */
-               
-               /*do premul if necassary*/
-               if (tex->iuser.flag & IMA_DO_PREMUL) {
-                       texres->tr *= texres->ta;
-                       texres->tg *= texres->ta;
-                       texres->tb *= texres->ta;
-               }
                break;
        case TEX_PLUGIN:
                retval= plugintex(tex, texvec, dxt, dyt, osatex, texres);
index 7945b6bacd31bc0faa84a0198fb30828ccc8e55b..0325128daa28b7f82d7cbfe98e4bcd950ff6d844 100644 (file)
@@ -1181,7 +1181,7 @@ void uiblock_image_panel(uiBlock *block, Image **ima_pp, ImageUser *iuser,
                 
                 uiBlockSetFunc(block, image_reload_cb, ima, iuser);
                 uiDefButBitS(block, TOG, IMA_ANTIALI, B_NOP, "Anti",                   10, 50, 45, 20, &ima->flag, 0, 0, 0, 0, "Toggles Image anti-aliasing, only works with solid colors");
-                uiDefButBitS(block, TOG, IMA_DO_PREMUL, imagechanged, "Premul",                55, 50, 65, 20, &iuser->flag, 0, 0, 0, 0, "Toggles whether to premultiply the image at render/composite time.");
+                uiDefButBitS(block, TOG, IMA_DO_PREMUL, imagechanged, "Premul",                55, 50, 65, 20, &ima->flag, 0, 0, 0, 0, "Toggles premultiplying alpha");
                 uiBlockEndAlign(block);
                 
                 if( ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
@@ -2560,7 +2560,7 @@ static void lamp_panel_spot(Object *ob, Lamp *la)
                                tip= "Irregular buffer produces sharp shadow always, but it doesn't show up for raytracing";
                        else if(la->buftype==LA_SHADBUF_HALFWAY)
                                tip= "Regular buffer, averaging the closest and 2nd closest Z value for reducing biasing";
-                               
+                       
                        uiDefButC(block, MENU, B_REDR, "Classical %x0|Classic-Halfway %x2|Irregular %x1", 10,140,80,19,&la->buftype, 0, 0, 0, 0, tip);
                }
        }
@@ -2656,6 +2656,7 @@ static void lamp_panel_spot(Object *ob, Lamp *la)
                        }
                }
                
+               
        }
        else uiDefBut(block, LABEL,0," ",       100,180,200,19,NULL, 0, 0, 0, 0, "");
 
index 3db93cdba02bea33788bc19abb4ec86e9d21e77a..da00e644a6b77bbe82af40a59e444b0e23e2270b 100644 (file)
@@ -2058,11 +2058,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
                                                        if(sima->flag & SI_USE_ALPHA) {
                                                                sima_draw_alpha_backdrop(sima, x1_rep, y1_rep, ibuf->x*xuser_asp, ibuf->y*yuser_asp);
                                                                glEnable(GL_BLEND);
-                                                               /*use key alpha if the IMA_DO_PREMUL option is set.*/
-                                                               if (sima->iuser.flag & IMA_DO_PREMUL)
-                                                                       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-                                                               else
-                                                                       glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+                                                               glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
                                                        }
                                                        
                                                        /* detect if we need to redo the curve map. 
index 5b4975401b3d8fa988f43997ae2ee6053e8abb50..54475eb362e23c31eb8cf8b9a095a8759f5237c9 100644 (file)
@@ -938,7 +938,7 @@ static void image_layer_cb(void *ima_v, void *iuser_v)
 {
        
        ntreeCompositForceHidden(G.scene->nodetree);
-       BKE_image_multilayer_index(BKE_image_get_renderresult(ima_v), iuser_v);
+       BKE_image_multilayer_index(ima_v, iuser_v);
        allqueue(REDRAWNODE, 0);
 }
 
@@ -995,11 +995,6 @@ static int node_composit_buts_image(uiBlock *block, bNodeTree *ntree, bNode *nod
                        uiButSetFunc(bt, node_image_type_cb, node, ima);
                        MEM_freeN(strp);
                        
-                       if (iuser) {
-                               dy -= 19;
-                               uiDefButBitS(block, TOG, IMA_DO_PREMUL, B_NODE_EXEC+node->nr, "Premul", xmin, dy, xmax-xmin, 20, &iuser->flag, 0, 0, 0, 0, "Toggles whether to premultiply the image at render/composite time.");
-                       }
-
                        if( ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE) ) {
                                width= (xmax-xmin)/2;
                                
@@ -1039,7 +1034,7 @@ static int node_composit_buts_image(uiBlock *block, bNodeTree *ntree, bNode *nod
        }       
        if(node->id) {
                Image *ima= (Image *)node->id;
-               int retval= 19*2;
+               int retval= 19;
                
                /* for each draw we test for anim refresh event */
                if(iuser->flag & IMA_ANIM_REFRESHED) {