Merging r50625 through r51896 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenkernel / intern / scene.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/blenkernel/intern/scene.c
29  *  \ingroup bke
30  */
31
32
33 #include <stddef.h>
34 #include <stdio.h>
35 #include <string.h>
36
37 #ifndef WIN32 
38 #include <unistd.h>
39 #else
40 #include <io.h>
41 #endif
42
43 #include "MEM_guardedalloc.h"
44
45 #include "DNA_anim_types.h"
46 #include "DNA_group_types.h"
47 #include "DNA_node_types.h"
48 #include "DNA_object_types.h"
49 #include "DNA_scene_types.h"
50 #include "DNA_screen_types.h"
51 #include "DNA_sequence_types.h"
52
53 #include "BLI_math.h"
54 #include "BLI_blenlib.h"
55 #include "BLI_utildefines.h"
56 #include "BLI_callbacks.h"
57 #include "BLI_string.h"
58
59 #include "BKE_anim.h"
60 #include "BKE_animsys.h"
61 #include "BKE_colortools.h"
62 #include "BKE_depsgraph.h"
63 #include "BKE_global.h"
64 #include "BKE_group.h"
65 #include "BKE_idprop.h"
66 #include "BKE_library.h"
67 #include "BKE_main.h"
68 #include "BKE_mask.h"
69 #include "BKE_node.h"
70 #include "BKE_object.h"
71 #include "BKE_paint.h"
72 #include "BKE_pointcache.h"
73 #include "BKE_scene.h"
74 #include "BKE_sequencer.h"
75 #include "BKE_world.h"
76
77 #include "BKE_sound.h"
78
79 #include "RE_engine.h"
80
81 #include "IMB_colormanagement.h"
82
83 //XXX #include "BIF_previewrender.h"
84 //XXX #include "BIF_editseq.h"
85
86 #ifdef WIN32
87 #else
88 #include <sys/time.h>
89 #endif
90
91 void free_avicodecdata(AviCodecData *acd)
92 {
93         if (acd) {
94                 if (acd->lpFormat) {
95                         MEM_freeN(acd->lpFormat);
96                         acd->lpFormat = NULL;
97                         acd->cbFormat = 0;
98                 }
99                 if (acd->lpParms) {
100                         MEM_freeN(acd->lpParms);
101                         acd->lpParms = NULL;
102                         acd->cbParms = 0;
103                 }
104         }
105 }
106
107 void free_qtcodecdata(QuicktimeCodecData *qcd)
108 {
109         if (qcd) {
110                 if (qcd->cdParms) {
111                         MEM_freeN(qcd->cdParms);
112                         qcd->cdParms = NULL;
113                         qcd->cdSize = 0;
114                 }
115         }
116 }
117
118 Scene *BKE_scene_copy(Scene *sce, int type)
119 {
120         Scene *scen;
121         ToolSettings *ts;
122         Base *base, *obase;
123         
124         if (type == SCE_COPY_EMPTY) {
125                 ListBase lb;
126                 scen = BKE_scene_add(sce->id.name + 2);
127                 
128                 lb = scen->r.layers;
129                 scen->r = sce->r;
130                 scen->r.layers = lb;
131                 scen->unit = sce->unit;
132                 scen->physics_settings = sce->physics_settings;
133                 scen->gm = sce->gm;
134                 scen->audio = sce->audio;
135
136                 MEM_freeN(scen->toolsettings);
137         }
138         else {
139                 scen = BKE_libblock_copy(&sce->id);
140                 BLI_duplicatelist(&(scen->base), &(sce->base));
141                 
142                 clear_id_newpoins();
143                 
144                 id_us_plus((ID *)scen->world);
145                 id_us_plus((ID *)scen->set);
146                 id_us_plus((ID *)scen->gm.dome.warptext);
147
148                 scen->ed = NULL;
149                 scen->theDag = NULL;
150                 scen->obedit = NULL;
151                 scen->stats = NULL;
152                 scen->fps_info = NULL;
153
154                 BLI_duplicatelist(&(scen->markers), &(sce->markers));
155                 BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces));
156                 BLI_duplicatelist(&(scen->r.layers), &(sce->r.layers));
157                 BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets));
158
159                 if (sce->nodetree) {
160                         /* ID's are managed on both copy and switch */
161                         scen->nodetree = ntreeCopyTree(sce->nodetree);
162                         ntreeSwitchID(scen->nodetree, &sce->id, &scen->id);
163                 }
164
165                 obase = sce->base.first;
166                 base = scen->base.first;
167                 while (base) {
168                         id_us_plus(&base->object->id);
169                         if (obase == sce->basact) scen->basact = base;
170         
171                         obase = obase->next;
172                         base = base->next;
173                 }
174
175                 /* copy color management settings */
176                 BKE_color_managed_display_settings_copy(&scen->display_settings, &sce->display_settings);
177                 BKE_color_managed_view_settings_copy(&scen->view_settings, &sce->view_settings);
178                 BKE_color_managed_view_settings_copy(&scen->r.im_format.view_settings, &sce->r.im_format.view_settings);
179
180                 BLI_strncpy(scen->sequencer_colorspace_settings.name, sce->sequencer_colorspace_settings.name,
181                             sizeof(scen->sequencer_colorspace_settings.name));
182         }
183
184         /* tool settings */
185         scen->toolsettings = MEM_dupallocN(sce->toolsettings);
186
187         ts = scen->toolsettings;
188         if (ts) {
189                 if (ts->vpaint) {
190                         ts->vpaint = MEM_dupallocN(ts->vpaint);
191                         ts->vpaint->paintcursor = NULL;
192                         ts->vpaint->vpaint_prev = NULL;
193                         ts->vpaint->wpaint_prev = NULL;
194                         BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint);
195                 }
196                 if (ts->wpaint) {
197                         ts->wpaint = MEM_dupallocN(ts->wpaint);
198                         ts->wpaint->paintcursor = NULL;
199                         ts->wpaint->vpaint_prev = NULL;
200                         ts->wpaint->wpaint_prev = NULL;
201                         BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint);
202                 }
203                 if (ts->sculpt) {
204                         ts->sculpt = MEM_dupallocN(ts->sculpt);
205                         BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint);
206                 }
207
208                 BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint);
209                 ts->imapaint.paintcursor = NULL;
210                 ts->particle.paintcursor = NULL;
211         }
212         
213         /* make a private copy of the avicodecdata */
214         if (sce->r.avicodecdata) {
215                 scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata);
216                 scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat);
217                 scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms);
218         }
219         
220         /* make a private copy of the qtcodecdata */
221         if (sce->r.qtcodecdata) {
222                 scen->r.qtcodecdata = MEM_dupallocN(sce->r.qtcodecdata);
223                 scen->r.qtcodecdata->cdParms = MEM_dupallocN(scen->r.qtcodecdata->cdParms);
224         }
225         
226         if (sce->r.ffcodecdata.properties) { /* intentionally check scen not sce. */
227                 scen->r.ffcodecdata.properties = IDP_CopyProperty(sce->r.ffcodecdata.properties);
228         }
229
230         /* NOTE: part of SCE_COPY_LINK_DATA and SCE_COPY_FULL operations
231          * are done outside of blenkernel with ED_objects_single_users! */
232
233         /*  camera */
234         if (type == SCE_COPY_LINK_DATA || type == SCE_COPY_FULL) {
235                 ID_NEW(scen->camera);
236         }
237         
238         /* before scene copy */
239         sound_create_scene(scen);
240
241         /* world */
242         if (type == SCE_COPY_FULL) {
243                 BKE_copy_animdata_id_action((ID *)scen);
244                 if (scen->world) {
245                         id_us_plus((ID *)scen->world);
246                         scen->world = BKE_world_copy(scen->world);
247                         BKE_copy_animdata_id_action((ID *)scen->world);
248                 }
249
250                 if (sce->ed) {
251                         scen->ed = MEM_callocN(sizeof(Editing), "addseq");
252                         scen->ed->seqbasep = &scen->ed->seqbase;
253                         BKE_sequence_base_dupli_recursive(sce, scen, &scen->ed->seqbase, &sce->ed->seqbase, SEQ_DUPE_ALL);
254                 }
255         }
256
257         return scen;
258 }
259
260 /* do not free scene itself */
261 void BKE_scene_free(Scene *sce)
262 {
263         Base *base;
264
265         base = sce->base.first;
266         while (base) {
267                 base->object->id.us--;
268                 base = base->next;
269         }
270         /* do not free objects! */
271         
272         if (sce->gpd) {
273 #if 0   /* removed since this can be invalid memory when freeing everything */
274                 /* since the grease pencil data is freed before the scene.
275                  * since grease pencil data is not (yet?), shared between objects
276                  * its probably safe not to do this, some save and reload will free this. */
277                 sce->gpd->id.us--;
278 #endif
279                 sce->gpd = NULL;
280         }
281
282         BLI_freelistN(&sce->base);
283         BKE_sequencer_editing_free(sce);
284
285         BKE_free_animdata((ID *)sce);
286         BKE_keyingsets_free(&sce->keyingsets);
287         
288         if (sce->r.avicodecdata) {
289                 free_avicodecdata(sce->r.avicodecdata);
290                 MEM_freeN(sce->r.avicodecdata);
291                 sce->r.avicodecdata = NULL;
292         }
293         if (sce->r.qtcodecdata) {
294                 free_qtcodecdata(sce->r.qtcodecdata);
295                 MEM_freeN(sce->r.qtcodecdata);
296                 sce->r.qtcodecdata = NULL;
297         }
298         if (sce->r.ffcodecdata.properties) {
299                 IDP_FreeProperty(sce->r.ffcodecdata.properties);
300                 MEM_freeN(sce->r.ffcodecdata.properties);
301                 sce->r.ffcodecdata.properties = NULL;
302         }
303         
304         BLI_freelistN(&sce->markers);
305         BLI_freelistN(&sce->transform_spaces);
306         BLI_freelistN(&sce->r.layers);
307         
308         if (sce->toolsettings) {
309                 if (sce->toolsettings->vpaint) {
310                         BKE_paint_free(&sce->toolsettings->vpaint->paint);
311                         MEM_freeN(sce->toolsettings->vpaint);
312                 }
313                 if (sce->toolsettings->wpaint) {
314                         BKE_paint_free(&sce->toolsettings->wpaint->paint);
315                         MEM_freeN(sce->toolsettings->wpaint);
316                 }
317                 if (sce->toolsettings->sculpt) {
318                         BKE_paint_free(&sce->toolsettings->sculpt->paint);
319                         MEM_freeN(sce->toolsettings->sculpt);
320                 }
321                 if (sce->toolsettings->uvsculpt) {
322                         BKE_paint_free(&sce->toolsettings->uvsculpt->paint);
323                         MEM_freeN(sce->toolsettings->uvsculpt);
324                 }
325                 BKE_paint_free(&sce->toolsettings->imapaint.paint);
326
327                 MEM_freeN(sce->toolsettings);
328                 sce->toolsettings = NULL;
329         }
330         
331         if (sce->theDag) {
332                 free_forest(sce->theDag);
333                 MEM_freeN(sce->theDag);
334         }
335         
336         if (sce->nodetree) {
337                 ntreeFreeTree(sce->nodetree);
338                 MEM_freeN(sce->nodetree);
339         }
340
341         if (sce->stats)
342                 MEM_freeN(sce->stats);
343         if (sce->fps_info)
344                 MEM_freeN(sce->fps_info);
345
346         sound_destroy_scene(sce);
347
348         BKE_color_managed_view_settings_free(&sce->view_settings);
349 }
350
351 Scene *BKE_scene_add(const char *name)
352 {
353         Main *bmain = G.main;
354         Scene *sce;
355         ParticleEditSettings *pset;
356         int a;
357         const char *colorspace_name;
358
359         sce = BKE_libblock_alloc(&bmain->scene, ID_SCE, name);
360         sce->lay = sce->layact = 1;
361         
362         sce->r.mode = R_GAMMA | R_OSA | R_SHADOW | R_SSS | R_ENVMAP | R_RAYTRACE;
363         sce->r.cfra = 1;
364         sce->r.sfra = 1;
365         sce->r.efra = 250;
366         sce->r.frame_step = 1;
367         sce->r.xsch = 1920;
368         sce->r.ysch = 1080;
369         sce->r.xasp = 1;
370         sce->r.yasp = 1;
371         sce->r.tilex = 256;
372         sce->r.tiley = 256;
373         sce->r.mblur_samples = 1;
374         sce->r.filtertype = R_FILTER_MITCH;
375         sce->r.size = 50;
376
377         sce->r.im_format.planes = R_IMF_PLANES_RGB;
378         sce->r.im_format.imtype = R_IMF_IMTYPE_PNG;
379         sce->r.im_format.quality = 90;
380
381         sce->r.displaymode = R_OUTPUT_AREA;
382         sce->r.framapto = 100;
383         sce->r.images = 100;
384         sce->r.framelen = 1.0;
385         sce->r.blurfac = 0.5;
386         sce->r.frs_sec = 24;
387         sce->r.frs_sec_base = 1;
388         sce->r.edgeint = 10;
389         sce->r.ocres = 128;
390
391         /* OCIO_TODO: for forwards compatibility only, so if no tonecurve are used,
392          *            images would look in the same way as in current blender
393          *
394          *            perhaps at some point should be completely deprecated?
395          */
396         sce->r.color_mgt_flag |= R_COLOR_MANAGEMENT;
397
398         sce->r.gauss = 1.0;
399         
400         /* deprecated but keep for upwards compat */
401         sce->r.postgamma = 1.0;
402         sce->r.posthue = 0.0;
403         sce->r.postsat = 1.0;
404
405         sce->r.bake_mode = 1;    /* prevent to include render stuff here */
406         sce->r.bake_filter = 2;
407         sce->r.bake_osa = 5;
408         sce->r.bake_flag = R_BAKE_CLEAR;
409         sce->r.bake_normal_space = R_BAKE_SPACE_TANGENT;
410         sce->r.scemode = R_DOCOMP | R_DOSEQ | R_EXTENSION;
411         sce->r.stamp = R_STAMP_TIME | R_STAMP_FRAME | R_STAMP_DATE | R_STAMP_CAMERA | R_STAMP_SCENE | R_STAMP_FILENAME | R_STAMP_RENDERTIME;
412         sce->r.stamp_font_id = 12;
413         sce->r.fg_stamp[0] = sce->r.fg_stamp[1] = sce->r.fg_stamp[2] = 0.8f;
414         sce->r.fg_stamp[3] = 1.0f;
415         sce->r.bg_stamp[0] = sce->r.bg_stamp[1] = sce->r.bg_stamp[2] = 0.0f;
416         sce->r.bg_stamp[3] = 0.25f;
417         sce->r.raytrace_options = R_RAYTRACE_USE_INSTANCES;
418
419         sce->r.seq_prev_type = OB_SOLID;
420         sce->r.seq_rend_type = OB_SOLID;
421         sce->r.seq_flag = R_SEQ_GL_PREV;
422
423         sce->r.threads = 1;
424
425         sce->r.simplify_subsurf = 6;
426         sce->r.simplify_particles = 1.0f;
427         sce->r.simplify_shadowsamples = 16;
428         sce->r.simplify_aosss = 1.0f;
429
430         sce->r.border.xmin = 0.0f;
431         sce->r.border.ymin = 0.0f;
432         sce->r.border.xmax = 1.0f;
433         sce->r.border.ymax = 1.0f;
434         
435         sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct");
436         sce->toolsettings->cornertype = 1;
437         sce->toolsettings->degr = 90; 
438         sce->toolsettings->step = 9;
439         sce->toolsettings->turn = 1;
440         sce->toolsettings->extr_offs = 1; 
441         sce->toolsettings->doublimit = 0.001;
442         sce->toolsettings->segments = 32;
443         sce->toolsettings->rings = 32;
444         sce->toolsettings->vertices = 32;
445         sce->toolsettings->uvcalc_radius = 1.0f;
446         sce->toolsettings->uvcalc_cubesize = 1.0f;
447         sce->toolsettings->uvcalc_mapdir = 1;
448         sce->toolsettings->uvcalc_mapalign = 1;
449         sce->toolsettings->uvcalc_margin = 0.001f;
450         sce->toolsettings->unwrapper = 1;
451         sce->toolsettings->select_thresh = 0.01f;
452         sce->toolsettings->jointrilimit = 0.8f;
453
454         sce->toolsettings->selectmode = SCE_SELECT_VERTEX;
455         sce->toolsettings->uv_selectmode = UV_SELECT_VERTEX;
456         sce->toolsettings->normalsize = 0.1;
457         sce->toolsettings->autokey_mode = U.autokey_mode;
458
459         sce->toolsettings->skgen_resolution = 100;
460         sce->toolsettings->skgen_threshold_internal     = 0.01f;
461         sce->toolsettings->skgen_threshold_external     = 0.01f;
462         sce->toolsettings->skgen_angle_limit            = 45.0f;
463         sce->toolsettings->skgen_length_ratio           = 1.3f;
464         sce->toolsettings->skgen_length_limit           = 1.5f;
465         sce->toolsettings->skgen_correlation_limit      = 0.98f;
466         sce->toolsettings->skgen_symmetry_limit         = 0.1f;
467         sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
468         sce->toolsettings->skgen_postpro_passes = 1;
469         sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL | SKGEN_FILTER_EXTERNAL | SKGEN_FILTER_SMART | SKGEN_HARMONIC | SKGEN_SUB_CORRELATION | SKGEN_STICK_TO_EMBEDDING;
470         sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
471         sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
472         sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
473
474         sce->toolsettings->proportional_size = 1.0f;
475
476         sce->physics_settings.gravity[0] = 0.0f;
477         sce->physics_settings.gravity[1] = 0.0f;
478         sce->physics_settings.gravity[2] = -9.81f;
479         sce->physics_settings.flag = PHYS_GLOBAL_GRAVITY;
480
481         sce->unit.scale_length = 1.0f;
482
483         pset = &sce->toolsettings->particle;
484         pset->flag = PE_KEEP_LENGTHS | PE_LOCK_FIRST | PE_DEFLECT_EMITTER | PE_AUTO_VELOCITY;
485         pset->emitterdist = 0.25f;
486         pset->totrekey = 5;
487         pset->totaddkey = 5;
488         pset->brushtype = PE_BRUSH_NONE;
489         pset->draw_step = 2;
490         pset->fade_frames = 2;
491         pset->selectmode = SCE_SELECT_PATH;
492         for (a = 0; a < PE_TOT_BRUSH; a++) {
493                 pset->brush[a].strength = 0.5;
494                 pset->brush[a].size = 50;
495                 pset->brush[a].step = 10;
496                 pset->brush[a].count = 10;
497         }
498         pset->brush[PE_BRUSH_CUT].strength = 100;
499
500         sce->r.ffcodecdata.audio_mixrate = 44100;
501         sce->r.ffcodecdata.audio_volume = 1.0f;
502         sce->r.ffcodecdata.audio_bitrate = 192;
503         sce->r.ffcodecdata.audio_channels = 2;
504
505         BLI_strncpy(sce->r.engine, "BLENDER_RENDER", sizeof(sce->r.engine));
506
507         sce->audio.distance_model = 2.0f;
508         sce->audio.doppler_factor = 1.0f;
509         sce->audio.speed_of_sound = 343.3f;
510         sce->audio.volume = 1.0f;
511
512         BLI_strncpy(sce->r.pic, U.renderdir, sizeof(sce->r.pic));
513
514         BLI_rctf_init(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
515         sce->r.osa = 8;
516
517         /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
518         BKE_scene_add_render_layer(sce, NULL);
519         
520         /* game data */
521         sce->gm.stereoflag = STEREO_NOSTEREO;
522         sce->gm.stereomode = STEREO_ANAGLYPH;
523         sce->gm.eyeseparation = 0.10;
524
525         sce->gm.dome.angle = 180;
526         sce->gm.dome.mode = DOME_FISHEYE;
527         sce->gm.dome.res = 4;
528         sce->gm.dome.resbuf = 1.0f;
529         sce->gm.dome.tilt = 0;
530
531         sce->gm.xplay = 640;
532         sce->gm.yplay = 480;
533         sce->gm.freqplay = 60;
534         sce->gm.depth = 32;
535
536         sce->gm.gravity = 9.8f;
537         sce->gm.physicsEngine = WOPHY_BULLET;
538         sce->gm.mode = 32; //XXX ugly harcoding, still not sure we should drop mode. 32 == 1 << 5 == use_occlusion_culling 
539         sce->gm.occlusionRes = 128;
540         sce->gm.ticrate = 60;
541         sce->gm.maxlogicstep = 5;
542         sce->gm.physubstep = 1;
543         sce->gm.maxphystep = 5;
544         sce->gm.lineardeactthreshold = 0.8f;
545         sce->gm.angulardeactthreshold = 1.0f;
546         sce->gm.deactivationtime = 0.0f;
547
548         sce->gm.flag = GAME_DISPLAY_LISTS;
549         sce->gm.matmode = GAME_MAT_MULTITEX;
550
551         sce->gm.obstacleSimulation = OBSTSIMULATION_NONE;
552         sce->gm.levelHeight = 2.f;
553
554         sce->gm.recastData.cellsize = 0.3f;
555         sce->gm.recastData.cellheight = 0.2f;
556         sce->gm.recastData.agentmaxslope = M_PI / 2;
557         sce->gm.recastData.agentmaxclimb = 0.9f;
558         sce->gm.recastData.agentheight = 2.0f;
559         sce->gm.recastData.agentradius = 0.6f;
560         sce->gm.recastData.edgemaxlen = 12.0f;
561         sce->gm.recastData.edgemaxerror = 1.3f;
562         sce->gm.recastData.regionminsize = 8.f;
563         sce->gm.recastData.regionmergesize = 20.f;
564         sce->gm.recastData.vertsperpoly = 6;
565         sce->gm.recastData.detailsampledist = 6.0f;
566         sce->gm.recastData.detailsamplemaxerror = 1.0f;
567
568         sce->gm.exitkey = 218; // Blender key code for ESC
569
570         sound_create_scene(sce);
571
572         /* color management */
573         colorspace_name = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_SEQUENCER);
574
575         BKE_color_managed_display_settings_init(&sce->display_settings);
576         BKE_color_managed_view_settings_init(&sce->view_settings);
577         BLI_strncpy(sce->sequencer_colorspace_settings.name, colorspace_name,
578                     sizeof(sce->sequencer_colorspace_settings.name));
579
580         return sce;
581 }
582
583 Base *BKE_scene_base_find(Scene *scene, Object *ob)
584 {
585         return BLI_findptr(&scene->base, ob, offsetof(Base, object));
586 }
587
588 void BKE_scene_set_background(Main *bmain, Scene *scene)
589 {
590         Scene *sce;
591         Base *base;
592         Object *ob;
593         Group *group;
594         GroupObject *go;
595         int flag;
596         
597         /* check for cyclic sets, for reading old files but also for definite security (py?) */
598         BKE_scene_validate_setscene(bmain, scene);
599         
600         /* can happen when switching modes in other scenes */
601         if (scene->obedit && !(scene->obedit->mode & OB_MODE_EDIT))
602                 scene->obedit = NULL;
603
604         /* deselect objects (for dataselect) */
605         for (ob = bmain->object.first; ob; ob = ob->id.next)
606                 ob->flag &= ~(SELECT | OB_FROMGROUP);
607
608         /* group flags again */
609         for (group = bmain->group.first; group; group = group->id.next) {
610                 for (go = group->gobject.first; go; go = go->next) {
611                         if (go->ob) {
612                                 go->ob->flag |= OB_FROMGROUP;
613                         }
614                 }
615         }
616
617         /* sort baselist */
618         DAG_scene_sort(bmain, scene);
619         
620         /* ensure dags are built for sets */
621         for (sce = scene->set; sce; sce = sce->set)
622                 if (sce->theDag == NULL)
623                         DAG_scene_sort(bmain, sce);
624
625         /* copy layers and flags from bases to objects */
626         for (base = scene->base.first; base; base = base->next) {
627                 ob = base->object;
628                 ob->lay = base->lay;
629                 
630                 /* group patch... */
631                 base->flag &= ~(OB_FROMGROUP);
632                 flag = ob->flag & (OB_FROMGROUP);
633                 base->flag |= flag;
634                 
635                 /* not too nice... for recovering objects with lost data */
636                 //if (ob->pose == NULL) base->flag &= ~OB_POSEMODE;
637                 ob->flag = base->flag;
638         }
639         /* no full animation update, this to enable render code to work (render code calls own animation updates) */
640 }
641
642 /* called from creator.c */
643 Scene *BKE_scene_set_name(Main *bmain, const char *name)
644 {
645         Scene *sce = (Scene *)BKE_libblock_find_name(ID_SCE, name);
646         if (sce) {
647                 BKE_scene_set_background(bmain, sce);
648                 printf("Scene switch: '%s' in file: '%s'\n", name, G.main->name);
649                 return sce;
650         }
651
652         printf("Can't find scene: '%s' in file: '%s'\n", name, G.main->name);
653         return NULL;
654 }
655
656 void BKE_scene_unlink(Main *bmain, Scene *sce, Scene *newsce)
657 {
658         Scene *sce1;
659         bScreen *sc;
660
661         /* check all sets */
662         for (sce1 = bmain->scene.first; sce1; sce1 = sce1->id.next)
663                 if (sce1->set == sce)
664                         sce1->set = NULL;
665         
666         /* check all sequences */
667         BKE_sequencer_clear_scene_in_allseqs(bmain, sce);
668
669         /* check render layer nodes in other scenes */
670         clear_scene_in_nodes(bmain, sce);
671         
672         /* al screens */
673         for (sc = bmain->screen.first; sc; sc = sc->id.next)
674                 if (sc->scene == sce)
675                         sc->scene = newsce;
676
677         BKE_libblock_free(&bmain->scene, sce);
678 }
679
680 /* used by metaballs
681  * doesnt return the original duplicated object, only dupli's
682  */
683 int BKE_scene_base_iter_next(Scene **scene, int val, Base **base, Object **ob)
684 {
685         static ListBase *duplilist = NULL;
686         static DupliObject *dupob;
687         static int fase = F_START, in_next_object = 0;
688         int run_again = 1;
689         
690         /* init */
691         if (val == 0) {
692                 fase = F_START;
693                 dupob = NULL;
694                 
695                 /* XXX particle systems with metas+dupligroups call this recursively */
696                 /* see bug #18725 */
697                 if (in_next_object) {
698                         printf("ERROR: Metaball generation called recursively, not supported\n");
699                         
700                         return F_ERROR;
701                 }
702         }
703         else {
704                 in_next_object = 1;
705                 
706                 /* run_again is set when a duplilist has been ended */
707                 while (run_again) {
708                         run_again = 0;
709
710                         /* the first base */
711                         if (fase == F_START) {
712                                 *base = (*scene)->base.first;
713                                 if (*base) {
714                                         *ob = (*base)->object;
715                                         fase = F_SCENE;
716                                 }
717                                 else {
718                                         /* exception: empty scene */
719                                         while ((*scene)->set) {
720                                                 (*scene) = (*scene)->set;
721                                                 if ((*scene)->base.first) {
722                                                         *base = (*scene)->base.first;
723                                                         *ob = (*base)->object;
724                                                         fase = F_SCENE;
725                                                         break;
726                                                 }
727                                         }
728                                 }
729                         }
730                         else {
731                                 if (*base && fase != F_DUPLI) {
732                                         *base = (*base)->next;
733                                         if (*base) *ob = (*base)->object;
734                                         else {
735                                                 if (fase == F_SCENE) {
736                                                         /* (*scene) is finished, now do the set */
737                                                         while ((*scene)->set) {
738                                                                 (*scene) = (*scene)->set;
739                                                                 if ((*scene)->base.first) {
740                                                                         *base = (*scene)->base.first;
741                                                                         *ob = (*base)->object;
742                                                                         break;
743                                                                 }
744                                                         }
745                                                 }
746                                         }
747                                 }
748                         }
749                         
750                         if (*base == NULL) fase = F_START;
751                         else {
752                                 if (fase != F_DUPLI) {
753                                         if ( (*base)->object->transflag & OB_DUPLI) {
754                                                 /* groups cannot be duplicated for mballs yet, 
755                                                  * this enters eternal loop because of 
756                                                  * makeDispListMBall getting called inside of group_duplilist */
757                                                 if ((*base)->object->dup_group == NULL) {
758                                                         duplilist = object_duplilist((*scene), (*base)->object, FALSE);
759                                                         
760                                                         dupob = duplilist->first;
761
762                                                         if (!dupob)
763                                                                 free_object_duplilist(duplilist);
764                                                 }
765                                         }
766                                 }
767                                 /* handle dupli's */
768                                 if (dupob) {
769                                         
770                                         copy_m4_m4(dupob->ob->obmat, dupob->mat);
771                                         
772                                         (*base)->flag |= OB_FROMDUPLI;
773                                         *ob = dupob->ob;
774                                         fase = F_DUPLI;
775                                         
776                                         dupob = dupob->next;
777                                 }
778                                 else if (fase == F_DUPLI) {
779                                         fase = F_SCENE;
780                                         (*base)->flag &= ~OB_FROMDUPLI;
781                                         
782                                         for (dupob = duplilist->first; dupob; dupob = dupob->next) {
783                                                 copy_m4_m4(dupob->ob->obmat, dupob->omat);
784                                         }
785                                         
786                                         free_object_duplilist(duplilist);
787                                         duplilist = NULL;
788                                         run_again = 1;
789                                 }
790                         }
791                 }
792         }
793
794 #if 0
795         if (ob && *ob) {
796                 printf("Scene: '%s', '%s'\n", (*scene)->id.name + 2, (*ob)->id.name + 2);
797         }
798 #endif
799
800         /* reset recursion test */
801         in_next_object = 0;
802         
803         return fase;
804 }
805
806 Object *BKE_scene_camera_find(Scene *sc)
807 {
808         Base *base;
809         
810         for (base = sc->base.first; base; base = base->next)
811                 if (base->object->type == OB_CAMERA)
812                         return base->object;
813
814         return NULL;
815 }
816
817 #ifdef DURIAN_CAMERA_SWITCH
818 Object *BKE_scene_camera_switch_find(Scene *scene)
819 {
820         TimeMarker *m;
821         int cfra = scene->r.cfra;
822         int frame = -(MAXFRAME + 1);
823         Object *camera = NULL;
824
825         for (m = scene->markers.first; m; m = m->next) {
826                 if (m->camera && (m->camera->restrictflag & OB_RESTRICT_RENDER) == 0 && (m->frame <= cfra) && (m->frame > frame)) {
827                         camera = m->camera;
828                         frame = m->frame;
829
830                         if (frame == cfra)
831                                 break;
832
833                 }
834         }
835         return camera;
836 }
837 #endif
838
839 int BKE_scene_camera_switch_update(Scene *scene)
840 {
841 #ifdef DURIAN_CAMERA_SWITCH
842         Object *camera = BKE_scene_camera_switch_find(scene);
843         if (camera) {
844                 scene->camera = camera;
845                 return 1;
846         }
847 #else
848         (void)scene;
849 #endif
850         return 0;
851 }
852
853 char *BKE_scene_find_marker_name(Scene *scene, int frame)
854 {
855         ListBase *markers = &scene->markers;
856         TimeMarker *m1, *m2;
857
858         /* search through markers for match */
859         for (m1 = markers->first, m2 = markers->last; m1 && m2; m1 = m1->next, m2 = m2->prev) {
860                 if (m1->frame == frame)
861                         return m1->name;
862
863                 if (m1 == m2)
864                         break;
865
866                 if (m2->frame == frame)
867                         return m2->name;
868         }
869
870         return NULL;
871 }
872
873 /* return the current marker for this frame,
874  * we can have more then 1 marker per frame, this just returns the first :/ */
875 char *BKE_scene_find_last_marker_name(Scene *scene, int frame)
876 {
877         TimeMarker *marker, *best_marker = NULL;
878         int best_frame = -MAXFRAME * 2;
879         for (marker = scene->markers.first; marker; marker = marker->next) {
880                 if (marker->frame == frame) {
881                         return marker->name;
882                 }
883
884                 if (marker->frame > best_frame && marker->frame < frame) {
885                         best_marker = marker;
886                         best_frame = marker->frame;
887                 }
888         }
889
890         return best_marker ? best_marker->name : NULL;
891 }
892
893
894 Base *BKE_scene_base_add(Scene *sce, Object *ob)
895 {
896         Base *b = MEM_callocN(sizeof(*b), "BKE_scene_base_add");
897         BLI_addhead(&sce->base, b);
898
899         b->object = ob;
900         b->flag = ob->flag;
901         b->lay = ob->lay;
902
903         return b;
904 }
905
906 void BKE_scene_base_deselect_all(Scene *sce)
907 {
908         Base *b;
909
910         for (b = sce->base.first; b; b = b->next) {
911                 b->flag &= ~SELECT;
912                 b->object->flag = b->flag;
913         }
914 }
915
916 void BKE_scene_base_select(Scene *sce, Base *selbase)
917 {
918         selbase->flag |= SELECT;
919         selbase->object->flag = selbase->flag;
920
921         sce->basact = selbase;
922 }
923
924 /* checks for cycle, returns 1 if it's all OK */
925 int BKE_scene_validate_setscene(Main *bmain, Scene *sce)
926 {
927         Scene *scene;
928         int a, totscene;
929         
930         if (sce->set == NULL) return 1;
931         
932         totscene = 0;
933         for (scene = bmain->scene.first; scene; scene = scene->id.next)
934                 totscene++;
935         
936         for (a = 0, scene = sce; scene->set; scene = scene->set, a++) {
937                 /* more iterations than scenes means we have a cycle */
938                 if (a > totscene) {
939                         /* the tested scene gets zero'ed, that's typically current scene */
940                         sce->set = NULL;
941                         return 0;
942                 }
943         }
944
945         return 1;
946 }
947
948 /* This function is needed to cope with fractional frames - including two Blender rendering features
949  * mblur (motion blur that renders 'subframes' and blurs them together), and fields rendering. 
950  */
951 float BKE_scene_frame_get(Scene *scene)
952 {
953         return BKE_scene_frame_get_from_ctime(scene, scene->r.cfra);
954 }
955
956 /* This function is used to obtain arbitrary fractional frames */
957 float BKE_scene_frame_get_from_ctime(Scene *scene, const float frame)
958 {
959         float ctime = frame;
960         ctime += scene->r.subframe;
961         ctime *= scene->r.framelen;
962         
963         return ctime;
964 }
965
966 /* drivers support/hacks 
967  *  - this method is called from scene_update_tagged_recursive(), so gets included in viewport + render
968  *      - these are always run since the depsgraph can't handle non-object data
969  *      - these happen after objects are all done so that we can read in their final transform values,
970  *        though this means that objects can't refer to scene info for guidance...
971  */
972 static void scene_update_drivers(Main *UNUSED(bmain), Scene *scene)
973 {
974         float ctime = BKE_scene_frame_get(scene);
975         
976         /* scene itself */
977         if (scene->adt && scene->adt->drivers.first) {
978                 BKE_animsys_evaluate_animdata(scene, &scene->id, scene->adt, ctime, ADT_RECALC_DRIVERS);
979         }
980
981         /* world */
982         /* TODO: what about world textures? but then those have nodes too... */
983         if (scene->world) {
984                 ID *wid = (ID *)scene->world;
985                 AnimData *adt = BKE_animdata_from_id(wid);
986                 
987                 if (adt && adt->drivers.first)
988                         BKE_animsys_evaluate_animdata(scene, wid, adt, ctime, ADT_RECALC_DRIVERS);
989         }
990         
991         /* nodes */
992         if (scene->nodetree) {
993                 ID *nid = (ID *)scene->nodetree;
994                 AnimData *adt = BKE_animdata_from_id(nid);
995                 
996                 if (adt && adt->drivers.first)
997                         BKE_animsys_evaluate_animdata(scene, nid, adt, ctime, ADT_RECALC_DRIVERS);
998         }
999 }
1000
1001 static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scene_parent)
1002 {
1003         Base *base;
1004         
1005         
1006         scene->customdata_mask = scene_parent->customdata_mask;
1007
1008         /* sets first, we allow per definition current scene to have
1009          * dependencies on sets, but not the other way around. */
1010         if (scene->set)
1011                 scene_update_tagged_recursive(bmain, scene->set, scene_parent);
1012         
1013         /* scene objects */
1014         for (base = scene->base.first; base; base = base->next) {
1015                 Object *ob = base->object;
1016                 
1017                 BKE_object_handle_update(scene_parent, ob);
1018                 
1019                 if (ob->dup_group && (ob->transflag & OB_DUPLIGROUP))
1020                         group_handle_recalc_and_update(scene_parent, ob, ob->dup_group);
1021                         
1022                 /* always update layer, so that animating layers works */
1023                 base->lay = ob->lay;
1024         }
1025         
1026         /* scene drivers... */
1027         scene_update_drivers(bmain, scene);
1028
1029         /* update sound system animation */
1030         sound_update_scene(scene);
1031
1032         /* update masking curves */
1033         BKE_mask_update_scene(bmain, scene, FALSE);
1034 }
1035
1036 /* this is called in main loop, doing tagged updates before redraw */
1037 void BKE_scene_update_tagged(Main *bmain, Scene *scene)
1038 {
1039         /* keep this first */
1040         BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_SCENE_UPDATE_PRE);
1041
1042         /* flush recalc flags to dependencies */
1043         DAG_ids_flush_tagged(bmain);
1044
1045         /* removed calls to quick_cache, see pointcache.c */
1046         
1047         /* clear "LIB_DOIT" flag from all materials, to prevent infinite recursion problems later 
1048          * when trying to find materials with drivers that need evaluating [#32017] 
1049          */
1050         tag_main_idcode(bmain, ID_MA, FALSE);
1051
1052         /* update all objects: drivers, matrices, displists, etc. flags set
1053          * by depgraph or manual, no layer check here, gets correct flushed
1054          *
1055          * in the future this should handle updates for all datablocks, not
1056          * only objects and scenes. - brecht */
1057         scene_update_tagged_recursive(bmain, scene, scene);
1058
1059         /* extra call here to recalc scene animation (for sequencer) */
1060         {
1061                 AnimData *adt = BKE_animdata_from_id(&scene->id);
1062                 float ctime = BKE_scene_frame_get(scene);
1063                 
1064                 if (adt && (adt->recalc & ADT_RECALC_ANIM))
1065                         BKE_animsys_evaluate_animdata(scene, &scene->id, adt, ctime, 0);
1066         }
1067         
1068         /* notify editors and python about recalc */
1069         BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_SCENE_UPDATE_POST);
1070         DAG_ids_check_recalc(bmain, scene, FALSE);
1071
1072         /* clear recalc flags */
1073         DAG_ids_clear_recalc(bmain);
1074 }
1075
1076 /* applies changes right away, does all sets too */
1077 void BKE_scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay)
1078 {
1079         float ctime = BKE_scene_frame_get(sce);
1080         Scene *sce_iter;
1081
1082         /* keep this first */
1083         BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_FRAME_CHANGE_PRE);
1084         BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_SCENE_UPDATE_PRE);
1085
1086         sound_set_cfra(sce->r.cfra);
1087         
1088         /* clear animation overrides */
1089         /* XXX TODO... */
1090
1091         for (sce_iter = sce; sce_iter; sce_iter = sce_iter->set) {
1092                 if (sce_iter->theDag == NULL)
1093                         DAG_scene_sort(bmain, sce_iter);
1094         }
1095
1096         /* flush recalc flags to dependencies, if we were only changing a frame
1097          * this would not be necessary, but if a user or a script has modified
1098          * some datablock before BKE_scene_update_tagged was called, we need the flush */
1099         DAG_ids_flush_tagged(bmain);
1100
1101         /* Following 2 functions are recursive
1102          * so don't call within 'scene_update_tagged_recursive' */
1103         DAG_scene_update_flags(bmain, sce, lay, TRUE);   // only stuff that moves or needs display still
1104
1105         BKE_mask_evaluate_all_masks(bmain, ctime, TRUE);
1106
1107         /* All 'standard' (i.e. without any dependencies) animation is handled here,
1108          * with an 'local' to 'macro' order of evaluation. This should ensure that
1109          * settings stored nestled within a hierarchy (i.e. settings in a Texture block
1110          * can be overridden by settings from Scene, which owns the Texture through a hierarchy
1111          * such as Scene->World->MTex/Texture) can still get correctly overridden.
1112          */
1113         BKE_animsys_evaluate_all_animation(bmain, sce, ctime);
1114         /*...done with recusrive funcs */
1115
1116         /* clear "LIB_DOIT" flag from all materials, to prevent infinite recursion problems later 
1117          * when trying to find materials with drivers that need evaluating [#32017] 
1118          */
1119         tag_main_idcode(bmain, ID_MA, FALSE);
1120
1121         /* BKE_object_handle_update() on all objects, groups and sets */
1122         scene_update_tagged_recursive(bmain, sce, sce);
1123
1124         /* notify editors and python about recalc */
1125         BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_SCENE_UPDATE_POST);
1126         BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_FRAME_CHANGE_POST);
1127
1128         DAG_ids_check_recalc(bmain, sce, TRUE);
1129
1130         /* clear recalc flags */
1131         DAG_ids_clear_recalc(bmain);
1132 }
1133
1134 /* return default layer, also used to patch old files */
1135 SceneRenderLayer *BKE_scene_add_render_layer(Scene *sce, const char *name)
1136 {
1137         SceneRenderLayer *srl;
1138
1139         if (!name)
1140                 name = "RenderLayer";
1141
1142         srl = MEM_callocN(sizeof(SceneRenderLayer), "new render layer");
1143         BLI_strncpy(srl->name, name, sizeof(srl->name));
1144         BLI_uniquename(&sce->r.layers, srl, "RenderLayer", '.', offsetof(SceneRenderLayer, name), sizeof(srl->name));
1145         BLI_addtail(&sce->r.layers, srl);
1146
1147         /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */
1148         srl->lay = (1 << 20) - 1;
1149         srl->layflag = 0x7FFF;   /* solid ztra halo edge strand */
1150         srl->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
1151
1152         return srl;
1153 }
1154
1155 int BKE_scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *srl)
1156 {
1157         const int act = BLI_findindex(&scene->r.layers, srl);
1158         Scene *sce;
1159
1160         if (act == -1) {
1161                 return 0;
1162         }
1163         else if ( (scene->r.layers.first == scene->r.layers.last) &&
1164                   (scene->r.layers.first == srl))
1165         {
1166                 /* ensure 1 layer is kept */
1167                 return 0;
1168         }
1169
1170         BLI_remlink(&scene->r.layers, srl);
1171         MEM_freeN(srl);
1172
1173         scene->r.actlay = 0;
1174
1175         for (sce = bmain->scene.first; sce; sce = sce->id.next) {
1176                 if (sce->nodetree) {
1177                         bNode *node;
1178                         for (node = sce->nodetree->nodes.first; node; node = node->next) {
1179                                 if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) {
1180                                         if (node->custom1 == act)
1181                                                 node->custom1 = 0;
1182                                         else if (node->custom1 > act)
1183                                                 node->custom1--;
1184                                 }
1185                         }
1186                 }
1187         }
1188
1189         return 1;
1190 }
1191
1192 /* render simplification */
1193
1194 int get_render_subsurf_level(RenderData *r, int lvl)
1195 {
1196         if (r->mode & R_SIMPLIFY)
1197                 return min_ii(r->simplify_subsurf, lvl);
1198         else
1199                 return lvl;
1200 }
1201
1202 int get_render_child_particle_number(RenderData *r, int num)
1203 {
1204         if (r->mode & R_SIMPLIFY)
1205                 return (int)(r->simplify_particles * num);
1206         else
1207                 return num;
1208 }
1209
1210 int get_render_shadow_samples(RenderData *r, int samples)
1211 {
1212         if ((r->mode & R_SIMPLIFY) && samples > 0)
1213                 return min_ii(r->simplify_shadowsamples, samples);
1214         else
1215                 return samples;
1216 }
1217
1218 float get_render_aosss_error(RenderData *r, float error)
1219 {
1220         if (r->mode & R_SIMPLIFY)
1221                 return ((1.0f - r->simplify_aosss) * 10.0f + 1.0f) * error;
1222         else
1223                 return error;
1224 }
1225
1226 /* helper function for the SETLOOPER macro */
1227 Base *_setlooper_base_step(Scene **sce_iter, Base *base)
1228 {
1229         if (base && base->next) {
1230                 /* common case, step to the next */
1231                 return base->next;
1232         }
1233         else if (base == NULL && (*sce_iter)->base.first) {
1234                 /* first time looping, return the scenes first base */
1235                 return (Base *)(*sce_iter)->base.first;
1236         }
1237         else {
1238                 /* reached the end, get the next base in the set */
1239                 while ((*sce_iter = (*sce_iter)->set)) {
1240                         base = (Base *)(*sce_iter)->base.first;
1241                         if (base) {
1242                                 return base;
1243                         }
1244                 }
1245         }
1246
1247         return NULL;
1248 }
1249
1250 int BKE_scene_use_new_shading_nodes(Scene *scene)
1251 {
1252         RenderEngineType *type = RE_engines_find(scene->r.engine);
1253         return (type && type->flag & RE_USE_SHADING_NODES);
1254 }
1255
1256 void BKE_scene_base_flag_to_objects(struct Scene *scene)
1257 {
1258         Base *base = scene->base.first;
1259
1260         while (base) {
1261                 base->object->flag = base->flag;
1262                 base = base->next;
1263         }
1264 }
1265
1266 void BKE_scene_base_flag_from_objects(struct Scene *scene)
1267 {
1268         Base *base = scene->base.first;
1269
1270         while (base) {
1271                 base->flag = base->object->flag;
1272                 base = base->next;
1273         }
1274 }
1275
1276 void BKE_scene_disable_color_management(Scene *scene)
1277 {
1278         ColorManagedDisplaySettings *display_settings = &scene->display_settings;
1279         ColorManagedViewSettings *view_settings = &scene->view_settings;
1280         const char *view;
1281         const char *none_display_name;
1282
1283         none_display_name = IMB_colormanagement_display_get_none_name();
1284
1285         BLI_strncpy(display_settings->display_device, none_display_name, sizeof(display_settings->display_device));
1286
1287         view = IMB_colormanagement_view_get_default_name(display_settings->display_device);
1288
1289         if (view) {
1290                 BLI_strncpy(view_settings->view_transform, view, sizeof(view_settings->view_transform));
1291         }
1292 }
1293
1294 int BKE_scene_check_color_management_enabled(const Scene *scene)
1295 {
1296         return strcmp(scene->display_settings.display_device, "None") != 0;
1297 }