svn merge ^/trunk/blender -r49947:49952
authorCampbell Barton <ideasman42@gmail.com>
Fri, 17 Aug 2012 13:04:23 +0000 (13:04 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 17 Aug 2012 13:04:23 +0000 (13:04 +0000)
1  2 
source/blender/editors/space_image/image_ops.c

index 0fb2892cf7edf21698994e925f6f1bc08296ca96,b969d898882daab0f7291379386fb7b0f23fb59a..439299ddcda0d5968f0488e5dea72818028b8209
@@@ -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"
  
@@@ -1115,14 -1114,12 +1115,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);
@@@ -1205,38 -1196,6 +1205,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);
@@@ -1368,7 -1316,7 +1368,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);
  
@@@ -1397,7 -1345,7 +1397,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);
  
@@@ -1483,7 -1431,7 +1483,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);
  
@@@ -2027,7 -1975,7 +2027,7 @@@ int ED_space_image_color_sample(SpaceIm
                if (ibuf->rect_float) {
                        fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
  
-                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
+                       if (ELEM(ibuf->profile, IB_PROFILE_LINEAR_RGB, IB_PROFILE_NONE)) {
                                linearrgb_to_srgb_v3_v3(r_col, fp);
                        }
                        else {
                }
                else if (ibuf->rect) {
                        cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
-                       r_col[0] = cp[0] / 255.0f;
-                       r_col[1] = cp[1] / 255.0f;
-                       r_col[2] = cp[2] / 255.0f;
+                       rgb_uchar_to_float(r_col, cp);
                        ret = TRUE;
                }
        }