Color Management, Stage 2: Switch color pipeline to use OpenColorIO
[blender.git] / source / blender / imbuf / intern / anim_movie.c
index 16dbd0823da53887c3ee0fe1fc42486650e39028..394f51690467b1d15ce250c3e9daf2137236d3d7 100644 (file)
 #endif
 #endif
 
+#include "IMB_colormanagement.h"
+#include "IMB_colormanagement_intern.h"
+
 int ismovie(const char *UNUSED(filepath))
 {
        return 0;
@@ -263,12 +266,20 @@ void IMB_close_anim_proxies(struct anim *anim)
        IMB_free_indices(anim);
 }
 
-struct anim *IMB_open_anim(const char *name, int ib_flags, int streamindex)
+struct anim *IMB_open_anim(const char *name, int ib_flags, int streamindex, char colorspace[IM_MAX_SPACE])
 {
        struct anim *anim;
 
        anim = (struct anim *)MEM_callocN(sizeof(struct anim), "anim struct");
        if (anim != NULL) {
+               if (colorspace) {
+                       colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
+                       BLI_strncpy(anim->colorspace, colorspace, sizeof(anim->colorspace));
+               }
+               else {
+                       colorspace_set_default_role(anim->colorspace, sizeof(anim->colorspace), COLOR_ROLE_DEFAULT_BYTE);
+               }
+
                BLI_strncpy(anim->name, name, sizeof(anim->name));
                anim->ib_flags = ib_flags;
                anim->streamindex = streamindex;
@@ -404,7 +415,7 @@ static ImBuf *avi_fetchibuf(struct anim *anim, int position)
                if (anim->pgf) {
                        lpbi = AVIStreamGetFrame(anim->pgf, position + AVIStreamStart(anim->pavi[anim->firstvideo]));
                        if (lpbi) {
-                               ibuf = IMB_ibImageFromMemory((unsigned char *) lpbi, 100, IB_rect, "<avi_fetchibuf>");
+                               ibuf = IMB_ibImageFromMemory((unsigned char *) lpbi, 100, IB_rect, anim->colorspace, "<avi_fetchibuf>");
 //Oh brother...
                        }
                }
@@ -432,8 +443,8 @@ static ImBuf *avi_fetchibuf(struct anim *anim, int position)
                MEM_freeN(tmp);
        }
        
-       ibuf->profile = IB_PROFILE_SRGB;
-       
+       ibuf->rect_colorspace = colormanage_colorspace_get_named(anim->colorspace);
+
        return ibuf;
 }
 
@@ -634,8 +645,6 @@ static void ffmpeg_postprocess(struct anim *anim)
        ImBuf *ibuf = anim->last_frame;
        int filter_y = 0;
 
-       ibuf->profile = IB_PROFILE_SRGB;
-
        if (!anim->pFrameComplete) {
                return;
        }
@@ -1090,6 +1099,7 @@ static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position,
 
        IMB_freeImBuf(anim->last_frame);
        anim->last_frame = IMB_allocImBuf(anim->x, anim->y, 32, IB_rect);
+       anim->last_frame->rect_colorspace = colormanage_colorspace_get_named(anim->colorspace);
 
        ffmpeg_postprocess(anim);
 
@@ -1213,7 +1223,7 @@ static ImBuf *anim_getnew(struct anim *anim)
 
        switch (anim->curtype) {
                case ANIM_SEQUENCE:
-                       ibuf = IMB_loadiffname(anim->name, anim->ib_flags);
+                       ibuf = IMB_loadiffname(anim->name, anim->ib_flags, anim->colorspace);
                        if (ibuf) {
                                BLI_strncpy(anim->first, anim->name, sizeof(anim->first));
                                anim->duration = 1;
@@ -1309,7 +1319,7 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim, int position,
                        pic = an_stringdec(anim->first, head, tail, &digits);
                        pic += position;
                        an_stringenc(anim->name, head, tail, digits, pic);
-                       ibuf = IMB_loadiffname(anim->name, IB_rect);
+                       ibuf = IMB_loadiffname(anim->name, IB_rect, anim->colorspace);
                        if (ibuf) {
                                anim->curposition = position;
                        }
@@ -1319,7 +1329,6 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim, int position,
                        if (ibuf) {
                                anim->curposition = position;
                                IMB_convert_rgba_to_abgr(ibuf);
-                               ibuf->profile = IB_PROFILE_SRGB;
                        }
                        break;
                case ANIM_AVI:
@@ -1330,8 +1339,16 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim, int position,
 #ifdef WITH_QUICKTIME
                case ANIM_QTIME:
                        ibuf = qtime_fetchibuf(anim, position);
-                       if (ibuf)
+                       if (ibuf) {
+                               if (ibuf->rect) {
+                                       /* OCIO_TODO: should happen in quicktime module, but it currently doesn't have access
+                                        *            to color management's internals
+                                        */
+                                       ibuf->rect_colorspace = colormanage_colorspace_get_named(anim->colorspace);
+                               }
+
                                anim->curposition = position;
+                       }
                        break;
 #endif
 #ifdef WITH_FFMPEG