Merging r50119 through r50132 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / space_node / drawnode.c
index c1a410317b783a205456ee26724088db56efe241..ddea7da929ac1d49aad7174acbe216ba038b9f41 100644 (file)
@@ -63,6 +63,7 @@
 
 #include "UI_resources.h"
 
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
@@ -1324,6 +1325,10 @@ static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA
 
        uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
        uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE);
+       uiItemR(layout, ptr, "projection", 0, "", ICON_NONE);
+
+       if(RNA_enum_get(ptr, "projection") == SHD_PROJ_BOX)
+               uiItemR(layout, ptr, "projection_blend", 0, "Blend", ICON_NONE);
 
        /* note: image user properties used directly here, unlike compositor image node,
         * which redefines them in the node struct RNA to get proper updates.
@@ -1812,6 +1817,15 @@ static void node_composit_buts_inpaint(uiLayout *layout, bContext *UNUSED(C), Po
        uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE);
 }
 
+static void node_composit_buts_despeckle(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+       uiLayout *col;
+
+       col = uiLayoutColumn(layout, FALSE);
+       uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE);
+       uiItemR(col, ptr, "threshold_neighbour", 0, NULL, ICON_NONE);
+}
+
 static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
        uiLayout *col;
@@ -1994,7 +2008,7 @@ static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C
        int multilayer = (RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER);
        
        node_composit_buts_file_output(layout, C, ptr);
-       uiTemplateImageSettings(layout, &imfptr);
+       uiTemplateImageSettings(layout, &imfptr, TRUE);
        
        uiItemS(layout);
        
@@ -2053,7 +2067,7 @@ static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C
                        
                        col = uiLayoutColumn(layout, FALSE);
                        uiLayoutSetActive(col, RNA_boolean_get(&active_input_ptr, "use_node_format") == FALSE);
-                       uiTemplateImageSettings(col, &imfptr);
+                       uiTemplateImageSettings(col, &imfptr, TRUE);
                }
        }
 }
@@ -2674,6 +2688,9 @@ static void node_composit_set_butfunc(bNodeType *ntype)
                case CMP_NODE_INPAINT:
                        ntype->uifunc = node_composit_buts_inpaint;
                        break;
+               case CMP_NODE_DESPECKLE:
+                       ntype->uifunc = node_composit_buts_despeckle;
+                       break;
                case CMP_NODE_OUTPUT_FILE:
                        ntype->uifunc = node_composit_buts_file_output;
                        ntype->uifuncbut = node_composit_buts_file_output_details;
@@ -3019,7 +3036,7 @@ void ED_node_init_butfuncs(void)
 
 /* ************** Generic drawing ************** */
 
-void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
+void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode)
 {
        
        if ((snode->flag & SNODE_BACKDRAW) && snode->treetype == NTREE_COMPOSIT) {
@@ -3027,7 +3044,10 @@ void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
                void *lock;
                ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
                if (ibuf) {
+                       SpaceNode *snode = CTX_wm_space_node(C);
                        float x, y; 
+                       unsigned char *display_buffer;
+                       void *cache_handle;
                        
                        glMatrixMode(GL_PROJECTION);
                        glPushMatrix();
@@ -3046,15 +3066,10 @@ void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
                        x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof;
                        y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof;
                        
-                       if (!ibuf->rect) {
-                               if (color_manage)
-                                       ibuf->profile = IB_PROFILE_LINEAR_RGB;
-                               else
-                                       ibuf->profile = IB_PROFILE_NONE;
-                               IMB_rect_from_float(ibuf);
-                       }
 
-                       if (ibuf->rect) {
+                       display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
+
+                       if (display_buffer) {
                                if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B)) {
                                        int ofs;
 
@@ -3082,7 +3097,7 @@ void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
 #ifdef __BIG_ENDIAN__
                                        glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
 #endif
-                                       glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, ibuf->rect);
+                                       glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, display_buffer);
 
 #ifdef __BIG_ENDIAN__
                                        glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
@@ -3094,7 +3109,7 @@ void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
                                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                                        glPixelZoom(snode->zoom, snode->zoom);
                                        
-                                       glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+                                       glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, display_buffer);
                                        
                                        glPixelZoom(1.0f, 1.0f);
                                        glDisable(GL_BLEND);
@@ -3102,12 +3117,14 @@ void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
                                else {
                                        glPixelZoom(snode->zoom, snode->zoom);
                                        
-                                       glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+                                       glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, display_buffer);
                                        
                                        glPixelZoom(1.0f, 1.0f);
                                }
                        }
 
+                       IMB_display_buffer_release(cache_handle);
+
                        /** @note draw selected info on backdrop */
                        if (snode->edittree) {
                                bNode *node = snode->edittree->nodes.first;