Color management: fix for clone brush
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 24 Aug 2012 13:12:18 +0000 (13:12 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 24 Aug 2012 13:12:18 +0000 (13:12 +0000)
It was using ibuf->rect for drawing alpha over, now it's using actual
display buffer.

source/blender/editors/space_image/image_draw.c
source/blender/imbuf/intern/colormanagement.c

index 3b18c9a4a2d9fbc21c8e03459d4093c895f69945..5d6ecd6effeab42196046977ef5b61a3633378eb 100644 (file)
@@ -651,22 +651,35 @@ static void draw_image_view_tool(Scene *scene)
 }
 #endif
 
-static unsigned char *get_alpha_clone_image(Scene *scene, int *width, int *height)
+static unsigned char *get_alpha_clone_image(const bContext *C, Scene *scene, int *width, int *height)
 {
        Brush *brush = paint_brush(&scene->toolsettings->imapaint.paint);
        ImBuf *ibuf;
        unsigned int size, alpha;
+       unsigned char *display_buffer;
        unsigned char *rect, *cp;
+       void *cache_handle;
 
        if (!brush || !brush->clone.image)
                return NULL;
        
        ibuf = BKE_image_get_ibuf(brush->clone.image, NULL);
 
-       if (!ibuf || !ibuf->rect)
+       if (!ibuf)
                return NULL;
 
-       rect = MEM_dupallocN(ibuf->rect);
+       display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
+
+       if (!display_buffer) {
+               IMB_display_buffer_release(cache_handle);
+
+               return NULL;
+       }
+
+       rect = MEM_dupallocN(display_buffer);
+
+       IMB_display_buffer_release(cache_handle);
+
        if (!rect)
                return NULL;
 
@@ -685,7 +698,7 @@ static unsigned char *get_alpha_clone_image(Scene *scene, int *width, int *heigh
        return rect;
 }
 
-static void draw_image_paint_helpers(ARegion *ar, Scene *scene, float zoomx, float zoomy)
+static void draw_image_paint_helpers(const bContext *C, ARegion *ar, Scene *scene, float zoomx, float zoomy)
 {
        Brush *brush;
        int x, y, w, h;
@@ -696,7 +709,7 @@ static void draw_image_paint_helpers(ARegion *ar, Scene *scene, float zoomx, flo
        if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) {
                /* this is not very efficient, but glDrawPixels doesn't allow
                 * drawing with alpha */
-               clonerect = get_alpha_clone_image(scene, &w, &h);
+               clonerect = get_alpha_clone_image(C, scene, &w, &h);
 
                if (clonerect) {
                        UI_view2d_to_region_no_clip(&ar->v2d, brush->clone.offset[0], brush->clone.offset[1], &x, &y);
@@ -777,7 +790,7 @@ void draw_image_main(const bContext *C, ARegion *ar)
 
        /* paint helpers */
        if (sima->mode == SI_MODE_PAINT)
-               draw_image_paint_helpers(ar, scene, zoomx, zoomy);
+               draw_image_paint_helpers(C, ar, scene, zoomx, zoomy);
 
 
        /* XXX integrate this code */
index 4ecc64708bfd950a8e3f873c7681544a588d949c..deffe9f49f128f242f63f8b3731d776c4d388440 100644 (file)
@@ -1950,7 +1950,7 @@ void IMB_partial_display_buffer_update(ImBuf *ibuf, const float *linear_buffer,
                        if (view_flags % 2 == 1) {
                                ColormanageCacheViewSettings view_settings = {0};
                                unsigned char *display_buffer;
-                               void *cache_handle;
+                               void *cache_handle = NULL;
                                int view_index = view + 1; /* views in configuration are 1-based */
                                float exposure, gamma;
                                int buffer_width;