svn merge ^/trunk/blender -r49854:49867
authorCampbell Barton <ideasman42@gmail.com>
Mon, 13 Aug 2012 09:35:11 +0000 (09:35 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 13 Aug 2012 09:35:11 +0000 (09:35 +0000)
1  2 
source/blender/blenkernel/intern/image.c
source/blender/editors/space_node/node_draw.c
source/blender/imbuf/IMB_imbuf.h
source/blender/imbuf/intern/divers.c
source/blender/makesdna/DNA_node_types.h

index cf25a0090a43c73290d0bc8a50fa4d1c2a485d65,5f6fedc553c0a34e22763314b293535fc7f2cfaa..8042c4d2807e3f34f8f8b54648d21559dab9e1c8
@@@ -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 */
@@@ -1496,6 -1476,10 +1496,10 @@@ void BKE_stamp_buf(Scene *scene, Objec
        float h_fixed;
        const int mono = blf_mono_font_render; // XXX
  
+       /* this could be an argument if we want to operate on non linear float imbuf's
+        * for now though this is only used for renders which use scene settings */
+       const int do_color_management = (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) != 0;
  #define BUFF_MARGIN_X 2
  #define BUFF_MARGIN_Y 1
  
        /* set before return */
        BLF_size(mono, scene->r.stamp_font_id, 72);
  
-       BLF_buffer(mono, rectf, rect, width, height, channels);
+       BLF_buffer(mono, rectf, rect, width, height, channels, do_color_management);
        BLF_buffer_col(mono, scene->r.fg_stamp[0], scene->r.fg_stamp[1], scene->r.fg_stamp[2], 1.0);
        pad = BLF_width_max(mono);
  
                y -= h;
  
                /* also a little of space to the background. */
-               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
+               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
+                                                 x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
  
                /* and draw the text. */
                BLF_position(mono, x, y + y_ofs, 0.0);
                y -= h;
  
                /* and space for background. */
-               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
+               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
+                                                 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
  
                BLF_position(mono, x, y + y_ofs, 0.0);
                BLF_draw_buffer(mono, stamp_data.note);
                y -= h;
  
                /* and space for background. */
-               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
+               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
+                                                 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
  
                BLF_position(mono, x, y + y_ofs, 0.0);
                BLF_draw_buffer(mono, stamp_data.date);
                y -= h;
  
                /* and space for background. */
-               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
+               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
+                                                 0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
  
                BLF_position(mono, x, y + y_ofs, 0.0);
                BLF_draw_buffer(mono, stamp_data.rendertime);
                BLF_width_and_height(mono, stamp_data.marker, &w, &h); h = h_fixed;
  
                /* extra space for background. */
-               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
+               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp,  do_color_management,
+                                                 x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
  
                /* and pad the text. */
                BLF_position(mono, x, y + y_ofs, 0.0);
                BLF_width_and_height(mono, stamp_data.time, &w, &h); h = h_fixed;
  
                /* extra space for background */
-               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
+               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
+                                                 x - BUFF_MARGIN_X, y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
  
                /* and pad the text. */
                BLF_position(mono, x, y + y_ofs, 0.0);
                BLF_width_and_height(mono, stamp_data.frame, &w, &h); h = h_fixed;
  
                /* extra space for background. */
-               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
+               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
+                                                 x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
  
                /* and pad the text. */
                BLF_position(mono, x, y + y_ofs, 0.0);
                BLF_width_and_height(mono, stamp_data.camera, &w, &h); h = h_fixed;
  
                /* extra space for background. */
-               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
+               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
+                                                 x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
                BLF_position(mono, x, y + y_ofs, 0.0);
                BLF_draw_buffer(mono, stamp_data.camera);
  
                BLF_width_and_height(mono, stamp_data.cameralens, &w, &h); h = h_fixed;
  
                /* extra space for background. */
-               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
+               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
+                                                 x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
                BLF_position(mono, x, y + y_ofs, 0.0);
                BLF_draw_buffer(mono, stamp_data.cameralens);
        }
                x = width - w - 2;
  
                /* extra space for background. */
-               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
+               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
+                                                 x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
  
                /* and pad the text. */
                BLF_position(mono, x, y + y_ofs, 0.0);
                y = height - h;
  
                /* extra space for background. */
-               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
+               buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
+                                                 x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
  
                BLF_position(mono, x, y + y_ofs, 0.0);
                BLF_draw_buffer(mono, stamp_data.strip);
        }
  
        /* cleanup the buffer. */
