Merging r49681 through r49707 from trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 8 Aug 2012 16:48:05 +0000 (16:48 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 8 Aug 2012 16:48:05 +0000 (16:48 +0000)
13 files changed:
1  2 
build_files/cmake/macros.cmake
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/scene.c
source/blender/editors/render/render_internal.c
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/imbuf/intern/filter.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c
source/blender/render/intern/source/pipeline.c
source/blender/windowmanager/intern/wm_init_exit.c
source/blenderplayer/bad_level_call_stubs/stubs.c

index 90ab0189a0946f0855ce365eae37028b86c34943,50bbab9eed9b61849d1d9f5ed6395a37595229d3..522a07ff7b23e59a3c1f43f770f333c6979ccab0
@@@ -212,9 -212,6 +212,9 @@@ macro(SETUP_LIBDIRS
        if(WITH_OPENIMAGEIO)
                link_directories(${OPENIMAGEIO_LIBPATH})
        endif()
 +      if(WITH_OPENCOLORIO)
 +              link_directories(${OPENCOLORIO_LIBPATH})
 +      endif()
        if(WITH_IMAGE_OPENJPEG AND WITH_SYSTEM_OPENJPEG)
                link_directories(${OPENJPEG_LIBPATH})
        endif()
@@@ -310,9 -307,6 +310,9 @@@ macro(setup_liblink
        if(WITH_OPENIMAGEIO)
                target_link_libraries(${target} ${OPENIMAGEIO_LIBRARIES})
        endif()
 +      if(WITH_OPENCOLORIO)
 +              target_link_libraries(${target} ${OPENCOLORIO_LIBRARIES})
 +      endif()
        if(WITH_BOOST)
                target_link_libraries(${target} ${BOOST_LIBRARIES})
        endif()
@@@ -731,3 -725,31 +731,31 @@@ macro(set_lib_pat
                set(${lvar} ${LIBDIR}/${lproj})
        endif()
  endmacro()
+ # not highly optimal, may replace with generated C program like makesdna
+ function(data_to_c
+          file_from file_to var_name)
+       file(READ ${file_from} file_from_string HEX)
+       string(LENGTH ${file_from_string} _max_index)
+       math(EXPR size_on_disk ${_max_index}/2)
+       file(REMOVE ${file_to})
+       file(APPEND ${file_to} "int  ${var_name}_size = ${size_on_disk};\n")
+       file(APPEND ${file_to} "char ${var_name}[] = {")
+       set(_index 0)
+       while(NOT _index EQUAL _max_index)
+               string(SUBSTRING "${file_from_string}" ${_index} 2 _pair)
+               file(APPEND ${file_to} "0x${_pair},")
+               math(EXPR _index ${_index}+2)
+       endwhile()
+       file(APPEND ${file_to} "};\n")
+ endfunction()
+ # eg
+ # data_to_c("/home/guest/test.txt" "/home/guest/test.txt.h" "this_is_data")
index e89b82138e32cfbfd7b84dc0a1999920d6ccfd31,c098056eb5e95c3f6b3fdba1909e84636ee49bee..0e1228cf51d1114114f3bdb7dbdb7cc455a471b5
@@@ -91,8 -91,6 +91,8 @@@
  
  #include "WM_api.h" // XXXXX BAD, very BAD dependency (bad level call) - remove asap, elubie
  
 +#include "IMB_colormanagement.h"
 +
  #ifdef WITH_PYTHON
  #include "BPY_extern.h"
  #endif
@@@ -118,7 -116,7 +118,7 @@@ void free_blender(void
  
        BLI_callback_global_finalize();
  
-       seq_stripelem_cache_destruct();
+       BKE_sequencer_cache_destruct();
        IMB_moviecache_destruct();
        
        free_nodesystem();      
@@@ -326,11 -324,7 +326,11 @@@ static void setup_app_data(bContext *C
  
        /* baseflags, groups, make depsgraph, etc */
        BKE_scene_set_background(G.main, CTX_data_scene(C));
 -      
 +
 +      if (mode != 'u') {
 +              IMB_colormanagement_check_file_config(G.main);
 +      }
 +
        MEM_freeN(bfd);
  
        (void)curscene; /* quiet warning */
index ebdf2f724081b96eedd35b1a60d74739b0d28a96,936ef9731282ea4c4f2b97944eca3404a28235f6..cdee0d98a2510359bcb313a19497fc36be130edb
@@@ -47,7 -47,6 +47,7 @@@
  
  #include "MEM_guardedalloc.h"
  
 +#include "IMB_colormanagement.h"
  #include "IMB_imbuf_types.h"
  #include "IMB_imbuf.h"
  
@@@ -71,7 -70,6 +71,7 @@@
  #include "BLI_bpath.h"
  
  #include "BKE_bmfont.h"
 +#include "BKE_colortools.h"
  #include "BKE_global.h"
  #include "BKE_icons.h"
  #include "BKE_image.h"
@@@ -246,8 -244,6 +246,8 @@@ static Image *image_alloc(const char *n
  
                ima->source = source;
                ima->type = type;
 +
 +              BKE_color_managed_colorspace_settings_init(&ima->colorspace_settings);
        }
        return ima;
  }
@@@ -330,8 -326,6 +330,8 @@@ Image *BKE_image_copy(Image *ima
        nima->aspx = ima->aspx;
        nima->aspy = ima->aspy;
  
 +      BKE_color_managed_colorspace_settings_copy(&nima->colorspace_settings, &ima->colorspace_settings);
 +
        return nima;
  }
  
@@@ -1016,20 -1010,6 +1016,20 @@@ int BKE_imtype_supports_quality(const c
        return 0;
  }
  
 +int BKE_imtype_supports_float(const char imtype)
 +{
 +      switch (imtype) {
 +              case R_IMF_IMTYPE_CINEON:
 +              case R_IMF_IMTYPE_DPX:
 +              case R_IMF_IMTYPE_RADHDR:
 +              case R_IMF_IMTYPE_OPENEXR:
 +              case R_IMF_IMTYPE_MULTILAYER:
 +              case R_IMF_IMTYPE_JP2:
 +                      return TRUE;
 +      }
 +      return 0;
 +}
 +
  char BKE_imtype_valid_channels(const char imtype)
  {
        char chan_flag = IMA_CHAN_FLAG_RGB; /* assume all support rgb */
@@@ -1462,7 -1442,7 +1462,7 @@@ static void stampdata(Scene *scene, Obj
        }
  
        if (scene->r.stamp & R_STAMP_SEQSTRIP) {
-               Sequence *seq = seq_foreground_frame_get(scene, scene->r.cfra);
+               Sequence *seq = BKE_sequencer_foreground_frame_get(scene, scene->r.cfra);
  
                if (seq) BLI_strncpy(text, seq->name + 2, sizeof(text));
                else BLI_strncpy(text, "<none>", sizeof(text));
@@@ -2193,9 -2173,6 +2193,9 @@@ static void image_create_multilayer(Ima
  /* common stuff to do with images after loading */
  static void image_initialize_after_load(Image *ima, ImBuf *ibuf)
  {
 +      /* make float buffer stored in ImBuf scene linear space */
 +      IMB_colormanagement_imbuf_make_scene_linear(ibuf, &ima->colorspace_settings);
 +
        /* preview is NULL when it has never been used as an icon before */
        if (G.background == 0 && ima->preview == NULL)
                BKE_icon_changed(BKE_icon_getid(&ima->id));
@@@ -2563,23 -2540,13 +2563,23 @@@ static ImBuf *image_get_render_result(I
                image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
        }
  
 +      /* invalidate color managed buffers if render result changed */
 +      BLI_lock_thread(LOCK_COLORMANAGE);
 +      if (ibuf->x != rres.rectx || ibuf->y != rres.recty || ibuf->rect_float != rectf) {
 +              IMB_display_buffer_invalidate(ibuf);
 +      }
 +
        ibuf->x = rres.rectx;
        ibuf->y = rres.recty;
  
        /* free rect buffer if float buffer changes, so it can be recreated with
         * the updated result, and also in case we got byte buffer from sequencer,
         * so we don't keep reference to freed buffer */
 -      if (ibuf->rect_float != rectf || rect || !rectf)
 +      
 +      /* todo: this fix breaks save buffers render progress 
 +         if (ibuf->rect_float != rectf || rect || !rectf) */
 +
 +      if (ibuf->rect_float != rectf || rect)
                imb_freerectImBuf(ibuf);
  
        if (rect)
                ibuf->flags &= ~IB_zbuffloat;
        }
  
 +      BLI_unlock_thread(LOCK_COLORMANAGE);
 +
        /* since its possible to access the buffer from the image directly, set the profile [#25073] */
        ibuf->profile = (iuser->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_NONE;
        ibuf->dither = dither;
index 22cb202e0193f2bc98c407b6535f10aab0028f90,889792ad3f82cf61300706702c79b10a0b96d364..444fbb2fc9f4ed643d3480e0ed2954bcbf666bdc
@@@ -57,7 -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"
@@@ -133,8 -132,6 +133,8 @@@ Scene *BKE_scene_copy(Scene *sce, int t
                MEM_freeN(scen->toolsettings);
        }
        else {
 +              ImageFormatData *im_format, *im_formatn;
 +
                scen = BKE_libblock_copy(&sce->id);
                BLI_duplicatelist(&(scen->base), &(sce->base));
                
                        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 */
                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);
                }
        }
  
@@@ -555,9 -545,6 +555,9 @@@ 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;
  }
  
@@@ -652,7 -639,7 +652,7 @@@ void BKE_scene_unlink(Main *bmain, Scen
                        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);
index d450cb58adf0f868d7227901b3504c7db3ec5fc9,6eaef62ec404f03ec021eff0b820dbe727313700..87d2c79d28faefbebb70b8a501e19dc66304a863
@@@ -61,7 -61,6 +61,7 @@@
  #include "ED_object.h"
  
  #include "RE_pipeline.h"
 +#include "IMB_colormanagement.h"
  #include "IMB_imbuf.h"
  #include "IMB_imbuf_types.h"
  
@@@ -151,9 -150,6 +151,9 @@@ void image_buffer_rect_update(Scene *sc
        IMB_buffer_byte_from_float(rectc, rectf,
                                   4, ibuf->dither, IB_PROFILE_SRGB, profile_from, predivide,
                                   xmax, ymax, ibuf->x, rr->rectx);
 +
 +      IMB_partial_display_buffer_update(ibuf, rectf, rr->rectx, rxmin, rymin,
 +                                        rxmin, rymin, rxmin + xmax, rymin + ymax);
  }
  
  /* ****************************** render invoking ***************** */
@@@ -228,7 -224,7 +228,7 @@@ static int screen_render_exec(bContext 
         * otherwise, invalidated cache entries can make their way into
         * the output rendering. We can't put that into RE_BlenderFrame,
         * since sequence rendering can call that recursively... (peter) */
-       seq_stripelem_cache_cleanup();
+       BKE_sequencer_cache_cleanup();
  
        RE_SetReports(re, op->reports);
  
@@@ -530,7 -526,7 +530,7 @@@ static int screen_render_invoke(bContex
         * otherwise, invalidated cache entries can make their way into
         * the output rendering. We can't put that into RE_BlenderFrame,
         * since sequence rendering can call that recursively... (peter) */
-       seq_stripelem_cache_cleanup();
+       BKE_sequencer_cache_cleanup();
  
        /* get editmode results */
        ED_object_exit_editmode(C, 0);  /* 0 = does not exit editmode */
index 6c6525ed7cd2e64e4ed255dc53d0bb7af15f3e59,4e9e0c92bd9dc30d3e803349eff281a468f7ed25..a1aee223c8f344c44bc045f72ea7346d111f0dc5
@@@ -63,7 -63,6 +63,7 @@@
  
  #include "UI_resources.h"
  
 +#include "IMB_colormanagement.h"
  #include "IMB_imbuf.h"
  #include "IMB_imbuf_types.h"
  
@@@ -339,8 -338,8 +339,8 @@@ static void node_buts_curvevec(uiLayou
        uiTemplateCurveMapping(layout, ptr, "mapping", 'v', 0, 0);
  }
  
- static float _sample_col[4];  /* bad bad, 2.5 will do better?... no it won't... */
  #define SAMPLE_FLT_ISNONE FLT_MAX
+ static float _sample_col[4] = {SAMPLE_FLT_ISNONE};  /* bad bad, 2.5 will do better?... no it won't... */
  void ED_node_sample_set(const float col[4])
  {
        if (col) {
@@@ -1325,10 -1324,6 +1325,10 @@@ static void node_shader_buts_tex_image(
  
        uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
        uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE);
 +      uiItemR(layout, ptr, "projection", 0, "", ICON_NONE);
 +
 +      if(RNA_enum_get(ptr, "projection") == SHD_PROJ_BOX)
 +              uiItemR(layout, ptr, "projection_blend", 0, "Blend", ICON_NONE);
  
        /* note: image user properties used directly here, unlike compositor image node,
         * which redefines them in the node struct RNA to get proper updates.
@@@ -3014,7 -3009,7 +3014,7 @@@ void ED_node_init_butfuncs(void
  
  /* ************** Generic drawing ************** */
  
 -void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
 +void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode)
  {
        
        if ((snode->flag & SNODE_BACKDRAW) && snode->treetype == NTREE_COMPOSIT) {
                void *lock;
                ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
                if (ibuf) {
 +                      SpaceNode *snode = CTX_wm_space_node(C);
 +                      wmWindow *win = CTX_wm_window(C);
 +                      const ColorManagedViewSettings *view_settings;
                        float x, y; 
 +                      unsigned char *display_buffer;
 +                      void *cache_handle;
                        
                        glMatrixMode(GL_PROJECTION);
                        glPushMatrix();
                        x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof;
                        y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof;
                        
 -                      if (!ibuf->rect) {
 -                              if (color_manage)
 -                                      ibuf->profile = IB_PROFILE_LINEAR_RGB;
 -                              else
 -                                      ibuf->profile = IB_PROFILE_NONE;
 -                              IMB_rect_from_float(ibuf);
 -                      }
  
 -                      if (ibuf->rect) {
 +                      view_settings = IMB_view_settings_get_effective(win, &snode->view_settings);
 +                      display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, &win->display_settings, &cache_handle);
 +
 +                      if (display_buffer) {
                                if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B)) {
                                        int ofs;
  
  #ifdef __BIG_ENDIAN__
                                        glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
  #endif
 -                                      glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, ibuf->rect);
 +                                      glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, display_buffer);
  
  #ifdef __BIG_ENDIAN__
                                        glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
                                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                                        glPixelZoom(snode->zoom, snode->zoom);
                                        
 -                                      glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
 +                                      glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, display_buffer);
                                        
                                        glPixelZoom(1.0f, 1.0f);
                                        glDisable(GL_BLEND);
                                else {
                                        glPixelZoom(snode->zoom, snode->zoom);
                                        
 -                                      glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
 +                                      glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, display_buffer);
                                        
                                        glPixelZoom(1.0f, 1.0f);
                                }
                        }
  
 +                      IMB_display_buffer_release(cache_handle);
 +
                        /** @note draw selected info on backdrop */
                        if (snode->edittree) {
                                bNode *node = snode->edittree->nodes.first;
index 910951864b893f23fc106e8c24db752f14dfde91,dc19dfc419d6e21bd8111303859f2b221771bba1..0fcc935d3e197fbbcd56989726596a30f2edd4f3
@@@ -52,7 -52,6 +52,7 @@@
  
  #include "BKE_sound.h"
  
 +#include "IMB_colormanagement.h"
  #include "IMB_imbuf.h"
  
  #include "BIF_gl.h"
@@@ -69,9 -68,6 +69,9 @@@
  #include "UI_resources.h"
  #include "UI_view2d.h"
  
 +#include "WM_api.h"
 +#include "WM_types.h"
 +
  /* own include */
  #include "sequencer_intern.h"
  
@@@ -378,7 -374,7 +378,7 @@@ static void draw_seq_handle(View2D *v2d
        
        /* draw! */
        if (seq->type < SEQ_TYPE_EFFECT || 
-           get_sequence_effect_num_inputs(seq->type) == 0)
+           BKE_sequence_effect_get_num_inputs(seq->type) == 0)
        {
                glEnable(GL_BLEND);
                
@@@ -534,7 -530,7 +534,7 @@@ static void draw_seq_text(View2D *v2d, 
  
        /* note, all strings should include 'name' */
        if (name[0] == '\0')
-               name = give_seqname(seq);
+               name = BKE_sequence_give_name(seq);
  
        if (seq->type == SEQ_TYPE_META || seq->type == SEQ_TYPE_ADJUSTMENT) {
                BLI_snprintf(str, sizeof(str), "%s | %d", name, seq->len);
@@@ -689,7 -685,7 +689,7 @@@ static void draw_seq_strip(Scene *scene
        const float handsize_clamped = draw_seq_handle_size_get_clamped(seq, pixelx);
  
        /* we need to know if this is a single image/color or not for drawing */
-       is_single_image = (char)seq_single_check(seq);
+       is_single_image = (char)BKE_sequence_single_check(seq);
        
        /* body */
        x1 = (seq->startstill) ? seq->start : seq->startdisp;
        
        /* draw the main strip body */
        if (is_single_image) {  /* single image */
-               draw_shadedstrip(seq, background_col, seq_tx_get_final_left(seq, 0), y1, seq_tx_get_final_right(seq, 0), y2);
+               draw_shadedstrip(seq, background_col, BKE_sequence_tx_get_final_left(seq, 0), y1, BKE_sequence_tx_get_final_right(seq, 0), y2);
        }
        else {  /* normal operation */
                draw_shadedstrip(seq, background_col, x1, y1, x2, y2);
@@@ -816,8 -812,6 +816,8 @@@ void draw_image_seq(const bContext *C, 
        GLuint texid;
        GLuint last_texid;
        SeqRenderData context;
 +      unsigned char *display_buffer;
 +      void *cache_handle = NULL;
  
        render_size = sseq->render_size;
        if (render_size == 0) {
        if (G.rendering)
                return;
  
-       context = seq_new_render_data(bmain, scene, rectx, recty, proxy_size);
+       context = BKE_sequencer_new_render_data(bmain, scene, rectx, recty, proxy_size);
  
        if (special_seq_update)
-               ibuf = give_ibuf_seq_direct(context, cfra + frame_ofs, special_seq_update);
+               ibuf = BKE_sequencer_give_ibuf_direct(context, cfra + frame_ofs, special_seq_update);
        else if (!U.prefetchframes) // XXX || (G.f & G_PLAYANIM) == 0) {
-               ibuf = give_ibuf_seq(context, cfra + frame_ofs, sseq->chanshown);
+               ibuf = BKE_sequencer_give_ibuf(context, cfra + frame_ofs, sseq->chanshown);
        else
-               ibuf = give_ibuf_seq_threaded(context, cfra + frame_ofs, sseq->chanshown);
+               ibuf = BKE_sequencer_give_ibuf_threaded(context, cfra + frame_ofs, sseq->chanshown);
        
        if (ibuf == NULL)
                return;
        if (scope) {
                IMB_freeImBuf(ibuf);
                ibuf = scope;
 +
 +              if (ibuf->rect_float && ibuf->rect == NULL) {
 +                      IMB_rect_from_float(ibuf);
 +              }
 +
 +              display_buffer = (unsigned char *)ibuf->rect;
        }
 +      else {
 +              const ColorManagedViewSettings *view_settings;
 +              wmWindow *win = CTX_wm_window(C);
 +
 +              ibuf->colormanagement_flags |= IMB_COLORMANAGEMENT_SRGB_SOURCE;
  
 -      if (ibuf->rect_float && ibuf->rect == NULL) {
 -              IMB_rect_from_float(ibuf);      
 +              view_settings = IMB_view_settings_get_effective(win, &sseq->view_settings);
 +              display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, &win->display_settings, &cache_handle);
        }
 -      
 +
        /* setting up the view - actual drawing starts here */
        UI_view2d_view_ortho(v2d);
  
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  
 -      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
 +      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, display_buffer);
        glBegin(GL_QUADS);
  
        if (frame_ofs) {
                }
        }
  
 +      if (cache_handle)
 +              IMB_display_buffer_release(cache_handle);
  }
  
  #if 0
index 12860ebc613bb6a96816755ba0f3950776a1211a,678b2908b96e54307a86f545038a463443d457da..5f8e9bd4dec6a7632a28f9c40186373fc6c8b8da
   *  \ingroup imbuf
   */
  
 +#include <math.h>
 +
  #include "MEM_guardedalloc.h"
  
 +#include "BLI_math.h"
  #include "BLI_utildefines.h"
  
  #include "IMB_imbuf_types.h"
@@@ -229,24 -226,24 +229,24 @@@ void IMB_filterN(ImBuf *out, ImBuf *in
                for (x = 0; x < rowlen; x++) {
                        if (x == 0) {
                                r11 = row1;
-                               r21 = row1;
-                               r31 = row1;
+                               r21 = row2;
+                               r31 = row3;
                        }
                        else {
                                r11 = row1 - 4;
-                               r21 = row1 - 4;
-                               r31 = row1 - 4;
+                               r21 = row2 - 4;
+                               r31 = row3 - 4;
                        }
  
                        if (x == rowlen - 1) {
                                r13 = row1;
-                               r23 = row1;
-                               r33 = row1;
+                               r23 = row2;
+                               r33 = row3;
                        }
                        else {
                                r13 = row1 + 4;
-                               r23 = row1 + 4;
-                               r33 = row1 + 4;
+                               r23 = row2 + 4;
+                               r33 = row3 + 4;
                        }
  
                        cp[0] = (r11[0] + 2 * row1[0] + r13[0] + 2 * r21[0] + 4 * row2[0] + 2 * r23[0] + r31[0] + 2 * row3[0] + r33[0]) >> 4;
@@@ -602,217 -599,3 +602,217 @@@ void IMB_premultiply_alpha(ImBuf *ibuf
                IMB_premultiply_rect_float(ibuf->rect_float, ibuf->planes, ibuf->x, ibuf->y);
  }
  
 +/* Tonecurve corrections */
 +
 +/* code of rdt_shaper_fwd and ratio_preserving_odt_tonecurve belongs to
 + * ACES project (https://github.com/ampas/aces-dev)
 + */
 +
 +/* === ODT SPLINE === */
 +/*
 + * Algorithm for applying ODT tone curve in forward direction.
 + *
 + *     vers 1.0  Doug Walker       2012-01-23
 + *      modified by Scott Dyer      2012-02-28
 + */
 +
 +/* Input and output are in linear (not log) units. */
 +static float rdt_shaper_fwd(float x)
 +{
 +      /* B-spline coefficients.
 +       * The units are density of the output.
 +       */
 +      const float COEFS0 = -0.008f;
 +      const float COEFS1 = -0.00616f;
 +      const float COEFS2 =  0.026f;
 +      const float COEFS3 =  0.185f;
 +      const float COEFS4 =  0.521f;
 +      const float COEFS5 =  0.993f;
 +      const float COEFS6 =  1.563f;
 +      const float COEFS7 =  2.218f;
 +      const float COEFS8 =  2.795f;
 +      const float COEFS9 =  3.36f;
 +      const float COEFS10 = 4.0f;   /* NB: keep this less than or equal to -log10(FLARE) */
 +      /* The locations of these control points in OCES density space are:
 +       * -1., -0.79, -0.44, -0.01, 0.48, 1.01, 1.58, 2.18, 2.82, 3.47, 4.15, 4.85
 +       */
 +
 +      /* The flare term allows the spline to more rapidly approach zero
 +       * while keeping the shape of the curve well-behaved in density space.
 +       */
 +      const float FLARE = 1e-4f;
 +
 +      /* The last control point is fixed to yield a specific density at the
 +       * end of the knot domain.
 +       */
 +      /* const float COEFS11 = 2. * (-log10(FLARE) - 0.001) - COEFS10; */
 +
 +      /* Note: Apparently a CTL bug prevents calling log10() here, so
 +       * you'll need to update this manually if you change FLARE.
 +       */
 +      const float COEFS11 = COEFS10 + 2.0f * (4.0f - COEFS10);
 +
 +      /* The knots are in units of OCES density. */
 +      const unsigned int KNOT_LEN = 11;
 +      const float KNOT_START = -0.9f;
 +      const float KNOT_END = 4.484256f;
 +
 +      /* The KNOT_POW adjusts the spacing to put more knots near the toe (highlights). */
 +      const float KNOT_POW = 1.0f / 1.3f;
 +      const float OFFS = KNOT_START;
 +      const float SC = KNOT_END - KNOT_START;
 +
 +      /* KNOT_DENS is density of the spline at the knots. */
 +      const float KNOT_DENS[11] = {
 +              (COEFS0 + COEFS1) / 2.0f,
 +              (COEFS1 + COEFS2) / 2.0f,
 +              (COEFS2 + COEFS3) / 2.0f,
 +              (COEFS3 + COEFS4) / 2.0f,
 +              (COEFS4 + COEFS5) / 2.0f,
 +              (COEFS5 + COEFS6) / 2.0f,
 +              (COEFS6 + COEFS7) / 2.0f,
 +              (COEFS7 + COEFS8) / 2.0f,
 +              (COEFS8 + COEFS9) / 2.0f,
 +              (COEFS9 + COEFS10) / 2.0f,
 +              (COEFS10 + COEFS11) / 2.0f
 +      };
 +
 +      /* Parameters controlling linear extrapolation. */
 +      const float LIGHT_SLOPE = 0.023;
 +      const float CROSSOVER = pow(10,-KNOT_END);
 +      const float REV_CROSSOVER = pow(10.0f, -KNOT_DENS[ KNOT_LEN - 1]) - FLARE;
 +      const float DARK_SLOPE = REV_CROSSOVER / CROSSOVER;
 +
 +      /* Textbook monomial to basis-function conversion matrix. */
 +      /*const*/ float M[3][3] = {
 +              { 0.5f, -1.0f, 0.5f},
 +              {-1.0f,  1.0f, 0.5f},
 +              { 0.5f,  0.0f, 0.0f}
 +      };
 +
 +      float y;
 +
 +      /* Linear extrapolation in linear space for negative & very dark values. */
 +      if (x <= CROSSOVER) {
 +              y = x * DARK_SLOPE;
 +      }
 +      else {
 +              float in_dens = -log10(x);
 +              float out_dens;
 +              float knot_coord = (in_dens - OFFS) / SC;
 +
 +              if (knot_coord <= 0.0f) {
 +                      /* Linear extrapolation in log space for very light values. */
 +
 +                      out_dens = KNOT_DENS[0] - (KNOT_START - in_dens) * LIGHT_SLOPE;
 +              }
 +              else {
 +                      /* For typical OCES values, apply a B-spline curve. */
 +
 +                      int j;
 +                      float t;
 +                      float cf[3], monomials[3], v[3];
 +
 +                      knot_coord = ( KNOT_LEN - 1) * pow( knot_coord, KNOT_POW);
 +
 +                      j = knot_coord;
 +                      t = knot_coord - j;
 +
 +                      /* Would like to do this: */
 +                      /* float cf[ 3] = { COEFS[ j], COEFS[ j + 1], COEFS[ j + 2]}; */
 +                      /* or at least: */
 +                      /* cf[0] = COEFS[j]; */
 +                      /* cf[1] = COEFS[j + 1]; */
 +                      /* cf[2] = COEFS[j + 2]; */
 +                      /* But apparently CTL bugs prevent it, so we do the following: */
 +                      if (j <= 0) {
 +                              cf[0] = COEFS0;  cf[1] = COEFS1;  cf[2] = COEFS2;
 +                      }
 +                      else if (j == 1) {
 +                              cf[0] = COEFS1;  cf[1] = COEFS2;  cf[2] = COEFS3;
 +                      }
 +                      else if (j == 2) {
 +                              cf[0] = COEFS2;  cf[1] = COEFS3;  cf[2] = COEFS4;
 +                      }
 +                      else if (j == 3) {
 +                              cf[0] = COEFS3;  cf[1] = COEFS4;  cf[2] = COEFS5;
 +                      }
 +                      else if (j == 4) {
 +                              cf[0] = COEFS4;  cf[1] = COEFS5;  cf[2] = COEFS6;
 +                      }
 +                      else if (j == 5) {
 +                              cf[0] = COEFS5;  cf[1] = COEFS6;  cf[2] = COEFS7;
 +                      }
 +                      else if (j == 6) {
 +                              cf[0] = COEFS6;  cf[1] = COEFS7;  cf[2] = COEFS8;
 +                      }
 +                      else if (j == 7) {
 +                              cf[0] = COEFS7;  cf[1] = COEFS8;  cf[2] = COEFS9;
 +                      }
 +                      else if (j == 8) {
 +                              cf[0] = COEFS8;  cf[1] = COEFS9;  cf[2] = COEFS10;
 +                      }
 +                      else {
 +                              cf[0] = COEFS9;  cf[1] = COEFS10;  cf[2] = COEFS11;
 +                      }
 +
 +                      monomials[0] = t * t;
 +                      monomials[1] = t;
 +                      monomials[2] = 1.0f;
 +
 +                      mul_v3_m3v3(v, M, cf);
 +                      out_dens = dot_v3v3( monomials, v);
 +              }
 +
 +              y = pow(10.0f, -out_dens) - FLARE;
 +      }
 +
 +      return y;
 +}
 +
 +void IMB_ratio_preserving_odt_tonecurve(float rgbOut[3], const float rgbIn[3])
 +{
 +      float acesIn[3], acesOut[3];
 +
 +      float rec709_to_aces[3][3] = {{0.4395770431f, 0.0895979404f, 0.0174174830f},
 +                                    {0.3839148879f, 0.8147120476f, 0.1087378338f},
 +                                    {0.1765103489f, 0.0956883803f, 0.8738504052f}};
 +
 +      float aces_to_rec709[3][3] = {{ 2.5219228268f, -0.2754705548f, -0.0159884077f},
 +                                    {-1.1370280981f,  1.3698303699f, -0.1477921605f},
 +                                    {-0.3849000633f, -0.0943564922f,  1.1637737751f}};
 +
 +      /* The "ratio preserving tonecurve" is used to avoid hue/chroma shifts.
 +       * It sends a norm through the tonecurve and scales the RGB values based on the output.
 +       */
 +
 +      const float NTH_POWER = 2.0f;
 +      const float TINY = 1e-12f;
 +      float numerator, denominator;
 +      float normRGB, normRGBo;
 +
 +      mul_v3_m3v3(acesIn, rec709_to_aces, (float *) rgbIn);
 +
 +      numerator = pow(acesIn[0], NTH_POWER) + pow(acesIn[1], NTH_POWER) + pow(acesIn[2], NTH_POWER);
 +
 +      denominator = pow(acesIn[0], NTH_POWER - 1) +
 +                    pow(acesIn[1], NTH_POWER - 1) +
 +                    pow(acesIn[2], NTH_POWER - 1);
 +
 +      /* use of max function to avoid divide by zero */
 +      denominator = MAX2(TINY, denominator);
 +
 +      normRGB = numerator / denominator;
 +
 +      if (normRGB <= 0.0f) {
 +              normRGB = TINY;
 +      }
 +
 +      normRGBo = rdt_shaper_fwd(normRGB);
 +
 +      acesOut[0] = acesIn[0] * normRGBo / normRGB;
 +      acesOut[1] = acesIn[1] * normRGBo / normRGB;
 +      acesOut[2] = acesIn[2] * normRGBo / normRGB;
 +
 +      mul_v3_m3v3(rgbOut, aces_to_rec709, (float *) acesOut);
 +}
index 384b3f9b0d5d6dcd3a53a4d663d833055bb34d55,09099ca5d9335481920b12789ac20b446202374c..43dab2b669dca6a42f1b1bbe47721757e4fdeca4
@@@ -475,7 -475,7 +475,7 @@@ static void rna_Scene_layer_update(Mai
  static void rna_Scene_fps_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
  {
        sound_update_fps(scene);
-       seq_update_sound_bounds_all(scene);
+       BKE_sequencer_update_sound_bounds_all(scene);
  }
  
  static void rna_Scene_listener_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
@@@ -2958,17 -2958,6 +2958,17 @@@ static void rna_def_scene_image_format_
        RNA_def_property_range(prop, 0.0f, 10.0f);
        RNA_def_property_ui_text(prop, "G", "Log conversion gamma");
        RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
 +
 +      /* color management */
 +      prop = RNA_def_property(srna, "view_settings", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_pointer_sdna(prop, NULL, "view_settings");
 +      RNA_def_property_struct_type(prop, "ColorManagedViewSettings");
 +      RNA_def_property_ui_text(prop, "View Settings", "Color management settings applied on image before saving");
 +
 +      prop = RNA_def_property(srna, "display_settings", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_pointer_sdna(prop, NULL, "display_settings");
 +      RNA_def_property_struct_type(prop, "ColorManagedDisplaySettings");
 +      RNA_def_property_ui_text(prop, "Display Settings", "Settings of device saved image would be displayed on");
  }
  
  static void rna_def_scene_ffmpeg_settings(BlenderRNA *brna)
index 1db3e9678a4efebdc50167e10913ba9fceea3e39,b09227a9461e72588180b889f7afaaaeacda9b53..3aa0e7f5260603afad598d04020e0d494c929e8b
@@@ -152,7 -152,6 +152,7 @@@ EnumPropertyItem clip_editor_mode_items
  #include "ED_sequencer.h"
  #include "ED_clip.h"
  
 +#include "IMB_colormanagement.h"
  #include "IMB_imbuf_types.h"
  
  static StructRNA *rna_Space_refine(struct PointerRNA *ptr)
@@@ -1909,7 -1908,7 +1909,7 @@@ static void rna_def_space_buttons(Blend
                {SB_TEXC_MAT_OR_LAMP, "MATERIAL", ICON_MATERIAL, "Material", "Material"},
                {0, NULL, 0, NULL, NULL}
        };                             /*actually populated dynamically trough a function */
 -              
 +
        srna = RNA_def_struct(brna, "SpaceProperties", "Space");
        RNA_def_struct_sdna(srna, "SpaceButs");
        RNA_def_struct_ui_text(srna, "Properties Space", "Properties space data");
@@@ -2086,11 -2085,6 +2086,11 @@@ static void rna_def_space_image(Blender
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Show UV Editor", "Show UV editing related properties");
  
 +      prop = RNA_def_property(srna, "view_settings", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_pointer_sdna(prop, NULL, "view_settings");
 +      RNA_def_property_struct_type(prop, "ColorManagedViewSettings");
 +      RNA_def_property_ui_text(prop, "View Settings", "Color management settings used for displaying images on the display");
 +
        prop = RNA_def_property(srna, "show_maskedit", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_funcs(prop, "rna_SpaceImageEditor_show_maskedit_get", NULL);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
@@@ -2210,11 -2204,6 +2210,11 @@@ static void rna_def_space_sequencer(Ble
        RNA_def_property_struct_type(prop, "GreasePencil");
        RNA_def_property_ui_text(prop, "Grease Pencil", "Grease pencil data for this space");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SEQUENCER, NULL);
 +
 +      prop = RNA_def_property(srna, "view_settings", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_pointer_sdna(prop, NULL, "view_settings");
 +      RNA_def_property_struct_type(prop, "ColorManagedViewSettings");
 +      RNA_def_property_ui_text(prop, "View Settings", "Color management settings used for displaying images on the display");
  }
  
  static void rna_def_space_text(BlenderRNA *brna)
@@@ -2972,9 -2961,14 +2972,14 @@@ static void rna_def_space_node(BlenderR
        RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
        RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_SpaceNodeEditor_node_tree_poll");
        RNA_def_property_flag(prop, PROP_EDITABLE);
-       RNA_def_property_ui_text(prop, "Node Tree", "Node tree being displayed and edited");
+       RNA_def_property_ui_text(prop, "Node Tree", "Node tree being displayed");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE, "rna_SpaceNodeEditor_node_tree_update");
  
+       prop = RNA_def_property(srna, "edit_tree", PROP_POINTER, PROP_NONE);
+       RNA_def_property_pointer_sdna(prop, NULL, "edittree");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Edit Tree", "Edited node tree");
        prop = RNA_def_property(srna, "show_backdrop", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", SNODE_BACKDRAW);
        RNA_def_property_ui_text(prop, "Backdrop", "Use active Viewer Node output as backdrop for compositing nodes");
        RNA_def_property_ui_text(prop, "Draw Channels", "Channels of the image to draw");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL);
  
 +      prop = RNA_def_property(srna, "view_settings", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_pointer_sdna(prop, NULL, "view_settings");
 +      RNA_def_property_struct_type(prop, "ColorManagedViewSettings");
 +      RNA_def_property_ui_text(prop, "View Settings", "Color management settings used for displaying images on the display");
 +
        prop = RNA_def_property(srna, "show_highlight", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", SNODE_SHOW_HIGHLIGHT);
        RNA_def_property_ui_text(prop, "Highlight", "Highlight nodes that are being calculated");
        RNA_def_property_boolean_sdna(prop, NULL, "flag", SNODE_USE_HIDDEN_PREVIEW);
        RNA_def_property_ui_text(prop, "Hide Preview", "Hide preview for newly creating nodes");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL);
+       /* the mx/my "cursor" in the node editor is used only by operators to store the mouse position */
+       prop = RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "mx");
+       RNA_def_property_array(prop, 2);
+       RNA_def_property_ui_text(prop, "Cursor Location", "Location for adding new nodes");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL);
  }
  
  static void rna_def_space_logic(BlenderRNA *brna)
@@@ -3331,12 -3327,6 +3343,12 @@@ static void rna_def_space_clip(BlenderR
        RNA_def_property_enum_items(prop, pivot_items);
        RNA_def_property_ui_text(prop, "Pivot Point", "Pivot center for rotation/scaling");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_CLIP, NULL);
 +
 +      /* color management view settings */
 +      prop = RNA_def_property(srna, "view_settings", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_pointer_sdna(prop, NULL, "view_settings");
 +      RNA_def_property_struct_type(prop, "ColorManagedViewSettings");
 +      RNA_def_property_ui_text(prop, "View Settings", "Color management settings used for displaying images on the display");
  }
  
  
index 7e093c230bf1474b5c002e00ed614b0119fefde5,d4bdf0633f00dd115d7fc185618a972df25d71e3..d74014b1334dd6dd2ebd131bad19aeb8a2019803
@@@ -67,7 -67,6 +67,7 @@@
  #include "BLI_callbacks.h"
  
  #include "PIL_time.h"
 +#include "IMB_colormanagement.h"
  #include "IMB_imbuf.h"
  #include "IMB_imbuf_types.h"
  
@@@ -641,7 -640,7 +641,7 @@@ static void *do_part_thread(void *pa_v
                if (!R.sss_points && (R.r.scemode & R_FULL_SAMPLE))
                        pa->result = render_result_new_full_sample(&R, &pa->fullresult, &pa->disprect, pa->crop, RR_USE_MEM);
                else
 -                      pa->result = render_result_new(&R, &pa->disprect, pa->crop, RR_USE_MEM);
 +                      pa->result = render_result_new(&R, &pa->disprect, pa->crop, RR_USE_MEM, RR_ALL_LAYERS);
  
                if (R.sss_points)
                        zbufshade_sss_tile(pa);
                        zbufshade_tile(pa);
                
                /* merge too on break! */
 -              if (R.result->exrhandle) {
 +              if (R.result->do_exr_tile) {
                        render_result_exr_file_merge(R.result, pa->result);
                }
                else if (render_display_draw_enabled(&R)) {
@@@ -795,12 -794,12 +795,12 @@@ static void threaded_tile_processor(Ren
                render_result_free(re->result);
        
                if (re->sss_points && render_display_draw_enabled(re))
 -                      re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM);
 +                      re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS);
                else if (re->r.scemode & R_FULL_SAMPLE)
                        re->result = render_result_new_full_sample(re, &re->fullresult, &re->disprect, 0, RR_USE_EXR);
                else
                        re->result = render_result_new(re, &re->disprect, 0,
 -                                                     (re->r.scemode & R_EXR_TILE_FILE) ? RR_USE_EXR : RR_USE_MEM);
 +                                                     (re->r.scemode & R_EXR_TILE_FILE) ? RR_USE_EXR : RR_USE_MEM, RR_ALL_LAYERS);
        }
  
        BLI_rw_mutex_unlock(&re->resultmutex);
        
        /* warning; no return here without closing exr file */
        
 -      initparts(re);
 +      initparts(re, TRUE);
  
 -      if (re->result->exrhandle)
 +      if (re->result->do_exr_tile)
                render_result_exr_file_begin(re);
        
        BLI_init_threads(&threads, do_part_thread, re->r.threads);
                
        }
        
 -      if (re->result->exrhandle) {
 +      if (re->result->do_exr_tile) {
                BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
                render_result_exr_file_end(re);
                BLI_rw_mutex_unlock(&re->resultmutex);
@@@ -1045,7 -1044,7 +1045,7 @@@ static void do_render_blur_3d(Render *r
        int blur = re->r.mblur_samples;
        
        /* create accumulation render result */
 -      rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM);
 +      rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS);
        
        /* do the blur steps */
        while (blur--) {
@@@ -1170,7 -1169,7 +1170,7 @@@ static void do_render_fields_3d(Render 
        re->disprect.ymax *= 2;
  
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
 -      re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM);
 +      re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS);
  
        if (rr2) {
                if (re->r.mode & R_ODDFIELD)
@@@ -1233,7 -1232,7 +1233,7 @@@ static void do_render_fields_blur_3d(Re
                                re->rectx = re->winx;
                                re->recty = re->winy;
                                
 -                              rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM);
 +                              rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS);
                                
                                render_result_merge(rres, re->result);
                                render_result_free(re->result);
@@@ -1553,7 -1552,7 +1553,7 @@@ static void do_render_composite_fields_
                BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
                
                render_result_free(re->result);
 -              re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM);
 +              re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS);
  
                BLI_rw_mutex_unlock(&re->resultmutex);
                
@@@ -1664,17 -1663,17 +1664,17 @@@ static void do_render_seq(Render *re
        if ((re->r.mode & R_BORDER) && (re->r.mode & R_CROP) == 0) {
                /* if border rendering is used and cropping is disabled, final buffer should
                 * be as large as the whole frame */
-               context = seq_new_render_data(re->main, re->scene,
+               context = BKE_sequencer_new_render_data(re->main, re->scene,
                                              re->winx, re->winy,
                                              100);
        }
        else {
-               context = seq_new_render_data(re->main, re->scene,
+               context = BKE_sequencer_new_render_data(re->main, re->scene,
                                              re->result->rectx, re->result->recty,
                                              100);
        }
  
-       ibuf = give_ibuf_seq(context, cfra, 0);
+       ibuf = BKE_sequencer_give_ibuf(context, cfra, 0);
  
        recurs_depth--;
  
                if (recurs_depth == 0) { /* with nested scenes, only free on toplevel... */
                        Editing *ed = re->scene->ed;
                        if (ed)
-                               free_imbuf_seq(re->scene, &ed->seqbase, TRUE, TRUE);
+                               BKE_sequencer_free_imbuf(re->scene, &ed->seqbase, TRUE, TRUE);
                }
                IMB_freeImBuf(ibuf);
        }
@@@ -1848,7 -1847,7 +1848,7 @@@ int RE_is_rendering_allowed(Scene *scen
        if (scene->r.scemode & (R_EXR_TILE_FILE | R_FULL_SAMPLE)) {
                char str[FILE_MAX];
                
 -              render_result_exr_file_path(scene, 0, str);
 +              render_result_exr_file_path(scene, "", 0, str);
                
                if (BLI_file_is_writable(str) == 0) {
                        BKE_report(reports, RPT_ERROR, "Can not save render buffers, check the temp default path");
@@@ -1932,7 -1931,7 +1932,7 @@@ static void validate_render_settings(Re
  
        if (RE_engine_is_external(re)) {
                /* not supported yet */
 -              re->r.scemode &= ~(R_EXR_TILE_FILE | R_FULL_SAMPLE);
 +              re->r.scemode &= ~(R_FULL_SAMPLE);
                re->r.mode &= ~(R_FIELDS | R_MBLUR);
        }
  }
@@@ -2069,15 -2068,6 +2069,15 @@@ void RE_BlenderFrame(Render *re, Main *
        G.rendering = 0;
  }
  
 +static void colormanage_image_for_write(Scene *scene, ImBuf *ibuf)
 +{
 +      IMB_display_buffer_to_imbuf_rect(ibuf, &scene->r.im_format.view_settings,
 +                                       &scene->r.im_format.display_settings);
 +
 +      if (ibuf)
 +              imb_freerectfloatImBuf(ibuf);
 +}
 +
  static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovieHandle *mh, const char *name_override)
  {
        char name[FILE_MAX];
        /* write movie or image */
        if (BKE_imtype_is_movie(scene->r.im_format.imtype)) {
                int do_free = FALSE;
 -              unsigned int *rect32 = (unsigned int *)rres.rect32;
 +              ImBuf *ibuf = render_result_rect_to_ibuf(&rres, &scene->r);
 +
                /* note; the way it gets 32 bits rects is weak... */
 -              if (rres.rect32 == NULL) {
 -                      rect32 = MEM_mapallocN(sizeof(int) * rres.rectx * rres.recty, "temp 32 bits rect");
 -                      RE_ResultGet32(re, rect32);
 +              if (ibuf->rect == NULL) {
 +                      ibuf->rect = MEM_mapallocN(sizeof(int) * rres.rectx * rres.recty, "temp 32 bits rect");
 +                      RE_ResultGet32(re, ibuf->rect);
                        do_free = TRUE;
                }
  
 -              ok = mh->append_movie(&re->r, scene->r.sfra, scene->r.cfra, (int *)rect32,
 -                                    rres.rectx, rres.recty, re->reports);
 +              colormanage_image_for_write(scene, ibuf);
 +
 +              ok = mh->append_movie(&re->r, scene->r.sfra, scene->r.cfra, (int *) ibuf->rect,
 +                                    ibuf->x, ibuf->y, re->reports);
                if (do_free) {
 -                      MEM_freeN(rect32);
 +                      MEM_freeN(ibuf->rect);
 +                      ibuf->rect = NULL;
                }
 +
 +              /* imbuf knows which rects are not part of ibuf */
 +              IMB_freeImBuf(ibuf);
 +
                printf("Append frame %d", scene->r.cfra);
        } 
        else {
                }
                else {
                        ImBuf *ibuf = render_result_rect_to_ibuf(&rres, &scene->r);
 +                      int do_colormanagement;
 +
 +                      do_colormanagement = !BKE_imtype_supports_float(scene->r.im_format.imtype);
 +
 +                      if (do_colormanagement)
 +                              colormanage_image_for_write(scene, ibuf);
  
                        ok = BKE_imbuf_write_stamp(scene, camera, ibuf, name, &scene->r.im_format);
                        
                                        name[strlen(name) - 4] = 0;
                                BKE_add_image_extension(name, R_IMF_IMTYPE_JPEG90);
                                ibuf->planes = 24;
 +
 +                              colormanage_image_for_write(scene, ibuf);
 +
                                BKE_imbuf_write_stamp(scene, camera, ibuf, name, &imf);
                                printf("\nSaved: %s", name);
                        }
@@@ -2447,7 -2420,7 +2447,7 @@@ void RE_layer_load_from_file(RenderLaye
  
  void RE_result_load_from_file(RenderResult *result, ReportList *reports, const char *filename)
  {
 -      if (!render_result_exr_file_read_path(result, filename)) {
 +      if (!render_result_exr_file_read_path(result, NULL, filename)) {
                BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename);
                return;
        }
index c1bc8912425be3c2e4f9ac2908b57068cd0158c8,5bdf59f37c8a82d9b3b56ac002ef9cbe0d566c0c..60f8b3d946622dd73b2ee92a718b486835f3cecb
@@@ -67,6 -67,7 +67,6 @@@
  #include "BKE_tracking.h" /* free tracking clipboard */
  
  #include "BLI_listbase.h"
 -#include "BLI_math_color.h"
  #include "BLI_string.h"
  #include "BLI_utildefines.h"
  
  #include "BKE_depsgraph.h"
  #include "BKE_sound.h"
  
 +#include "IMB_colormanagement.h"
 +
  static void wm_init_reports(bContext *C)
  {
        BKE_reports_init(CTX_wm_reports(C), RPT_STORE);
@@@ -149,8 -148,8 +149,8 @@@ void WM_init(bContext *C, int argc, con
        BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */
        BLF_lang_init();
  
 -      /* initialize color stuff */
 -      BLI_init_srgb_conversion();
 +      /* initialize color management stuff */
 +      IMB_colormanagement_init();
  
        /* get the default database, plus a wm */
        WM_read_homefile(C, NULL, G.factory_startup);
@@@ -372,7 -371,6 +372,7 @@@ void WM_exit_ext(bContext *C, const sho
  
        sound_exit();
  
 +      IMB_colormanagement_exit();
  
        /* first wrap up running stuff, we assume only the active WM is running */
        /* modal handlers are on window level freed, others too? */
        if (C && CTX_wm_manager(C))
                wm_free_reports(C);  /* before free_blender! - since the ListBases get freed there */
  
-       seq_free_clipboard(); /* sequencer.c */
+       BKE_sequencer_free_clipboard(); /* sequencer.c */
        BKE_tracking_clipboard_free();
                
        free_blender();  /* blender.c, does entire library and spacetypes */
index ec3d32f9eecb7e1a9b309d81d5fc3cbf262b5b74,9ae2cb0c3531d61ad3fad4a6ab915514ea2f9834..a95e1422bed6ab868ecd44ea704b472fcc2e7932
@@@ -96,6 -96,7 +96,7 @@@ struct Tex
  struct TexResult;
  struct Text;
  struct ToolSettings;
+ struct View2D;
  struct View3D;
  struct bAction;
  struct bArmature;
@@@ -212,6 -213,9 +213,9 @@@ void *ED_region_draw_cb_activate(struc
  void *ED_region_draw_cb_customdata(void *handle) {return 0;} /* XXX This one looks wrong also */
  void ED_region_draw_cb_exit(struct ARegionType *art, void *handle) {}
  void  ED_area_headerprint(struct ScrArea *sa, char *str) {}
+ void UI_view2d_region_to_view(struct View2D *v2d, int x, int y, float *viewx, float *viewy) {}
+ void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, int *regionx, int *regiony) {}
+ void UI_view2d_to_region_no_clip(struct View2D *v2d, float x, float y, int *regionx, int *region_y) {}
  
  struct EditBone *ED_armature_bone_get_mirrored(struct ListBase *edbo, struct EditBone *ebo) {return (struct EditBone *) NULL;}
  struct EditBone *ED_armature_edit_bone_add(struct bArmature *arm, char *name) {return (struct EditBone*) NULL;}
@@@ -424,8 -428,6 +428,8 @@@ void uiTemplateMovieClip(struct uiLayou
  void uiTemplateTrack(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname) {}
  void uiTemplateMarker(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname, PointerRNA *userptr, PointerRNA *trackptr, int compact) {}
  void uiTemplateImageSettings(struct uiLayout *layout, struct PointerRNA *imfptr) {}
 +void uiTemplateColorspaceSettings(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname) {}
 +void uiTemplateColormanagedViewSettings(struct uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, int show_global_settings) {}
  
  /* rna render */
  struct RenderResult *RE_engine_begin_result(struct RenderEngine *engine, int x, int y, int w, int h) {return (struct RenderResult *) NULL;}