Merging r50049 through r50076 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / space_clip / clip_draw.c
index 2353f8f8c12cdcf925c39b2bea20db3bcc9dfecd..14197a46663192097b094fcea6d4644e0dd947b9 100644 (file)
@@ -42,6 +42,7 @@
 #include "BKE_tracking.h"
 #include "BKE_mask.h"
 
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 
@@ -246,14 +247,20 @@ static void draw_movieclip_notes(SpaceClip *sc, ARegion *ar)
                ED_region_info_draw(ar, str, block, 0.6f);
 }
 
+/* OCIO_TODO: after finishing proper color management pipeline integration
+ *            this wouldn't be needed -- color managed display buffer
+ *            would be used unstead
+ */
+#if 0
 static void verify_buffer_float(ImBuf *ibuf)
 {
        if (ibuf->rect_float && (ibuf->rect == NULL || (ibuf->userflags & IB_RECT_INVALID))) {
                IMB_rect_from_float(ibuf);
        }
 }
+#endif
 
-static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
+static void draw_movieclip_buffer(wmWindow *win, SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
                                   int width, int height, float zoomx, float zoomy)
 {
        int x, y;
@@ -267,13 +274,21 @@ static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
                glRectf(x, y, x + zoomx * width, y + zoomy * height);
        }
        else {
-               verify_buffer_float(ibuf);
+               const ColorManagedViewSettings *view_settings;
+               unsigned char *display_buffer;
+               void *cache_handle;
 
-               if (ibuf->rect) {
+               /* OCIO_TODO: finally get rid of this stuff */
+               /* verify_buffer_float(ibuf); */
+
+               view_settings = IMB_view_settings_get_effective(win, &sc->view_settings);
+               display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, &win->display_settings, &cache_handle);
+
+               if (display_buffer) {
                        int need_fallback = 1;
 
                        if (ED_space_clip_texture_buffer_supported(sc)) {
-                               if (ED_space_clip_load_movieclip_buffer(sc, ibuf)) {
+                               if (ED_space_clip_load_movieclip_buffer(sc, ibuf, display_buffer)) {
                                        glPushMatrix();
                                        glTranslatef(x, y, 0.0f);
                                        glScalef(zoomx, zoomy, 1.0f);
@@ -299,12 +314,14 @@ static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
                                /* set zoom */
                                glPixelZoom(zoomx * width / ibuf->x, zoomy * height / ibuf->y);
 
-                               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);
 
                                /* reset zoom */
                                glPixelZoom(1.0f, 1.0f);
                        }
                }
+
+               IMB_display_buffer_release(cache_handle);
        }
 
        /* draw boundary border for frame if stabilization is enabled */
@@ -1412,6 +1429,7 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip,
 
 void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar)
 {
+       wmWindow *win = CTX_wm_window(C);
        MovieClip *clip = ED_space_clip_get_clip(sc);
        Scene *scene = CTX_data_scene(C);
        ImBuf *ibuf;
@@ -1461,7 +1479,7 @@ void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar)
        }
 
        if (ibuf) {
-               draw_movieclip_buffer(sc, ar, ibuf, width, height, zoomx, zoomy);
+               draw_movieclip_buffer(win, sc, ar, ibuf, width, height, zoomx, zoomy);
                IMB_freeImBuf(ibuf);
        }
        else {