Merging r50049 through r50076 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenkernel / intern / scene.c
index 185bee86f694a868cd7b671f6b798aef8ed0435f..fc261d48132e74ff5d0f66521622c853e5c69c89 100644 (file)
@@ -57,6 +57,7 @@
 
 #include "BKE_anim.h"
 #include "BKE_animsys.h"
+#include "BKE_colortools.h"
 #include "BKE_depsgraph.h"
 #include "BKE_global.h"
 #include "BKE_group.h"
@@ -132,6 +133,8 @@ Scene *BKE_scene_copy(Scene *sce, int type)
                MEM_freeN(scen->toolsettings);
        }
        else {
+               ImageFormatData *im_format, *im_formatn;
+
                scen = BKE_libblock_copy(&sce->id);
                BLI_duplicatelist(&(scen->base), &(sce->base));
                
@@ -166,6 +169,13 @@ Scene *BKE_scene_copy(Scene *sce, int type)
                        obase = obase->next;
                        base = base->next;
                }
+
+               /* copy color management settings */
+               im_format = &sce->r.im_format;
+               im_formatn = &scen->r.im_format;
+
+               BKE_color_managed_display_settings_copy(&im_formatn->display_settings, &im_format->display_settings);
+               BKE_color_managed_view_settings_copy(&im_formatn->view_settings, &im_format->view_settings);
        }
 
        /* tool settings */
@@ -178,21 +188,21 @@ Scene *BKE_scene_copy(Scene *sce, int type)
                        ts->vpaint->paintcursor = NULL;
                        ts->vpaint->vpaint_prev = NULL;
                        ts->vpaint->wpaint_prev = NULL;
-                       copy_paint(&ts->vpaint->paint, &ts->vpaint->paint);
+                       BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint);
                }
                if (ts->wpaint) {
                        ts->wpaint = MEM_dupallocN(ts->wpaint);
                        ts->wpaint->paintcursor = NULL;
                        ts->wpaint->vpaint_prev = NULL;
                        ts->wpaint->wpaint_prev = NULL;
-                       copy_paint(&ts->wpaint->paint, &ts->wpaint->paint);
+                       BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint);
                }
                if (ts->sculpt) {
                        ts->sculpt = MEM_dupallocN(ts->sculpt);
-                       copy_paint(&ts->sculpt->paint, &ts->sculpt->paint);
+                       BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint);
                }
 
-               copy_paint(&ts->imapaint.paint, &ts->imapaint.paint);
+               BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint);
                ts->imapaint.paintcursor = NULL;
                ts->particle.paintcursor = NULL;
        }
@@ -237,7 +247,7 @@ Scene *BKE_scene_copy(Scene *sce, int type)
                if (sce->ed) {
                        scen->ed = MEM_callocN(sizeof(Editing), "addseq");
                        scen->ed->seqbasep = &scen->ed->seqbase;
-                       seqbase_dupli_recursive(sce, scen, &scen->ed->seqbase, &sce->ed->seqbase, SEQ_DUPE_ALL);
+                       BKE_sequence_base_dupli_recursive(sce, scen, &scen->ed->seqbase, &sce->ed->seqbase, SEQ_DUPE_ALL);
                }
        }
 
@@ -294,22 +304,22 @@ void BKE_scene_free(Scene *sce)
        
        if (sce->toolsettings) {
                if (sce->toolsettings->vpaint) {
-                       free_paint(&sce->toolsettings->vpaint->paint);
+                       BKE_paint_free(&sce->toolsettings->vpaint->paint);
                        MEM_freeN(sce->toolsettings->vpaint);
                }
                if (sce->toolsettings->wpaint) {
-                       free_paint(&sce->toolsettings->wpaint->paint);
+                       BKE_paint_free(&sce->toolsettings->wpaint->paint);
                        MEM_freeN(sce->toolsettings->wpaint);
                }
                if (sce->toolsettings->sculpt) {
-                       free_paint(&sce->toolsettings->sculpt->paint);
+                       BKE_paint_free(&sce->toolsettings->sculpt->paint);
                        MEM_freeN(sce->toolsettings->sculpt);
                }
                if (sce->toolsettings->uvsculpt) {
-                       free_paint(&sce->toolsettings->uvsculpt->paint);
+                       BKE_paint_free(&sce->toolsettings->uvsculpt->paint);
                        MEM_freeN(sce->toolsettings->uvsculpt);
                }
-               free_paint(&sce->toolsettings->imapaint.paint);
+               BKE_paint_free(&sce->toolsettings->imapaint.paint);
 
                MEM_freeN(sce->toolsettings);
                sce->toolsettings = NULL;       
@@ -545,19 +555,15 @@ Scene *BKE_scene_add(const char *name)
 
        sound_create_scene(sce);
 
+       BKE_color_managed_display_settings_init(&sce->r.im_format.display_settings);
+       BKE_color_managed_view_settings_init(&sce->r.im_format.view_settings);
+
        return sce;
 }
 
 Base *BKE_scene_base_find(Scene *scene, Object *ob)
 {
-       Base *base;
-       
-       base = scene->base.first;
-       while (base) {
-               if (base->object == ob) return base;
-               base = base->next;
-       }
-       return NULL;
+       return BLI_findptr(&scene->base, ob, offsetof(Base, object));
 }
 
 void BKE_scene_set_background(Main *bmain, Scene *scene)
@@ -582,10 +588,10 @@ void BKE_scene_set_background(Main *bmain, Scene *scene)
 
        /* group flags again */
        for (group = bmain->group.first; group; group = group->id.next) {
-               go = group->gobject.first;
-               while (go) {
-                       if (go->ob) go->ob->flag |= OB_FROMGROUP;
-                       go = go->next;
+               for (go = group->gobject.first; go; go = go->next) {
+                       if (go->ob) {
+                               go->ob->flag |= OB_FROMGROUP;
+                       }
                }
        }
 
@@ -639,7 +645,7 @@ void BKE_scene_unlink(Main *bmain, Scene *sce, Scene *newsce)
                        sce1->set = NULL;
        
        /* check all sequences */
-       clear_scene_in_allseqs(bmain, sce);
+       BKE_sequencer_clear_scene_in_allseqs(bmain, sce);
 
        /* check render layer nodes in other scenes */
        clear_scene_in_nodes(bmain, sce);