-       BLF_buffer(mono, NULL, NULL, 0, 0, 0);
+       BLF_buffer(mono, NULL, NULL, 0, 0, 0, FALSE);
  
  #undef BUFF_MARGIN_X
  #undef BUFF_MARGIN_Y
@@@ -2193,9 -2188,6 +2208,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 -2555,13 +2578,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 57b08de2d71621ca56cac96cfaeda83052c40fc2,1a4c302124ff320ff1f8036410ffd264b8645440..643ac177933640150da048d60ed1322af05a834f
@@@ -1039,6 -1039,8 +1039,8 @@@ static void node_draw(const bContext *C
                node->typeinfo->drawfunc(C, ar, snode, ntree, node);
  }
  
+ #define USE_DRAW_TOT_UPDATE
  void node_draw_nodetree(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree)
  {
        bNode *node;
        int a;
        
        if (ntree == NULL) return;      /* groups... */
-       
+ #ifdef USE_DRAW_TOT_UPDATE
+       if (ntree->nodes.first) {
+               BLI_rctf_init_minmax(&ar->v2d.tot);
+       }
+ #endif
        /* draw background nodes, last nodes in front */
        for (a = 0, node = ntree->nodes.first; node; node = node->next, a++) {
+ #ifdef USE_DRAW_TOT_UPDATE
+               /* unrelated to background nodes, update the v2d->tot,
+                * can be anywhere before we draw the scroll bars */
+               BLI_rctf_union(&ar->v2d.tot, &node->totr);
+ #endif
                if (!(node->flag & NODE_BACKGROUND))
                        continue;
                node->nr = a;        /* index of node in list, used for exec event code */
@@@ -1076,6 -1091,8 +1091,6 @@@ void drawnodespace(const bContext *C, A
  {
        View2DScrollers *scrollers;
        SpaceNode *snode = CTX_wm_space_node(C);
 -      Scene *scene = CTX_data_scene(C);
 -      int color_manage = scene->r.color_mgt_flag & R_COLOR_MANAGEMENT;
        bNodeLinkDrag *nldrag;
        LinkData *linkdata;
        
        UI_view2d_multi_grid_draw(v2d, 25.0f, 5, 2);
  
        /* backdrop */
 -      draw_nodespace_back_pix(ar, snode, color_manage);
 +      draw_nodespace_back_pix(C, ar, snode);
        
        /* nodes */
        snode_set_context(snode, CTX_data_scene(C));
index a2124ab9cde4ab3662763eaa149c3d012d014a90,738e61dbe6e0aaba9fc995d494b4ad95a24b96d8..f6dc6735567b1e7fb6f074e17cc6e79996be81de
@@@ -392,15 -392,6 +392,15 @@@ void IMB_buffer_byte_from_byte(unsigne
        int width, int height, int stride_to, int stride_from);
  void IMB_buffer_float_clamp(float *buf, int width, int height);
  
 +/* converting pixel buffers using tonecurve */
 +
 +typedef void (*imb_tonecurveCb) (float rgbOut[3], const float rgbIn[3]);
 +
 +void IMB_buffer_byte_from_float_tonecurve(unsigned char *rect_to, const float *rect_from,
 +                                          int channels_from, float dither, int profile_to, int profile_from, int predivide,
 +                                          int width, int height, int stride_to, int stride_from,
 +                                          imb_tonecurveCb tonecurve_func);
 +
  /**
   * Change the ordering of the color bytes pointed to by rect from
   * rgba to abgr. size * 4 color bytes are reordered.
@@@ -491,7 -482,9 +491,9 @@@ void IMB_rectfill_area(struct ImBuf *ib
  void IMB_rectfill_alpha(struct ImBuf *ibuf, const float value);
  
  /* this should not be here, really, we needed it for operating on render data, IMB_rectfill_area calls it */
- void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, const float col[4], int x1, int y1, int x2, int y2);
+ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height,
+                                          const float col[4], const int do_color_management,
+                                          int x1, int y1, int x2, int y2);
  
  /* defined in metadata.c */
  int IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field);
index 62d8d273fdd68a183a045289c06d3bedd5b42fc9,5ba08f1dd735741fd45f2bb3d8da4b23743c128c..581b55d4377e64efaac85d1afcf0819a0ca89d32
@@@ -31,8 -31,6 +31,6 @@@
   *  \ingroup imbuf
   */
  
- #include "BLI_blenlib.h"
  #include "BLI_rand.h"
  #include "BLI_math.h"
  #include "BLI_utildefines.h"
  #include "imbuf.h"
  #include "IMB_imbuf_types.h"
  #include "IMB_imbuf.h"
 +#include "IMB_filter.h"
  #include "IMB_allocimbuf.h"
  
  #include "MEM_guardedalloc.h"
  
 +#ifdef WITH_OCIO
 +#include <ocio_capi.h>
 +#endif
 +
  /**************************** Interlace/Deinterlace **************************/
  
  void IMB_de_interlace(ImBuf *ibuf)
@@@ -192,13 -185,11 +190,13 @@@ MINLINE void float_to_byte_dither_v4(uc
  }
  
  /* float to byte pixels, output 4-channel RGBA */
 -void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
 -                                int channels_from, float dither, int profile_to, int profile_from, int predivide,
 -                                int width, int height, int stride_to, int stride_from)
 +void IMB_buffer_byte_from_float_tonecurve(uchar *rect_to, const float *rect_from,
 +                                          int channels_from, float dither, int profile_to, int profile_from, int predivide,
 +                                          int width, int height, int stride_to, int stride_from,
 +                                          imb_tonecurveCb tonecurve_func)
  {
        float tmp[4];
 +      float corrected[4];
        int x, y;
        DitherContext *di;
  
        if (dither)
                di = create_dither_context(width, dither);
  
 +      if (!tonecurve_func)
 +              tonecurve_func = copy_v3_v3;
 +
        for (y = 0; y < height; y++) {
                if (channels_from == 1) {
                        /* single channel input */
                        else if (profile_to == IB_PROFILE_SRGB) {
                                /* convert from linear to sRGB */
                                for (x = 0; x < width; x++, from += 3, to += 4) {
 -                                      linearrgb_to_srgb_v3_v3(tmp, from);
 +                                      tonecurve_func(corrected, from);
 +                                      linearrgb_to_srgb_v3_v3(tmp, corrected);
                                        rgb_float_to_uchar(to, tmp);
                                        to[3] = 255;
                                }
  
                                if (dither && predivide) {
                                        for (x = 0; x < width; x++, from += 4, to += 4) {
 -                                              linearrgb_to_srgb_ushort4_predivide(us, from);
 +                                              tonecurve_func(corrected, from);
 +                                              corrected[3] = from[3];
 +
 +                                              linearrgb_to_srgb_ushort4_predivide(us, corrected);
                                                ushort_to_byte_dither_v4(to, us, di);
                                        }
                                }
                                else if (dither) {
                                        for (x = 0; x < width; x++, from += 4, to += 4) {
 -                                              linearrgb_to_srgb_ushort4(us, from);
 +                                              tonecurve_func(corrected, from);
 +                                              corrected[3] = from[3];
 +
 +                                              linearrgb_to_srgb_ushort4(us, corrected);
                                                ushort_to_byte_dither_v4(to, us, di);
                                        }
                                }
                                else if (predivide) {
                                        for (x = 0; x < width; x++, from += 4, to += 4) {
 -                                              linearrgb_to_srgb_ushort4_predivide(us, from);
 +                                              tonecurve_func(corrected, from);
 +                                              corrected[3] = from[3];
 +
 +                                              linearrgb_to_srgb_ushort4_predivide(us, corrected);
                                                ushort_to_byte_v4(to, us);
                                        }
                                }
                                else {
                                        for (x = 0; x < width; x++, from += 4, to += 4) {
 -                                              linearrgb_to_srgb_ushort4(us, from);
 +                                              tonecurve_func(corrected, from);
 +                                              corrected[3] = from[3];
 +
 +                                              linearrgb_to_srgb_ushort4(us, corrected);
                                                ushort_to_byte_v4(to, us);
                                        }
                                }
                clear_dither_context(di);
  }
  
 +void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
 +                                int channels_from, float dither, int profile_to, int profile_from, int predivide,
 +                                int width, int height, int stride_to, int stride_from)
 +{
 +      IMB_buffer_byte_from_float_tonecurve(rect_to, rect_from, channels_from, dither, profile_to, profile_from, predivide,
 +                                           width, height, stride_to, stride_from, NULL);
 +}
 +
 +
  /* byte to float pixels, input and output 4-channel RGBA  */
  void IMB_buffer_float_from_byte(float *rect_to, const uchar *rect_from,
                                  int profile_to, int profile_from, int predivide,
index 4776c975618a0c38cd8285b19df824da059bcc25,3f439454a97aad84ec1e79a7ff1e5f56a7e245be..54c1b1bb77322fe3f87cabdc211063e00f77d5d5
@@@ -168,7 -168,7 +168,7 @@@ typedef struct bNode 
        void *storage;                  /* custom data, must be struct, for storage in file */
        struct bNode *original; /* the original node in the tree (for localized tree) */
        
-       float locx, locy;               /* root offset for drawing */
+       float locx, locy;               /* root offset for drawing (parent space) */
        float width, height;    /* node custom width and height */
        float miniwidth;                /* node width if hidden */
        float offsetx, offsety; /* additional offset from loc */
  
        short need_exec, exec;  /* need_exec is set as UI execution event, exec is flag during exec */
        void *threaddata;               /* optional extra storage for use in thread (read only then!) */
-       rctf totr;                              /* entire boundbox */
+       rctf totr;                              /* entire boundbox (worldspace) */
        rctf butr;                              /* optional buttons area */
        rctf prvr;                              /* optional preview area */
        bNodePreview *preview;  /* optional preview image */
@@@ -611,10 -611,7 +611,10 @@@ typedef struct NodeTexSky 
  typedef struct NodeTexImage {
        NodeTexBase base;
        ImageUser iuser;
 -      int color_space, pad;
 +      int color_space;
 +      int projection;
 +      float projection_blend;
 +      int pad;
  } NodeTexImage;
  
  typedef struct NodeTexChecker {
  typedef struct NodeTexEnvironment {
        NodeTexBase base;
        ImageUser iuser;
 -      int color_space, projection;
 +      int color_space;
 +      int projection;
  } NodeTexEnvironment;
  
  typedef struct NodeTexGradient {
@@@ -765,10 -761,6 +765,10 @@@ typedef struct NodeTrackPosData 
  #define SHD_PROJ_EQUIRECTANGULAR      0
  #define SHD_PROJ_MIRROR_BALL          1
  
 +/* image texture */
 +#define SHD_PROJ_FLAT                         0
 +#define SHD_PROJ_BOX                          1
 +
  /* blur node */
  #define CMP_NODE_BLUR_ASPECT_NONE             0
  #define CMP_NODE_BLUR_ASPECT_Y                        1