Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Sat, 15 Oct 2011 19:20:34 +0000 (19:20 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sat, 15 Oct 2011 19:20:34 +0000 (19:20 +0000)
===========================

Changes to moviecache pointed and discussed in codereview page:

http://codereview.appspot.com/5283049/

source/blender/blenkernel/CMakeLists.txt
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/seqcache.c
source/blender/imbuf/CMakeLists.txt
source/blender/imbuf/IMB_moviecache.h [moved from source/blender/blenkernel/BKE_moviecache.h with 73% similarity]
source/blender/imbuf/intern/moviecache.c [moved from source/blender/blenkernel/intern/moviecache.c with 94% similarity]

index e8ed03b46f75c4eb8a641b9032a502af9259cdcd..229796b0830d2e8cd5025f2b3a7d320d6bb7337c 100644 (file)
@@ -117,7 +117,6 @@ set(SRC
        intern/mesh_validate.c
        intern/modifier.c
        intern/movieclip.c
-       intern/moviecache.c
        intern/multires.c
        intern/nla.c
        intern/node.c
@@ -202,7 +201,6 @@ set(SRC
        BKE_mesh.h
        BKE_modifier.h
        BKE_movieclip.h
-       BKE_moviecache.h
        BKE_multires.h
        BKE_nla.h
        BKE_node.h
index 5fdcea81a3b9e7f2c4bf752f9c4cc613a94c8d7f..dc0580bce969ea6285afb1482f3398b8400c71e1 100644 (file)
@@ -64,6 +64,7 @@
 #include "BLI_callbacks.h"
 
 #include "IMB_imbuf.h"
+#include "IMB_moviecache.h"
 
 #include "BKE_blender.h"
 #include "BKE_context.h"
@@ -80,7 +81,6 @@
 #include "BKE_screen.h"
 #include "BKE_sequencer.h"
 #include "BKE_sound.h"
-#include "BKE_moviecache.h"
 
 
 #include "BLO_undofile.h"
@@ -115,7 +115,7 @@ void free_blender(void)
        BLI_cb_finalize();
 
        seq_stripelem_cache_destruct();
-       BKE_moviecache_destruct();
+       IMB_moviecache_destruct();
        
        free_nodesystem();      
 }
index 58569d2da91c44a81bd5245fd31f43e4a00dcd3f..f556ae43c239fca670cece4e49007ed625a2f11c 100644 (file)
@@ -68,7 +68,7 @@
 #include "BKE_main.h"
 #include "BKE_utildefines.h"
 #include "BKE_movieclip.h"
-#include "BKE_moviecache.h"
+#include "IMB_moviecache.h"
 #include "BKE_image.h" /* openanim */
 #include "BKE_tracking.h"
 
@@ -334,7 +334,7 @@ static ImBuf *get_imbuf_cache(MovieClip *clip, MovieClipUser *user, int flag)
                        key.render_flag= 0;
                }
 
-               return BKE_moviecache_get(clip->cache->moviecache, &key);
+               return IMB_moviecache_get(clip->cache->moviecache, &key);
        }
 
        return NULL;
@@ -347,7 +347,7 @@ static void put_imbuf_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, i
        if(!clip->cache) {
                clip->cache= MEM_callocN(sizeof(MovieClipCache), "movieClipCache");
 
-               clip->cache->moviecache= BKE_moviecache_create(sizeof(MovieClipImBufCacheKey), moviecache_hashhash,
+               clip->cache->moviecache= IMB_moviecache_create(sizeof(MovieClipImBufCacheKey), moviecache_hashhash,
                                moviecache_hashcmp, moviecache_keydata);
        }
 
@@ -362,7 +362,7 @@ static void put_imbuf_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, i
                key.render_flag= 0;
        }
 
-       BKE_moviecache_put(clip->cache->moviecache, &key, ibuf);
+       IMB_moviecache_put(clip->cache->moviecache, &key, ibuf);
 }
 
 /*********************** common functions *************************/
@@ -792,7 +792,7 @@ void BKE_movieclip_get_cache_segments(MovieClip *clip, MovieClipUser *user, int
        if(clip->cache) {
                int proxy= rendersize_to_proxy(user, clip->flag);
 
-               BKE_moviecache_get_cache_segments(clip->cache->moviecache, proxy, user->render_flag, totseg_r, points_r);
+               IMB_moviecache_get_cache_segments(clip->cache->moviecache, proxy, user->render_flag, totseg_r, points_r);
        }
 }
 
