Merging r49681 through r49707 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenkernel / intern / image.c
index 936ef9731282ea4c4f2b97944eca3404a28235f6..cdee0d98a2510359bcb313a19497fc36be130edb 100644 (file)
@@ -47,6 +47,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 
@@ -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"
@@ -244,6 +246,8 @@ static Image *image_alloc(const char *name, short source, short type)
 
                ima->source = source;
                ima->type = type;
+
+               BKE_color_managed_colorspace_settings_init(&ima->colorspace_settings);
        }
        return ima;
 }
@@ -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;
 }
 
@@ -1010,6 +1016,20 @@ int BKE_imtype_supports_quality(const char imtype)
        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 */
@@ -2173,6 +2193,9 @@ static void image_create_multilayer(Image *ima, ImBuf *ibuf, int framenr)
 /* 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));
@@ -2540,13 +2563,23 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
                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)
@@ -2571,6 +2604,8 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
                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;