Merging r50192 through r50223 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenkernel / intern / sequencer.c
index 3bcef50..60b0b65 100644 (file)
@@ -72,6 +72,7 @@
 
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
+#include "IMB_colormanagement.h"
 
 #include "BKE_context.h"
 #include "BKE_sound.h"
@@ -1712,7 +1713,7 @@ int BKE_sequencer_input_have_to_preprocess(SeqRenderData UNUSED(context), Sequen
        float mul;
 
        if (seq->flag & (SEQ_FILTERY | SEQ_USE_CROP | SEQ_USE_TRANSFORM | SEQ_FLIPX |
-                        SEQ_FLIPY | SEQ_USE_COLOR_BALANCE | SEQ_MAKE_PREMUL))
+                        SEQ_FLIPY | SEQ_USE_COLOR_BALANCE | SEQ_MAKE_PREMUL | SEQ_MAKE_FLOAT))
        {
                return TRUE;
        }
@@ -1838,8 +1839,9 @@ static ImBuf *input_preprocess(SeqRenderData context, Sequence *seq, float cfra,
        }
 
        if (seq->flag & SEQ_MAKE_FLOAT) {
-               if (!ibuf->rect_float)
-                       IMB_float_from_rect_simple(ibuf);
+               if (!ibuf->rect_float) {
+                       IMB_colormanagement_imbuf_to_sequencer_space(ibuf, TRUE);
+               }
 
                if (ibuf->rect) {
                        imb_freerectImBuf(ibuf);
@@ -2350,11 +2352,8 @@ static ImBuf *seq_render_scene_strip(SeqRenderData context, Sequence *seq, float
                        }
 
                        /* float buffers in the sequencer are not linear */
-                       if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)
-                               ibuf->profile = IB_PROFILE_LINEAR_RGB;
-                       else
-                               ibuf->profile = IB_PROFILE_NONE;
-                       IMB_convert_profile(ibuf, IB_PROFILE_SRGB);                     
+                       ibuf->profile = IB_PROFILE_LINEAR_RGB;
+                       IMB_colormanagement_imbuf_to_sequencer_space(ibuf, FALSE);
                }
                else if (rres.rect32) {
                        ibuf = IMB_allocImBuf(rres.rectx, rres.recty, 32, IB_rect);
@@ -2460,8 +2459,7 @@ static ImBuf *do_render_strip_uncached(SeqRenderData context, Sequence *seq, flo
                                        imb_freerectImBuf(ibuf);
 
                                /* all sequencer color is done in SRGB space, linear gives odd crossfades */
-                               if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
-                                       IMB_convert_profile(ibuf, IB_PROFILE_NONE);
+                               IMB_colormanagement_imbuf_to_sequencer_space(ibuf, FALSE);
 
                                copy_to_ibuf_still(context, seq, nr, ibuf);
 
@@ -2653,6 +2651,12 @@ static ImBuf *seq_render_strip_stack(SeqRenderData context, ListBase *seqbasep,
        
        if (count == 1) {
                out = seq_render_strip(context, seq_arr[0], cfra);
+
+               if (out) {
+                       /* put buffer back to linear space */
+                       IMB_colormanagement_imbuf_from_sequencer_space(out);
+               }
+
                BKE_sequencer_cache_put(context, seq_arr[0], cfra, SEQ_STRIPELEM_IBUF_COMP, out);
 
                return out;
@@ -2732,6 +2736,11 @@ static ImBuf *seq_render_strip_stack(SeqRenderData context, ListBase *seqbasep,
                BKE_sequencer_cache_put(context, seq_arr[i], cfra, SEQ_STRIPELEM_IBUF_COMP, out);
        }
 
+       if (out) {
+               /* put buffer back to linear space */
+               IMB_colormanagement_imbuf_from_sequencer_space(out);
+       }
+
        return out;
 }
 
@@ -2992,46 +3001,27 @@ void BKE_sequence_invalidate_cache_for_modifier(Scene *scene, Sequence *seq)
        sequence_invalidate_cache(scene, seq, FALSE);
 }
 
-void BKE_sequencer_free_imbuf(Scene *scene, ListBase *seqbase, int check_mem_usage, int keep_file_handles)
+void BKE_sequencer_free_imbuf(Scene *scene, ListBase *seqbase, int for_render)
 {
        Sequence *seq;
 
-       if (check_mem_usage) {
-               /* Let the cache limitor take care of this (schlaile) */
-               /* While render let's keep all memory available for render 
-                * (ton)
-                * At least if free memory is tight...
-                * This can make a big difference in encoding speed
-                * (it is around 4 times(!) faster, if we do not waste time
-                * on freeing _all_ buffers every time on long timelines...)
-                * (schlaile)
-                */
-       
-               uintptr_t mem_in_use;
-               uintptr_t mmap_in_use;
-               uintptr_t max;
-       
-               mem_in_use = MEM_get_memory_in_use();
-               mmap_in_use = MEM_get_mapped_memory_in_use();
-               max = MEM_CacheLimiter_get_maximum();
-       
-               if (max == 0 || mem_in_use + mmap_in_use <= max) {
-                       return;
-               }
-       }
-
        BKE_sequencer_cache_cleanup();
-       
+
        for (seq = seqbase->first; seq; seq = seq->next) {
+               if (for_render && CFRA >= seq->startdisp && CFRA <= seq->enddisp) {
+                       continue;
+               }
+
                if (seq->strip) {
-                       if (seq->type == SEQ_TYPE_MOVIE && !keep_file_handles)
+                       if (seq->type == SEQ_TYPE_MOVIE) {
                                free_anim_seq(seq);
+                       }
                        if (seq->type == SEQ_TYPE_SPEED) {
                                BKE_sequence_effect_speed_rebuild_map(scene, seq, 1);
                        }
                }
                if (seq->type == SEQ_TYPE_META) {
-                       BKE_sequencer_free_imbuf(scene, &seq->seqbase, FALSE, keep_file_handles);
+                       BKE_sequencer_free_imbuf(scene, &seq->seqbase, for_render);
                }
                if (seq->type == SEQ_TYPE_SCENE) {
                        /* FIXME: recurs downwards,