Merging r50049 through r50076 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / space_clip / clip_editor.c
index 7a54a39ee481b810675fc159e97de03c49ba5c4f..c730712deb23cd27de87ec87809f700df522529f 100644 (file)
@@ -583,12 +583,15 @@ typedef struct SpaceClipDrawContext {
        GLuint texture;                 /* OGL texture ID */
        short texture_allocated;        /* flag if texture was allocated by glGenTextures */
        struct ImBuf *texture_ibuf;     /* image buffer for which texture was created */
+       const unsigned char *display_buffer; /* display buffer for which texture was created */
        int image_width, image_height;  /* image width and height for which texture was created */
        unsigned last_texture;          /* ID of previously used texture, so it'll be restored after clip drawing */
 
        /* fields to check if cache is still valid */
        int framenr, start_frame, frame_offset;
        short render_size, render_flag;
+
+       char colorspace[64];
 } SpaceClipDrawContext;
 
 int ED_space_clip_texture_buffer_supported(SpaceClip *sc)
@@ -613,7 +616,7 @@ int ED_space_clip_texture_buffer_supported(SpaceClip *sc)
        return context->buffers_supported;
 }
 
-int ED_space_clip_load_movieclip_buffer(SpaceClip *sc, ImBuf *ibuf)
+int ED_space_clip_load_movieclip_buffer(SpaceClip *sc, ImBuf *ibuf, const unsigned char *display_buffer)
 {
        SpaceClipDrawContext *context = sc->draw_context;
        MovieClip *clip = ED_space_clip_get_clip(sc);
@@ -625,12 +628,22 @@ int ED_space_clip_load_movieclip_buffer(SpaceClip *sc, ImBuf *ibuf)
         * assuming displaying happens of footage frames only on which painting doesn't heppen.
         * so not changed image buffer pointer means unchanged image content */
        need_rebind |= context->texture_ibuf != ibuf;
+       need_rebind |= context->display_buffer != display_buffer;
        need_rebind |= context->framenr != sc->user.framenr;
        need_rebind |= context->render_size != sc->user.render_size;
        need_rebind |= context->render_flag != sc->user.render_flag;
        need_rebind |= context->start_frame != clip->start_frame;
        need_rebind |= context->frame_offset != clip->frame_offset;
 
+       if (!need_rebind) {
+               /* OCIO_TODO: not entirely nice, but currently it seems to be easiest way
+                *            to deal with changing input color space settings
+                *            pointer-based check could fail due to new buffers could be
+                *            be allocated on on old memory
+                */
+               need_rebind = strcmp(context->colorspace, clip->colorspace_settings.name) != 0;
+       }
+
        if (need_rebind) {
                int width = ibuf->x, height = ibuf->y;
                int need_recreate = 0;
@@ -670,16 +683,12 @@ int ED_space_clip_load_movieclip_buffer(SpaceClip *sc, ImBuf *ibuf)
                        glBindTexture(GL_TEXTURE_2D, context->texture);
                }
 
-               if (ibuf->rect_float) {
-                       if (ibuf->rect == NULL)
-                               IMB_rect_from_float(ibuf);
-               }
-
-               if (ibuf->rect)
-                       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+               if (display_buffer)
+                       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, display_buffer);
 
                /* store settings */
                context->texture_allocated = 1;
+               context->display_buffer = display_buffer;
                context->texture_ibuf = ibuf;
                context->image_width = ibuf->x;
                context->image_height = ibuf->y;
@@ -688,6 +697,8 @@ int ED_space_clip_load_movieclip_buffer(SpaceClip *sc, ImBuf *ibuf)
                context->render_flag = sc->user.render_flag;
                context->start_frame = clip->start_frame;
                context->frame_offset = clip->frame_offset;
+
+               strcpy(context->colorspace, clip->colorspace_settings.name);
        }
        else {
                /* displaying exactly the same image which was loaded t oa texture,