Color Management, Stage 2: Switch color pipeline to use OpenColorIO
[blender.git] / source / blender / windowmanager / intern / wm_playanim.c
index 3c7ae3ef584bad687a4c6ca877d6bf184e4cf43d..bff40faf1d1cbc87de73f98858a37107712cc801 100644 (file)
 
 #include "PIL_time.h"
 
+#include "BLI_fileops.h"
 #include "BLI_listbase.h"
-#include "BLI_string.h"
 #include "BLI_path_util.h"
-#include "BLI_fileops.h"
 #include "BLI_rect.h"
+#include "BLI_string.h"
+#include "BLI_utildefines.h"
 
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 
 #include "BKE_blender.h"
 #include "BKE_global.h"
-#include "BKE_utildefines.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
-#ifdef WITH_QUICKTIME
-#  ifdef _WIN32
-#    include <QTML.h>
-#    include <Movies.h>
-#  elif defined(__APPLE__)
-#    include <QuickTime/Movies.h>
-#  endif /* __APPLE__ */
-#endif /* WITH_QUICKTIME */
-
 #include "DNA_scene_types.h"
-#include "BLI_utildefines.h"
 #include "ED_datafiles.h" /* for fonts */
-#include "wm_event_types.h"
 #include "GHOST_C-api.h"
 #include "BLF_api.h"
 
