Merging r48740 through r48749 from trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 9 Jul 2012 10:33:09 +0000 (10:33 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 9 Jul 2012 10:33:09 +0000 (10:33 +0000)
1  2 
source/blender/blenkernel/intern/movieclip.c

index 488b590107101cbc7fa6134c7392629f64e5b947,2d83a748767e7e6ccbd1f0ea9158bb2a6f3fcca5..de367b6b4d0267efa3011ae6dbad9bd849649d28
@@@ -322,6 -322,8 +322,8 @@@ typedef struct MovieClipCache 
  
        /* cache for stable shot */
        struct {
+               ImBuf *reference_ibuf;
                ImBuf *ibuf;
                int framenr;
                int postprocess_flag;
@@@ -338,10 -340,6 +340,10 @@@ typedef struct MovieClipImBufCacheKey 
        short render_flag;
  } MovieClipImBufCacheKey;
  
 +typedef struct MovieClipCachePriorityData {
 +      int framenr;
 +} MovieClipCachePriorityData;
 +
  static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags)
  {
        MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *)userkey;
@@@ -382,32 -380,6 +384,32 @@@ static int moviecache_hashcmp(const voi
        return 0;
  }
  
 +void *moviecache_getprioritydata(void *key_v)
 +{
 +      MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *) key_v;
 +      MovieClipCachePriorityData *priority_data;
 +
 +      priority_data = MEM_callocN(sizeof(priority_data), "movie cache clip priority data");
 +      priority_data->framenr = key->framenr;
 +
 +      return priority_data;
 +}
 +
 +int moviecache_getitempriority(void *last_userkey_v, void *priority_data_v)
 +{
 +      MovieClipImBufCacheKey *last_userkey = (MovieClipImBufCacheKey *) last_userkey_v;
 +      MovieClipCachePriorityData *priority_data = (MovieClipCachePriorityData *) priority_data_v;
 +
 +      return -abs(last_userkey->framenr - priority_data->framenr);
 +}
 +
 +void moviecache_prioritydeleter(void *priority_data_v)
 +{
 +      MovieClipCachePriorityData *priority_data = (MovieClipCachePriorityData *) priority_data_v;
 +
 +      MEM_freeN(priority_data);
 +}
 +
  static ImBuf *get_imbuf_cache(MovieClip *clip, MovieClipUser *user, int flag)
  {
        if (clip->cache) {
@@@ -435,20 -407,10 +437,20 @@@ static void put_imbuf_cache(MovieClip *
        MovieClipImBufCacheKey key;
  
        if (!clip->cache) {
 +              struct MovieCache *moviecache;
 +
 +              // char cache_name[64];
 +              // BLI_snprintf(cache_name, sizeof(cache_name), "movie %s", clip->id.name);
 +
                clip->cache = MEM_callocN(sizeof(MovieClipCache), "movieClipCache");
  
 -              clip->cache->moviecache = IMB_moviecache_create(sizeof(MovieClipImBufCacheKey), moviecache_hashhash,
 -                                                              moviecache_hashcmp, moviecache_keydata);
 +              moviecache = IMB_moviecache_create("movieclip", sizeof(MovieClipImBufCacheKey), moviecache_hashhash, moviecache_hashcmp);
 +
 +              IMB_moviecache_set_getdata_callback(moviecache, moviecache_keydata);
 +              IMB_moviecache_set_priority_callback(moviecache, moviecache_getprioritydata, moviecache_getitempriority,
 +                                                   moviecache_prioritydeleter);
 +
 +              clip->cache->moviecache = moviecache;
        }
  
        key.framenr = user->framenr;
@@@ -695,9 -657,6 +697,6 @@@ static ImBuf *put_postprocessed_frame_t
        MovieTrackingCamera *camera = &clip->tracking.camera;
        ImBuf *postproc_ibuf = NULL;
  
-       if (cache->postprocessed.ibuf)
-               IMB_freeImBuf(cache->postprocessed.ibuf);
        cache->postprocessed.framenr = user->framenr;
        cache->postprocessed.flag = postprocess_flag;
  
  
        IMB_refImBuf(postproc_ibuf);
  
-       cache->postprocessed.ibuf = postproc_ibuf;
+       if (cache->postprocessed.ibuf)
+               IMB_freeImBuf(cache->postprocessed.ibuf);
  
-       if (cache->stabilized.ibuf) {
-               /* force stable buffer be re-calculated */
-               IMB_freeImBuf(cache->stabilized.ibuf);
-               cache->stabilized.ibuf = NULL;
-       }
+       cache->postprocessed.ibuf = postproc_ibuf;
  
        return postproc_ibuf;
  }
@@@ -817,7 -773,8 +813,8 @@@ ImBuf *BKE_movieclip_get_postprocessed_
        return movieclip_get_postprocessed_ibuf(clip, user, clip->flag, postprocess_flag, 0);
  }
  
- static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, int framenr, int postprocess_flag)
+ static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, ImBuf *reference_ibuf,
+                                       int framenr, int postprocess_flag)
  {
        MovieClipCache *cache = clip->cache;
        MovieTracking *tracking = &clip->tracking;
        if (!cache->stabilized.ibuf || cache->stabilized.framenr != framenr)
                return NULL;
  
+       if (cache->stabilized.reference_ibuf != reference_ibuf)
+               return NULL;
        /* cached ibuf used different proxy settings */
        if (cache->stabilized.render_flag != render_flag || cache->stabilized.proxy != proxy)
                return NULL;
@@@ -876,13 -836,8 +876,8 @@@ static ImBuf *put_stabilized_frame_to_c
        float tloc[2], tscale, tangle;
        int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, framenr);
  
-       if (cache->stabilized.ibuf)
-               IMB_freeImBuf(cache->stabilized.ibuf);
        stableibuf = BKE_tracking_stabilize_frame(&clip->tracking, clip_framenr, ibuf, tloc, &tscale, &tangle);
  
-       cache->stabilized.ibuf = stableibuf;
        copy_v2_v2(cache->stabilized.loc, tloc);
  
        cache->stabilized.scale = tscale;
  
        cache->stabilized.postprocess_flag = postprocess_flag;
  
+       if (cache->stabilized.ibuf)
+               IMB_freeImBuf(cache->stabilized.ibuf);
+       cache->stabilized.ibuf = stableibuf;
        IMB_refImBuf(stableibuf);
  
        return stableibuf;
@@@ -921,7 -881,7 +921,7 @@@ ImBuf *BKE_movieclip_get_stable_ibuf(Mo
        if (clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
                MovieClipCache *cache = clip->cache;
  
-               stableibuf = get_stable_cached_frame(clip, user, framenr, postprocess_flag);
+               stableibuf = get_stable_cached_frame(clip, user, ibuf, framenr, postprocess_flag);
  
                if (!stableibuf)
                        stableibuf = put_stabilized_frame_to_cache(clip, user, ibuf, framenr, postprocess_flag);