@@ -806,7 +806,7 @@ void BKE_movieclip_user_set_frame(MovieClipUser *iuser, int framenr)
 static void free_buffers(MovieClip *clip)
 {
        if(clip->cache) {
-               BKE_moviecache_free(clip->cache->moviecache);
+               IMB_moviecache_free(clip->cache->moviecache);
 
                if(clip->cache->stableibuf)
                        IMB_freeImBuf(clip->cache->stableibuf);
index d84f2522c864a0c8b6670a8f11336620379a6b65..3814e3e40257c71f1ccd580ecdfa0c1b734b1064 100644 (file)
@@ -38,7 +38,7 @@
 #include "DNA_sequence_types.h"
 #include "BKE_sequencer.h"
 
-#include "BKE_moviecache.h"
+#include "IMB_moviecache.h"
 
 typedef struct seqCacheKey 
 {
@@ -48,7 +48,7 @@ typedef struct seqCacheKey
        seq_stripelem_ibuf_t type;
 } seqCacheKey;
 
-struct MovieCache *moviecache = NULL;
+static struct MovieCache *moviecache = NULL;
 
 static unsigned int seqcache_hashhash(const void *key_)
 {
@@ -94,14 +94,14 @@ static int seqcache_hashcmp(const void *a_, const void *b_)
 void seq_stripelem_cache_destruct(void)
 {
        if(moviecache)
-               BKE_moviecache_free(moviecache);
+               IMB_moviecache_free(moviecache);
 }
 
 void seq_stripelem_cache_cleanup(void)
 {
        if(moviecache) {
-               BKE_moviecache_free(moviecache);
-               moviecache = BKE_moviecache_create(sizeof(seqCacheKey), seqcache_hashhash,
+               IMB_moviecache_free(moviecache);
+               moviecache = IMB_moviecache_create(sizeof(seqCacheKey), seqcache_hashhash,
                                seqcache_hashcmp, NULL);
        }
 }
@@ -119,7 +119,7 @@ struct ImBuf * seq_stripelem_cache_get(
                key.cfra = cfra - seq->start;
                key.type = type;
 
-               return BKE_moviecache_get(moviecache, &key);
+               return IMB_moviecache_get(moviecache, &key);
        }
 
        return NULL;
@@ -136,7 +136,7 @@ void seq_stripelem_cache_put(
        }
 
        if(!moviecache) {
-               moviecache = BKE_moviecache_create(sizeof(seqCacheKey), seqcache_hashhash,
+               moviecache = IMB_moviecache_create(sizeof(seqCacheKey), seqcache_hashhash,
                                seqcache_hashcmp, NULL);
        }
 
@@ -145,5 +145,5 @@ void seq_stripelem_cache_put(
        key.cfra = cfra - seq->start;
        key.type = type;
 
-       BKE_moviecache_put(moviecache, &key, i);
+       IMB_moviecache_put(moviecache, &key, i);
 }
index 26be64bc268977713f4c5e0d0e71d61ab6a16d63..8e9969292cd39a238ed08dbb703cf458270b6a7e 100644 (file)
@@ -62,6 +62,7 @@ set(SRC
        intern/md5.c
        intern/metadata.c
        intern/module.c
+       intern/moviecache.c
        intern/png.c
        intern/readimage.c
        intern/rectop.c
@@ -75,6 +76,7 @@ set(SRC
 
        IMB_imbuf.h
        IMB_imbuf_types.h
+       IMB_moviecache.h
        IMB_thumbs.h
        intern/IMB_allocimbuf.h
        intern/IMB_anim.h
similarity index 73%
rename from source/blender/blenkernel/BKE_moviecache.h
rename to source/blender/imbuf/IMB_moviecache.h
index c3c38d68af0bbea3119c9e0d66c15525c06afb30..cee1720a8d0387967c0216f50e7988dd36f1f329 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
-#ifndef BKE_MOVIECACHE_H
-#define BKE_MOVIECACHE_H
+#ifndef IMB_MOVIECACHE_H
+#define IMB_MOVIECACHE_H
 
-/** \file BKE_moviecache.h
- *  \ingroup bke
+/** \file IMB_moviecache.h
+ *  \ingroup imbuf
  *  \author Sergey Sharybin
  */
 
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
 
-/* Cache system for movie data - now supports stroting ImBufs only
+/* Cache system for movie data - now supports stoting ImBufs only
    Supposed to provide unified cache system for movie clips, sequencer and
    other movie-related areas */
 
@@ -46,13 +46,13 @@ struct MovieCache;
 
 typedef void (*MovieCacheGetKeyDataFP) (void *userkey, int *framenr, int *proxy, int *render_flags);
 
-void BKE_moviecache_init(void);
-void BKE_moviecache_destruct(void);
+void IMB_moviecache_init(void);
+void IMB_moviecache_destruct(void);
 
-struct MovieCache *BKE_moviecache_create(int keysize, GHashHashFP hashfp, GHashCmpFP cmpfp, MovieCacheGetKeyDataFP getdatafp);
-void BKE_moviecache_put(struct MovieCache *cache, void *userkey, struct ImBuf *ibuf);
-struct ImBuf* BKE_moviecache_get(struct MovieCache *cache, void *userkey);
-void BKE_moviecache_free(struct MovieCache *cache);
-void BKE_moviecache_get_cache_segments(struct MovieCache *cache, int proxy, int render_flags, int *totseg_r, int **points_r);
+struct MovieCache *IMB_moviecache_create(int keysize, GHashHashFP hashfp, GHashCmpFP cmpfp, MovieCacheGetKeyDataFP getdatafp);
+void IMB_moviecache_put(struct MovieCache *cache, void *userkey, struct ImBuf *ibuf);
+struct ImBuf* IMB_moviecache_get(struct MovieCache *cache, void *userkey);
+void IMB_moviecache_free(struct MovieCache *cache);
+void IMB_moviecache_get_cache_segments(struct MovieCache *cache, int proxy, int render_flags, int *totseg_r, int **points_r);
 
 #endif
similarity index 94%
rename from source/blender/blenkernel/intern/moviecache.c
rename to source/blender/imbuf/intern/moviecache.c
index 9aaccb840ede682951041e8a6d776480a45b8f71..33fbeba755bce65d2dbb061718e9c58f01da7a0c 100644 (file)
@@ -38,7 +38,7 @@
 #include "BLI_ghash.h"
 #include "BLI_mempool.h"
 
-#include "BKE_moviecache.h"
+#include "IMB_moviecache.h"
 
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
@@ -157,7 +157,7 @@ static intptr_t IMB_get_size_in_memory(ImBuf *ibuf)
                channel_size+= sizeof(char);
 
        if(ibuf->rect_float)
-               channel_size= sizeof(float);
+               channel_size+= sizeof(float);
 
        size+= channel_size*ibuf->x*ibuf->y*ibuf->channels;
 
@@ -186,18 +186,18 @@ static intptr_t get_item_size (void *p)
        return size;
 }
 
-void BKE_moviecache_init(void)
+void IMB_moviecache_init(void)
 {
        limitor= new_MEM_CacheLimiter(IMB_moviecache_destructor, get_item_size);
 }
 
-void BKE_moviecache_destruct(void)
+void IMB_moviecache_destruct(void)
 {
        if(limitor)
                delete_MEM_CacheLimiter(limitor);
 }
 
-struct MovieCache *BKE_moviecache_create(int keysize, GHashHashFP hashfp, GHashCmpFP cmpfp,
+struct MovieCache *IMB_moviecache_create(int keysize, GHashHashFP hashfp, GHashCmpFP cmpfp,
                MovieCacheGetKeyDataFP getdatafp)
 {
        MovieCache *cache;
@@ -217,13 +217,13 @@ struct MovieCache *BKE_moviecache_create(int keysize, GHashHashFP hashfp, GHashC
        return cache;
 }
 
-void BKE_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf)
+void IMB_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf)
 {
        MovieCacheKey *key;
        MovieCacheItem *item;
 
        if(!limitor)
-               BKE_moviecache_init();
+               IMB_moviecache_init();
 
        IMB_refImBuf(ibuf);
 
@@ -256,7 +256,7 @@ void BKE_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf)
        }
 }
 
-ImBuf* BKE_moviecache_get(MovieCache *cache, void *userkey)
+ImBuf* IMB_moviecache_get(MovieCache *cache, void *userkey)
 {
        MovieCacheKey key;
        MovieCacheItem *item;
@@ -279,7 +279,7 @@ ImBuf* BKE_moviecache_get(MovieCache *cache, void *userkey)
        return NULL;
 }
 
-void BKE_moviecache_free(MovieCache *cache)
+void IMB_moviecache_free(MovieCache *cache)
 {
        BLI_ghash_free(cache->hash, moviecache_keyfree, moviecache_valfree);
 
@@ -294,7 +294,7 @@ void BKE_moviecache_free(MovieCache *cache)
 }
 
 /* get segments of cached frames. useful for debugging cache policies */
-void BKE_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_flags, int *totseg_r, int **points_r)
+void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_flags, int *totseg_r, int **points_r)
 {
        *totseg_r= 0;
        *points_r= NULL;
@@ -312,7 +312,7 @@ void BKE_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_
        if(cache->points) {
                *totseg_r= cache->totseg;
                *points_r= cache->points;
-       } else if(cache) {
+       } else {
                int totframe= BLI_ghash_size(cache->hash);
                int *frames= MEM_callocN(totframe*sizeof(int), "movieclip cache frames");
                int a, totseg= 0;
@@ -367,8 +367,6 @@ void BKE_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_
                                        points[b++]= frames[a];
                        }
 
-                       MEM_freeN(frames);
-
                        *totseg_r= totseg;
                        *points_r= points;
 
@@ -377,5 +375,7 @@ void BKE_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_
                        cache->proxy= proxy;
                        cache->render_flags= render_flags;
                }
+
+               MEM_freeN(frames);
        }
 }