svn merge ^/trunk/blender -r49186:49190
authorCampbell Barton <ideasman42@gmail.com>
Wed, 25 Jul 2012 09:06:44 +0000 (09:06 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 25 Jul 2012 09:06:44 +0000 (09:06 +0000)
1  2 
source/blender/editors/interface/interface_templates.c
source/blender/editors/space_image/image_ops.c

index a87fc76d9d8e57733ef11a4873bfb6d5c53f2165,63b201e4cf76c258d317283dfcd9c6ec03b8f53d..613d74e309b50d6c3c59435bfc175b9fd97e917e
@@@ -254,7 -254,7 +254,7 @@@ static void template_id_cb(bContext *C
                        break;
                case UI_ID_OPEN:
                case UI_ID_ADD_NEW:
-                       /* these call uiIDContextPropertySet */
+                       /* these call uiIDContextProperty */
                        break;
                case UI_ID_DELETE:
                        memset(&idptr, 0, sizeof(idptr));
@@@ -2768,66 -2768,3 +2768,66 @@@ void uiTemplateKeymapItemProperties(uiL
        }
  }
  
 +/********************************* Color management *************************************/
 +
 +void uiTemplateColorspaceSettings(uiLayout *layout, PointerRNA *ptr, const char *propname)
 +{
 +      PropertyRNA *prop;
 +      PointerRNA colorspace_settings_ptr;
 +
 +      prop = RNA_struct_find_property(ptr, propname);
 +
 +      if (!prop) {
 +              printf("%s: property not found: %s.%s\n",
 +                     __func__, RNA_struct_identifier(ptr->type), propname);
 +              return;
 +      }
 +
 +      colorspace_settings_ptr = RNA_property_pointer_get(ptr, prop);
 +
 +      uiItemL(layout, "Color Space:", ICON_NONE);
 +      uiItemR(layout, &colorspace_settings_ptr, "name", 0, "", ICON_NONE);
 +}
 +
 +void uiTemplateColormanagedViewSettings(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, int show_global_settings)
 +{
 +      PropertyRNA *prop;
 +      PointerRNA view_transform_ptr;
 +      uiLayout *col;
 +      ColorManagedViewSettings *view_settings;
 +
 +      prop = RNA_struct_find_property(ptr, propname);
 +
 +      if (!prop) {
 +              printf("%s: property not found: %s.%s\n",
 +                     __func__, RNA_struct_identifier(ptr->type), propname);
 +              return;
 +      }
 +
 +      view_transform_ptr = RNA_property_pointer_get(ptr, prop);
 +      view_settings = view_transform_ptr.data;
 +
 +      col = uiLayoutColumn(layout, FALSE);
 +
 +      if (show_global_settings) {
 +              wmWindow *win = CTX_wm_window(C);
 +              bScreen *screen = CTX_wm_screen(C);
 +
 +              uiItemR(col, &view_transform_ptr, "use_global_settings", 0, NULL, ICON_NONE);
 +
 +              if (view_settings->flag & COLORMANAGE_VIEW_USE_GLOBAL) {
 +                      PointerRNA window_ptr;
 +
 +                      RNA_pointer_create(&screen->id, &RNA_Window, win, &window_ptr);
 +
 +                      prop = RNA_struct_find_property(&window_ptr, "view_settings");
 +                      view_transform_ptr = RNA_property_pointer_get(&window_ptr, prop);
 +              }
 +      }
 +
 +      uiItemR(col, &view_transform_ptr, "view_transform", 0, "View", ICON_NONE);
 +
 +      col = uiLayoutColumn(layout, FALSE);
 +      uiItemR(col, &view_transform_ptr, "exposure", 0, NULL, ICON_NONE);
 +      uiItemR(col, &view_transform_ptr, "gamma", 0, NULL, ICON_NONE);
 +}
index 42af515983ab34d7b2d44fe0f498b7279c0bcddc,7d1328ca2667a207944d1196c5552ba2e7f4ca8e..8885b30842b69510b12cc5ef2f3c1715baf4040a
@@@ -55,7 -55,6 +55,7 @@@
  #include "BKE_report.h"
  #include "BKE_screen.h"
  
 +#include "IMB_colormanagement.h"
  #include "IMB_imbuf.h"
  #include "IMB_imbuf_types.h"
  
@@@ -902,6 -901,25 +902,25 @@@ static int image_open_invoke(bContext *
                        ima = tex->ima;
        }
  
+       if (ima == NULL) {
+               PointerRNA ptr;
+               PropertyRNA *prop;
+               /* hook into UI */
+               uiIDContextProperty(C, &ptr, &prop);
+               if (prop) {
+                       PointerRNA oldptr;
+                       oldptr = RNA_property_pointer_get(&ptr, prop);
+                       ima = (Image *)oldptr.id.data;
+                       /* unlikely but better avoid strange crash */
+                       if (ima && GS(ima->id.name) != ID_IM) {
+                               ima = NULL;
+                       }
+               }
+       }
        if (ima)
                path = ima->name;
  
@@@ -1083,14 -1101,12 +1102,14 @@@ static char imtype_best_depth(ImBuf *ib
        }
  }
  
 -static int save_image_options_init(SaveImageOptions *simopts, SpaceImage *sima, Scene *scene, const short guess_path)
 +static int save_image_options_init(bContext *C, SaveImageOptions *simopts, SpaceImage *sima, Scene *scene, const short guess_path)
  {
        void *lock;
        ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
  
        if (ibuf) {
 +              wmWindow *win = CTX_wm_window(C);
 +              const ColorManagedViewSettings *view_settings;
                Image *ima = sima->image;
                short is_depth_set = FALSE;
  
                        }
                        BLI_path_abs(simopts->filepath, G.main->name);
                }
 +
 +              /* color management */
 +              view_settings = IMB_view_settings_get_effective(win, &sima->view_settings);
 +
 +              BKE_color_managed_display_settings_copy(&simopts->im_format.display_settings, &win->display_settings);
 +              BKE_color_managed_view_settings_copy(&simopts->im_format.view_settings, view_settings);
        }
  
        ED_space_image_release_buffer(sima, lock);