+#include "wm_event_types.h"
+
+#include "WM_api.h"  /* only for WM_main_playanim */
 
 typedef struct PlayState {
 
@@ -152,7 +144,7 @@ static struct WindowStateGlobal {
        eWS_Qual qual;
 } g_WS = {NULL};
 
-void playanim_window_get_size(int *width_r, int *height_r)
+static void playanim_window_get_size(int *width_r, int *height_r)
 {
        GHOST_RectangleHandle bounds = GHOST_GetClientBounds(g_WS.ghost_window);
        *width_r = GHOST_GetWidthRectangle(bounds);
@@ -289,7 +281,8 @@ static void build_pict_list(char *first, int totframes, int fstep, int fontid)
        struct anim *anim;
 
        if (IMB_isanim(first)) {
-               anim = IMB_open_anim(first, IB_rect, 0);
+               /* OCIO_TODO: support different input color space */
+               anim = IMB_open_anim(first, IB_rect, 0, NULL);
                if (anim) {
                        int pic;
                        ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
@@ -336,7 +329,11 @@ static void build_pict_list(char *first, int totframes, int fstep, int fontid)
                        int file;
 
                        file = open(filepath, O_BINARY | O_RDONLY, 0);
-                       if (file < 0) return;
+                       if (file < 0) {
+                               /* print errno? */
+                               return;
+                       }
+
                        picture = (PlayAnimPict *)MEM_callocN(sizeof(PlayAnimPict), "picture");
                        if (picture == NULL) {
                                printf("Not enough memory for pict struct '%s'\n", filepath);
@@ -384,12 +381,13 @@ static void build_pict_list(char *first, int totframes, int fstep, int fontid)
                        pupdate_time();
 
                        if (ptottime > 1.0) {
+                               /* OCIO_TODO: support different input color space */
                                if (picture->mem) {
                                        ibuf = IMB_ibImageFromMemory((unsigned char *)picture->mem, picture->size,
-                                                                    picture->IB_flags, picture->name);
+                                                                    picture->IB_flags, NULL, picture->name);
                                }
                                else {
-                                       ibuf = IMB_loadiffname(picture->name, picture->IB_flags);
+                                       ibuf = IMB_loadiffname(picture->name, picture->IB_flags, NULL);
                                }
                                if (ibuf) {
                                        playanim_toscreen(picture, ibuf, fontid);
@@ -695,7 +693,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
        return 1;
 }
 
-void playanim_window_open(const char *title, int posx, int posy, int sizex, int sizey, int start_maximized)
+static void playanim_window_open(const char *title, int posx, int posy, int sizex, int sizey, int start_maximized)
 {
        GHOST_TWindowState inital_state;
        GHOST_TUns32 scr_w, scr_h;
@@ -708,19 +706,13 @@ void playanim_window_open(const char *title, int posx, int posy, int sizex, int
                inital_state = start_maximized ? GHOST_kWindowStateFullScreen : GHOST_kWindowStateNormal;
        else
                inital_state = start_maximized ? GHOST_kWindowStateMaximized : GHOST_kWindowStateNormal;
-#if defined(__APPLE__) && !defined(GHOST_COCOA)
-       {
-               extern int macPrefState; /* creator.c */
-               initial_state += macPrefState;
-       }
-#endif
 
        g_WS.ghost_window = GHOST_CreateWindow(g_WS.ghost_system,
-                                     title,
-                                     posx, posy, sizex, sizey,
-                                     inital_state,
-                                     GHOST_kDrawingContextTypeOpenGL,
-                                     FALSE /* no stereo */, FALSE);
+                                              title,
+                                              posx, posy, sizex, sizey,
+                                              inital_state,
+                                              GHOST_kDrawingContextTypeOpenGL,
+                                              FALSE /* no stereo */, FALSE);
 
        //if (ghostwin) {
        //if (win) {
@@ -732,7 +724,7 @@ void playanim_window_open(const char *title, int posx, int posy, int sizex, int
 }
 
 
-void playanim(int argc, const char **argv)
+void WM_main_playanim(int argc, const char **argv)
 {
        struct ImBuf *ibuf = NULL;
        char filepath[FILE_MAX];
@@ -827,26 +819,6 @@ void playanim(int argc, const char **argv)
                }
        }
 
-#ifdef WITH_QUICKTIME
-#if defined(_WIN32) || defined(__APPLE__) && !defined(GHOST_COCOA)
-       /* Initialize QuickTime */
-#ifndef noErr
-#define noErr 0
-#endif
-
-#ifdef _WIN32
-       if (InitializeQTML(0) != noErr)
-               G.have_quicktime = FALSE;
-       else
-               G.have_quicktime = TRUE;
-#endif /* _WIN32 */
-       if (EnterMovies() != noErr)
-               G.have_quicktime = FALSE;
-       else
-#endif /* _WIN32 || __APPLE__  && !defined(GHOST_COCOA)*/
-       G.have_quicktime = TRUE;
-#endif /* WITH_QUICKTIME */
-
        if (argc > 1) {
                BLI_strncpy(filepath, argv[1], sizeof(filepath));
        }
@@ -856,7 +828,8 @@ void playanim(int argc, const char **argv)
        }
 
        if (IMB_isanim(filepath)) {
-               anim = IMB_open_anim(filepath, IB_rect, 0);
+               /* OCIO_TODO: support different input color spaces */
+               anim = IMB_open_anim(filepath, IB_rect, 0, NULL);
                if (anim) {
                        ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
                        IMB_close_anim(anim);
@@ -868,7 +841,8 @@ void playanim(int argc, const char **argv)
        }
 
        if (ibuf == NULL) {
-               ibuf = IMB_loadiffname(filepath, IB_rect);
+               /* OCIO_TODO: support different input color space */
+               ibuf = IMB_loadiffname(filepath, IB_rect, NULL);
        }
 
        if (ibuf == NULL) {
@@ -941,6 +915,9 @@ void playanim(int argc, const char **argv)
        pupdate_time();
        ptottime = 0;
 
+       /* newly added in 2.6x, without this images never get freed */
+#define USE_IMB_CACHE
+
        while (ps.go) {
                if (ps.pingpong)
                        ps.direction = -ps.direction;
@@ -967,8 +944,9 @@ void playanim(int argc, const char **argv)
                if (ptottime > 0.0) ptottime = 0.0;
 
                while (ps.picture) {
+#ifndef USE_IMB_CACHE
                        if (ibuf != NULL && ibuf->ftype == 0) IMB_freeImBuf(ibuf);
-
+#endif
                        if (ps.picture->ibuf) {
                                ibuf = ps.picture->ibuf;
                        }
@@ -976,14 +954,21 @@ void playanim(int argc, const char **argv)
                                ibuf = IMB_anim_absolute(ps.picture->anim, ps.picture->frame, IMB_TC_NONE, IMB_PROXY_NONE);
                        }
                        else if (ps.picture->mem) {
+                               /* use correct colorspace here */
                                ibuf = IMB_ibImageFromMemory((unsigned char *) ps.picture->mem, ps.picture->size,
-                                                            ps.picture->IB_flags, ps.picture->name);
+                                                            ps.picture->IB_flags, NULL, ps.picture->name);
                        }
                        else {
-                               ibuf = IMB_loadiffname(ps.picture->name, ps.picture->IB_flags);
+                               /* use correct colorspace here */
+                               ibuf = IMB_loadiffname(ps.picture->name, ps.picture->IB_flags, NULL);
                        }
 
                        if (ibuf) {
+
+#ifdef USE_IMB_CACHE
+                               ps.picture->ibuf = ibuf;
+#endif
+
                                BLI_strncpy(ibuf->name, ps.picture->name, sizeof(ibuf->name));
 
                                /* why only windows? (from 2.4x) - campbell */
@@ -1089,19 +1074,12 @@ void playanim(int argc, const char **argv)
 
                ps.picture = ps.picture->next;
        }
-#ifdef WITH_QUICKTIME
-#if defined(_WIN32) || defined(__APPLE__) && !defined(GHOST_COCOA)
-       if (G.have_quicktime) {
-               ExitMovies();
-#ifdef _WIN32
-               TerminateQTML();
-#endif /* _WIN32 */
-       }
-#endif /* _WIN32 || __APPLE__ && !defined(GHOST_COCOA) */
-#endif /* WITH_QUICKTIME */
 
        /* cleanup */
+#ifndef USE_IMB_CACHE
        if (ibuf) IMB_freeImBuf(ibuf);
+#endif
+
        BLI_freelistN(&picsbase);
 #if 0 // XXX25
        free_blender();
@@ -1115,7 +1093,10 @@ void playanim(int argc, const char **argv)
 
        totblock = MEM_get_memory_blocks_in_use();
        if (totblock != 0) {
+               /* prints many bAKey, bArgument's which are tricky to fix */
+#if 0
                printf("Error Totblock: %d\n", totblock);
                MEM_printmemlist();
+#endif
        }
 }