@@@ -1173,38 -1183,6 +1192,38 @@@ static void save_image_options_to_op(Sa
        RNA_string_set(op->ptr, "filepath", simopts->filepath);
  }
  
 +static ImBuf *save_image_colormanaged_imbuf_acquire(ImBuf *ibuf, SaveImageOptions *simopts, void **cache_handle)
 +{
 +      ImageFormatData *imf = &simopts->im_format;
 +      ImBuf *colormanaged_ibuf;
 +      int do_colormanagement;
 +
 +      *cache_handle = NULL;
 +      do_colormanagement = !BKE_imtype_supports_float(imf->imtype);
 +
 +      if (do_colormanagement) {
 +              unsigned char *display_buffer =
 +                      IMB_display_buffer_acquire(ibuf, &imf->view_settings, &imf->display_settings, cache_handle);
 +
 +              if (*cache_handle) {
 +                      colormanaged_ibuf = IMB_allocImBuf(ibuf->x, ibuf->y, ibuf->planes, 0);
 +                      colormanaged_ibuf->rect = (unsigned int *) display_buffer;
 +              }
 +              else {
 +                      /* no cache handle means color management didn't run transformation
 +                       * or performed transformation to image's byte buffer which doesn't
 +                       * require allocating new image buffer
 +                       */
 +                      colormanaged_ibuf = ibuf;
 +              }
 +      }
 +      else {
 +              colormanaged_ibuf = ibuf;
 +      }
 +
 +      return colormanaged_ibuf;
 +}
 +
  /* assumes name is FILE_MAX */
  /* ima->name and ibuf->name should end up the same */
  static void save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveImageOptions *simopts, int do_newpath)
        ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
  
        if (ibuf) {
 +              void *cache_handle;
 +              ImBuf *colormanaged_ibuf;
                const char *relbase = ID_BLEND_PATH(CTX_data_main(C), &ima->id);
                const short relative = (RNA_struct_find_property(op->ptr, "relative_path") && RNA_boolean_get(op->ptr, "relative_path"));
                const short save_copy = (RNA_struct_find_property(op->ptr, "copy") && RNA_boolean_get(op->ptr, "copy"));
                                ibuf->planes = BKE_imbuf_alpha_test(ibuf) ? 32 : 24;
                        }
                }
 -              
 +
 +              colormanaged_ibuf = save_image_colormanaged_imbuf_acquire(ibuf, simopts, &cache_handle);
 +
                if (simopts->im_format.imtype == R_IMF_IMTYPE_MULTILAYER) {
                        Scene *scene = CTX_data_scene(C);
                        RenderResult *rr = BKE_image_acquire_renderresult(scene, ima);
                        BKE_image_release_renderresult(scene, ima);
                }
                else {
 -                      if (BKE_imbuf_write_as(ibuf, simopts->filepath, &simopts->im_format, save_copy)) {
 +                      if (BKE_imbuf_write_as(colormanaged_ibuf, simopts->filepath, &simopts->im_format, save_copy)) {
                                ok = TRUE;
                        }
                }
                WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, sima->image);
  
                WM_cursor_wait(0);
 +
 +              if (cache_handle) {
 +                      colormanaged_ibuf->rect = NULL;
 +                      IMB_freeImBuf(colormanaged_ibuf);
 +
 +                      IMB_display_buffer_release(cache_handle);
 +              }
        }
  
        ED_space_image_release_buffer(sima, lock);
@@@ -1336,7 -1303,7 +1355,7 @@@ static int image_save_as_exec(bContext 
  
        /* just in case to initialize values,
         * these should be set on invoke or by the caller. */
 -      save_image_options_init(&simopts, sima, CTX_data_scene(C), 0);
 +      save_image_options_init(C, &simopts, sima, CTX_data_scene(C), 0);
  
        save_image_options_from_op(&simopts, op);
  
@@@ -1365,7 -1332,7 +1384,7 @@@ static int image_save_as_invoke(bContex
  
        save_image_options_defaults(&simopts);
  
 -      if (save_image_options_init(&simopts, sima, scene, TRUE) == 0)
 +      if (save_image_options_init(C, &simopts, sima, scene, TRUE) == 0)
                return OPERATOR_CANCELLED;
        save_image_options_to_op(&simopts, op);
  
@@@ -1450,7 -1417,7 +1469,7 @@@ static int image_save_exec(bContext *C
        Scene *scene = CTX_data_scene(C);
        SaveImageOptions simopts;
  
 -      if (save_image_options_init(&simopts, sima, scene, FALSE) == 0)
 +      if (save_image_options_init(C, &simopts, sima, scene, FALSE) == 0)
                return OPERATOR_CANCELLED;
        save_image_options_from_op(&simopts, op);