Color Management: get rid of image buffer's profile flag
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 14 Sep 2012 14:37:19 +0000 (14:37 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 14 Sep 2012 14:37:19 +0000 (14:37 +0000)
Currently float buffers are always linear, space of byte buffer is defined by
rect_colorspace property.

Replaced logic of IMB_rect_from_float and IMB_float_from_rect to use this
assumptions (before it was special function used in some areas only, now it's
default behavior).

Almost all functions from ImBuf module which are actually used are got rid from
profile flag. Only remained issue is IMB_float_profile_ensure which only used by
CIneon/DPX exporter which is broken for a while already. Need to be fixed
separately.

This also fixed clone brush when cloning byte image on top of float, before
this result would be gamma-corrected twice.

38 files changed:
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/ocean.c
source/blender/blenkernel/intern/sequencer.c
source/blender/blenkernel/intern/tracking.c
source/blender/compositor/operations/COM_ImageOperation.cpp
source/blender/editors/render/render_opengl.c
source/blender/editors/render/render_preview.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/space_clip/clip_editor.c
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_node/node_view.c
source/blender/gpu/intern/gpu_draw.c
source/blender/imbuf/IMB_colormanagement.h
source/blender/imbuf/IMB_imbuf.h
source/blender/imbuf/IMB_imbuf_types.h
source/blender/imbuf/intern/IMB_colormanagement_intern.h
source/blender/imbuf/intern/allocimbuf.c
source/blender/imbuf/intern/anim_movie.c
source/blender/imbuf/intern/bmp.c
source/blender/imbuf/intern/colormanagement.c
source/blender/imbuf/intern/dds/dds_api.cpp
source/blender/imbuf/intern/divers.c
source/blender/imbuf/intern/iris.c
source/blender/imbuf/intern/jp2.c
source/blender/imbuf/intern/jpeg.c
source/blender/imbuf/intern/openexr/openexr_api.cpp
source/blender/imbuf/intern/png.c
source/blender/imbuf/intern/radiance_hdr.c
source/blender/imbuf/intern/readimage.c
source/blender/imbuf/intern/targa.c
source/blender/imbuf/intern/tiff.c
source/blender/nodes/composite/nodes/node_composite_image.c
source/blender/nodes/composite/nodes/node_composite_outputFile.c
source/blender/quicktime/apple/qtkit_import.m
source/blender/quicktime/apple/quicktime_import.c
source/blender/render/intern/source/envmap.c
source/blender/render/intern/source/render_result.c
source/blender/render/intern/source/rendercore.c

index ce3e99a..f08af55 100644 (file)
@@ -612,12 +612,10 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char
        if (floatbuf) {
                ibuf = IMB_allocImBuf(width, height, depth, IB_rectfloat);
                rect_float = ibuf->rect_float;
-               ibuf->profile = IB_PROFILE_LINEAR_RGB;
        }
        else {
                ibuf = IMB_allocImBuf(width, height, depth, IB_rect);
                rect = (unsigned char *)ibuf->rect;
-               ibuf->profile = IB_PROFILE_SRGB;
        }
 
        BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
@@ -2330,7 +2328,6 @@ static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int f
                        ibuf->flags |= IB_rectfloat;
                        ibuf->mall = IB_rectfloat;
                        ibuf->channels = rpass->channels;
-                       ibuf->profile = IB_PROFILE_LINEAR_RGB;
 
                        image_initialize_after_load(ima, ibuf);
                        image_assign_ibuf(ima, ibuf, iuser ? iuser->multi_index : 0, frame);
@@ -2481,7 +2478,6 @@ static ImBuf *image_get_ibuf_multilayer(Image *ima, ImageUser *iuser)
                        ibuf->rect_float = rpass->rect;
                        ibuf->flags |= IB_rectfloat;
                        ibuf->channels = rpass->channels;
-                       ibuf->profile = IB_PROFILE_LINEAR_RGB;
 
                        image_assign_ibuf(ima, ibuf, iuser ? iuser->multi_index : IMA_NO_INDEX, 0);
                }
@@ -2630,7 +2626,6 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
 
        BLI_unlock_thread(LOCK_COLORMANAGE);
 
-       ibuf->profile = IB_PROFILE_LINEAR_RGB;
        ibuf->dither = dither;
 
        if (iuser->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE) {
index 46b89f7..4f39219 100644 (file)
@@ -1173,8 +1173,6 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v
                ibuf_disp = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat);
                ibuf_normal = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat);
 
-               ibuf_disp->profile = ibuf_foam->profile = ibuf_normal->profile = IB_PROFILE_LINEAR_RGB;
-
                BKE_simulate_ocean(o, och->time[i], och->wave_scale, och->chop_amount);
 
                /* add new foam */
index 1d4efb0..20db9d5 100644 (file)
@@ -313,7 +313,6 @@ void BKE_sequencer_editing_free(Scene *scene)
 
 void BKE_sequencer_imbuf_assign_spaces(Scene *scene, ImBuf *ibuf)
 {
-       IMB_colormanagement_imbuf_assign_spaces(ibuf, NULL);
        IMB_colormanagement_imbuf_assign_float_space(ibuf, &scene->sequencer_colorspace_settings);
 }
 
@@ -335,7 +334,7 @@ void BKE_sequencer_imbuf_to_sequencer_space(Scene *scene, ImBuf *ibuf, int make_
                         * OCIO_TODO: would be nice to support direct single transform from byte to sequencer's
                         */
 
-                       IMB_colormanagement_imbuf_float_from_rect(ibuf);
+                       IMB_float_from_rect(ibuf);
                }
                else {
                        /* if there's only byte buffer in image it's already in compositor's working space,
@@ -352,12 +351,6 @@ void BKE_sequencer_imbuf_to_sequencer_space(Scene *scene, ImBuf *ibuf, int make_
 
                IMB_colormanagement_transform_threaded(ibuf->rect_float, ibuf->x, ibuf->y, ibuf->channels,
                                                       from_colorspace, to_colorspace, predivide);
-
-               ibuf->profile = IB_PROFILE_SRGB;
-       }
-       else {
-               /* if no color management enables fallback to legacy conversion */
-               IMB_convert_profile(ibuf, IB_PROFILE_NONE);
        }
 }
 
@@ -374,12 +367,6 @@ void BKE_sequencer_imbuf_from_sequencer_space(Scene *scene, ImBuf *ibuf)
 
                IMB_colormanagement_transform_threaded(ibuf->rect_float, ibuf->x, ibuf->y, ibuf->channels,
                                                       from_colorspace, to_colorspace, predivide);
-
-               ibuf->profile = IB_PROFILE_LINEAR_RGB;
-       }
-       else {
-               /* if no color management enables fallback to legacy conversion */
-               IMB_convert_profile(ibuf, IB_PROFILE_LINEAR_RGB);
        }
 }
 
@@ -2441,7 +2428,6 @@ static ImBuf *seq_render_scene_strip(SeqRenderData context, Sequence *seq, float
                        }
 
                        /* float buffers in the sequencer are not linear */
-                       ibuf->profile = IB_PROFILE_LINEAR_RGB;
                        BKE_sequencer_imbuf_to_sequencer_space(context.scene, ibuf, FALSE);
                }
                else if (rres.rect32) {
@@ -2549,8 +2535,7 @@ static ImBuf *do_render_strip_uncached(SeqRenderData context, Sequence *seq, flo
                                        imb_freerectImBuf(ibuf);
 
                                /* all sequencer color is done in SRGB space, linear gives odd crossfades */
-                               if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
-                                       BKE_sequencer_imbuf_to_sequencer_space(context.scene, ibuf, FALSE);
+                               BKE_sequencer_imbuf_to_sequencer_space(context.scene, ibuf, FALSE);
 
                                copy_to_ibuf_still(context, seq, nr, ibuf);
 
index 2ed9d99..c0c5c57 100644 (file)
@@ -1627,7 +1627,6 @@ ImBuf *BKE_tracking_sample_pattern(int frame_width, int frame_height, ImBuf *sea
        float *mask = NULL;
 
        pattern_ibuf = IMB_allocImBuf(num_samples_x, num_samples_y, 32, IB_rectfloat);
-       pattern_ibuf->profile = IB_PROFILE_LINEAR_RGB;
 
        if (!search_ibuf->rect_float) {
                IMB_float_from_rect(search_ibuf);
@@ -1722,7 +1721,6 @@ ImBuf *BKE_tracking_get_search_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, Mov
        h = (marker->search_max[1] - marker->search_min[1]) * ibuf->y;
 
        searchibuf = IMB_allocImBuf(w, h, 32, ibuf->rect_float ? IB_rectfloat : IB_rect);
-       searchibuf->profile = ibuf->profile;
 
        IMB_rectcpy(searchibuf, ibuf, 0, 0, x, y, w, h);
 
@@ -3317,7 +3315,6 @@ static ImBuf *stabilization_allocate_ibuf(ImBuf *cacheibuf, ImBuf *srcibuf, int
        }
        else {
                cacheibuf = IMB_allocImBuf(srcibuf->x, srcibuf->y, srcibuf->planes, flags);
-               cacheibuf->profile = srcibuf->profile;
        }
 
        return cacheibuf;
index 4c454d9..fb3efbb 100644 (file)
@@ -71,7 +71,7 @@ ImBuf *BaseImageOperation::getImBuf()
        }
        
        if (ibuf->rect_float == NULL) {
-               IMB_colormanagement_imbuf_float_from_rect(ibuf);
+               IMB_float_from_rect(ibuf);
        }
        return ibuf;
 }
index 3217aca..d9618e8 100644 (file)
@@ -144,22 +144,30 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
                ibuf = BKE_sequencer_give_ibuf(context, CFRA, chanshown);
 
                if (ibuf) {
+                       ImBuf *linear_ibuf;
+
                        BLI_assert((oglrender->sizex == ibuf->x) && (oglrender->sizey == ibuf->y));
 
-                       if (ibuf->rect_float == NULL) {
-                               /* internally sequencer working in sRGB space and stores both bytes and float
-                                * buffers in sRGB space, but if byte->float onversion doesn't happen in sequencer
-                                * (e.g. when adding image sequence/movie into sequencer) there'll be only
-                                * byte buffer and profile will still indicate sRGB->linear space conversion is needed
-                                * here we're ensure there'll be no conversion happen and float buffer would store
-                                * linear frame (sergey) */
-                               ibuf->profile = IB_PROFILE_NONE;
-                               IMB_float_from_rect(ibuf);
+                       linear_ibuf = IMB_dupImBuf(ibuf);
+                       IMB_freeImBuf(ibuf);
+
+                       if (linear_ibuf->rect_float == NULL) {
+                               /* internally sequencer working in display space and stores both bytes and float buffers in that space.
+                                * It is possible that byte->float onversion didn't happen in sequencer (e.g. when adding image sequence/movie
+                                * into sequencer) there'll be only byte buffer. Create float buffer from existing byte buffer, making it linear
+                                */
+
+                               IMB_float_from_rect(linear_ibuf);
+                       }
+                       else {
+                               /* ensure float buffer is in linear space, not in display space */
+                               BKE_sequencer_imbuf_from_sequencer_space(scene, linear_ibuf);
                        }
 
-                       memcpy(rr->rectf, ibuf->rect_float, sizeof(float) * 4 * oglrender->sizex * oglrender->sizey);
 
-                       IMB_freeImBuf(ibuf);
+                       memcpy(rr->rectf, linear_ibuf->rect_float, sizeof(float) * 4 * oglrender->sizex * oglrender->sizey);
+
+                       IMB_freeImBuf(linear_ibuf);
                }
        }
        else if (view_context) {
@@ -234,11 +242,6 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
                }
        }
        
-       /* rr->rectf is now filled with image data */
-
-       if ((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW))
-               BKE_stamp_buf(scene, camera, NULL, rr->rectf, rr->rectx, rr->recty, 4);
-
        /* note on color management:
         *
         * OpenGL renders into sRGB colors, but render buffers are expected to be
@@ -247,9 +250,18 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
         * correct linear float buffer.
         */
 
-       IMB_buffer_float_from_float(rr->rectf, rr->rectf,
-                                   4, IB_PROFILE_LINEAR_RGB, IB_PROFILE_SRGB, FALSE,
-                                   oglrender->sizex, oglrender->sizey, oglrender->sizex, oglrender->sizex);
+       if (!oglrender->is_sequencer) {
+               /* sequencer has got tricker ocnversion happened above */
+
+               IMB_buffer_float_from_float(rr->rectf, rr->rectf,
+                                           4, IB_PROFILE_LINEAR_RGB, IB_PROFILE_SRGB, FALSE,
+                                           oglrender->sizex, oglrender->sizey, oglrender->sizex, oglrender->sizex);
+       }
+
+       /* rr->rectf is now filled with image data */
+
+       if ((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW))
+               BKE_stamp_buf(scene, camera, NULL, rr->rectf, rr->rectx, rr->recty, 4);
 
        RE_ReleaseResult(oglrender->re);
 
index 4b8411e..a829ef5 100644 (file)
@@ -535,12 +535,12 @@ static int ed_preview_draw_rect(ScrArea *sa, Scene *sce, ID *id, int split, int
 
                                }
                                else {
-                                       /* OCIO_TODO: currently seems an exception for textures,
+                                       /* OCIO_TODO: currently seems an exception for textures (came fro mlegacish time),
                                         *            but is it indeed expected behavior, or textures should be
                                         *            color managed as well?
                                         */
                                        IMB_buffer_byte_from_float(rect_byte, rres.rectf,
-                                                                  4, dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB, do_predivide,
+                                                                  4, dither, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB, do_predivide,
                                                                   rres.rectx, rres.recty, rres.rectx, rres.rectx);
                                }
 
index 386342d..6f51c5a 100644 (file)
@@ -155,7 +155,6 @@ typedef struct ImagePaintState {
        Image *image;
        ImBuf *canvas;
        ImBuf *clonecanvas;
-       short clonefreefloat;
        char *warnpackedfile;
        char *warnmultifile;
 
@@ -3947,7 +3946,7 @@ static void *do_projectpaint_thread(void *ph_v)
 
                                        last_projIma->touch = 1;
                                        is_floatbuf = last_projIma->ibuf->rect_float ? 1 : 0;
-                                       use_color_correction = (last_projIma->ibuf->profile == IB_PROFILE_LINEAR_RGB) ? 1 : 0;
+                                       use_color_correction = TRUE;
                                }
                                /* end copy */
 
@@ -4030,7 +4029,7 @@ static void *do_projectpaint_thread(void *ph_v)
 
                                                                last_projIma->touch = 1;
                                                                is_floatbuf = last_projIma->ibuf->rect_float ? 1 : 0;
-                                                               use_color_correction = (last_projIma->ibuf->profile == IB_PROFILE_LINEAR_RGB) ? 1 : 0;
+                                                               use_color_correction = TRUE;
                                                        }
                                                        /* end copy */
 
@@ -4580,15 +4579,7 @@ static int imapaint_canvas_set(ImagePaintState *s, Image *ima)
 
                /* temporarily add float rect for cloning */
                if (s->canvas->rect_float && !s->clonecanvas->rect_float) {
-                       short profile = IB_PROFILE_NONE;
-                       
-                       /* Don't want to color manage, but don't disturb existing profiles */
-                       SWAP(short, s->clonecanvas->profile, profile);
-
                        IMB_float_from_rect(s->clonecanvas);
-                       s->clonefreefloat = 1;
-                       
-                       SWAP(short, s->clonecanvas->profile, profile);
                }
                else if (!s->canvas->rect_float && !s->clonecanvas->rect)
                        IMB_rect_from_float(s->clonecanvas);
@@ -4597,10 +4588,8 @@ static int imapaint_canvas_set(ImagePaintState *s, Image *ima)
        return 1;
 }
 
-static void imapaint_canvas_free(ImagePaintState *s)
+static void imapaint_canvas_free(ImagePaintState *UNUSED(s))
 {
-       if (s->clonefreefloat)
-               imb_freerectfloatImBuf(s->clonecanvas);
 }
 
 static int imapaint_paint_sub_stroke(ImagePaintState *s, BrushPainter *painter, Image *image, short texpaint, float *uv, double time, int update, float pressure)
@@ -4616,7 +4605,10 @@ static int imapaint_paint_sub_stroke(ImagePaintState *s, BrushPainter *painter,
 
        BKE_brush_painter_require_imbuf(painter, ((ibuf->rect_float) ? 1 : 0), 0, 0);
 
-       if (BKE_brush_painter_paint(painter, imapaint_paint_op, pos, time, pressure, s, ibuf->profile == IB_PROFILE_LINEAR_RGB)) {
+       /* OCIO_TODO: float buffers are now always linear, so always use color correction
+        *            this should probably be changed when texture painting color space is supported
+        */
+       if (BKE_brush_painter_paint(painter, imapaint_paint_op, pos, time, pressure, s, TRUE)) {
                if (update)
                        imapaint_image_update(s->scene, s->sima, image, ibuf, texpaint);
                return 1;
index 0225758..f2a48f2 100644 (file)
@@ -277,13 +277,7 @@ int ED_space_clip_color_sample(SpaceClip *sc, ARegion *ar, int mval[2], float r_
 
                if (ibuf->rect_float) {
                        fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
-                       /* IB_PROFILE_NONE is default but infact its linear */
-                       if (ELEM(ibuf->profile, IB_PROFILE_LINEAR_RGB, IB_PROFILE_NONE)) {
-                               linearrgb_to_srgb_v3_v3(r_col, fp);
-                       }
-                       else {
-                               copy_v3_v3(r_col, fp);
-                       }
+                       linearrgb_to_srgb_v3_v3(r_col, fp);
                        ret = TRUE;
                }
                else if (ibuf->rect) {
index 563680f..616587b 100644 (file)
@@ -2047,13 +2047,7 @@ int ED_space_image_color_sample(SpaceImage *sima, ARegion *ar, int mval[2], floa
 
                if (ibuf->rect_float) {
                        fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
-
-                       if (ELEM(ibuf->profile, IB_PROFILE_LINEAR_RGB, IB_PROFILE_NONE)) {
-                               linearrgb_to_srgb_v3_v3(r_col, fp);
-                       }
-                       else {
-                               copy_v3_v3(r_col, fp);
-                       }
+                       linearrgb_to_srgb_v3_v3(r_col, fp);
                        ret = TRUE;
                }
                else if (ibuf->rect) {
index 9e3a537..8e38247 100644 (file)
@@ -381,12 +381,7 @@ int ED_space_node_color_sample(SpaceNode *snode, ARegion *ar, int mval[2], float
                if (ibuf->rect_float) {
                        fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
                        /* IB_PROFILE_NONE is default but infact its linear */
-                       if (ELEM(ibuf->profile, IB_PROFILE_LINEAR_RGB, IB_PROFILE_NONE)) {
-                               linearrgb_to_srgb_v3_v3(r_col, fp);
-                       }
-                       else {
-                               copy_v3_v3(r_col, fp);
-                       }
+                       linearrgb_to_srgb_v3_v3(r_col, fp);
                        ret = TRUE;
                }
                else if (ibuf->rect) {
@@ -419,10 +414,6 @@ static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
        }
 
        if (!ibuf->rect) {
-               if (info->color_manage)
-                       ibuf->profile = IB_PROFILE_LINEAR_RGB;
-               else
-                       ibuf->profile = IB_PROFILE_NONE;
                IMB_rect_from_float(ibuf);
        }
 
index 95e2889..af52366 100644 (file)
@@ -492,7 +492,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
                }
 
                /* TODO unneeded when float images are correctly treated as linear always */
-               if (!ncd && ibuf->profile == IB_PROFILE_LINEAR_RGB)
+               if (!ncd)
                        do_color_management = TRUE;
 
                if (ibuf->rect==NULL)
@@ -535,7 +535,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
                                if (do_color_management) {
                                        srgb_frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(float)*4, "floar_buf_col_cor");
                                        IMB_buffer_float_from_float(srgb_frect, ibuf->rect_float,
-                                               ibuf->channels, IB_PROFILE_SRGB, ibuf->profile, 0,
+                                               ibuf->channels, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB, 0,
                                                ibuf->x, ibuf->y, ibuf->x, ibuf->x);
                                        /* clamp buffer colors to 1.0 to avoid artifacts due to glu for hdr images */
                                        IMB_buffer_float_clamp(srgb_frect, ibuf->x, ibuf->y);
@@ -560,7 +560,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
                                if (do_color_management) {
                                        frect = srgb_frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(*srgb_frect)*4, "floar_buf_col_cor");
                                        IMB_buffer_float_from_float(srgb_frect, ibuf->rect_float,
-                                                       ibuf->channels, IB_PROFILE_SRGB, ibuf->profile, 0,
+                                                       ibuf->channels, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB, 0,
                                                        ibuf->x, ibuf->y, ibuf->x, ibuf->x);
                                        /* clamp buffer colors to 1.0 to avoid artifacts due to glu for hdr images */
                                        IMB_buffer_float_clamp(srgb_frect, ibuf->x, ibuf->y);
@@ -901,7 +901,7 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap)
                glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows);
 
                /* if color correction is needed, we must update the part that needs updating. */
-               if (ibuf->rect_float && (!U.use_16bit_textures || (ibuf->profile == IB_PROFILE_LINEAR_RGB))) {
+               if (ibuf->rect_float) {
                        float *buffer = MEM_mallocN(w*h*sizeof(float)*4, "temp_texpaint_float_buf");
                        IMB_partial_rect_from_float(ibuf, buffer, x, y, w, h);
 
index e5632d4..d090079 100644 (file)
@@ -62,7 +62,6 @@ void IMB_colormanagement_validate_settings(struct ColorManagedDisplaySettings *d
                                            struct ColorManagedViewSettings *view_settings);
 
 const char *IMB_colormanagement_role_colorspace_name_get(int role);
-void IMB_colormanagement_imbuf_float_from_rect(struct ImBuf *ibuf);
 
 /* ** Color space transformation functions ** */
 void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
@@ -85,7 +84,6 @@ void IMB_colormanagement_pixel_to_display_space_v4(float result[4], const float
 void IMB_colormanagement_pixel_to_display_space_v3(float result[3], const float pixel[3],  const struct ColorManagedViewSettings *view_settings,
                                                    const struct ColorManagedDisplaySettings *display_settings);
 
-void IMB_colormanagement_imbuf_assign_spaces(struct ImBuf *ibuf, struct ColorManagedColorspaceSettings *colorspace_settings);
 void IMB_colormanagement_imbuf_assign_float_space(struct ImBuf *ibuf, struct ColorManagedColorspaceSettings *colorspace_settings);
 
 void IMB_colormanagement_imbuf_make_display_space(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
index a8780d3..1503b9f 100644 (file)
@@ -375,7 +375,6 @@ void IMB_partial_rect_from_float(struct ImBuf *ibuf, float *buffer, int x, int y
 void IMB_float_from_rect(struct ImBuf *ibuf);
 void IMB_float_from_rect_simple(struct ImBuf *ibuf); /* no profile conversion */
 /* note, check that the conversion exists, only some are supported */
-void IMB_convert_profile(struct ImBuf *ibuf, int profile);
 float *IMB_float_profile_ensure(struct ImBuf *ibuf, int profile, int *alloc);
 void IMB_color_to_bw(struct ImBuf *ibuf);
 void IMB_saturation(struct ImBuf *ibuf, float sat);
index cda4319..93e213d 100644 (file)
@@ -101,7 +101,6 @@ typedef struct ImBuf {
 
        /* parameters used by conversion between byte and float */
        float dither;                           /* random dither value, for conversion from float -> byte rect */
-       short profile;                          /* color space/profile preset that the byte rect buffer represents */
 
        /* mipmapping */
        struct ImBuf *mipmap[IB_MIPMAP_LEVELS]; /* MipMap levels, a series of halved images */
index 67c99d5..0c002b7 100644 (file)
@@ -86,6 +86,7 @@ struct ColorSpace *colormanage_colorspace_get_indexed(int index);
 
 void colorspace_set_default_role(char *colorspace, int size, int role);
 
+void colormanage_imbuf_set_default_spaces(struct ImBuf *ibuf);
 void colormanage_imbuf_make_linear(struct ImBuf *ibuf, const char *from_colorspace);
 
 #endif  /* IMB_COLORMANAGEMENT_INTERN_H */
index 32c14e3..6904827 100644 (file)
@@ -386,6 +386,9 @@ ImBuf *IMB_allocImBuf(unsigned int x, unsigned int y, uchar planes, unsigned int
                                return NULL;
                        }
                }
+
+               /* assign default spaces */
+               colormanage_imbuf_set_default_spaces(ibuf);
        }
        return (ibuf);
 }
index fa8cc6c..394f516 100644 (file)
@@ -443,7 +443,6 @@ static ImBuf *avi_fetchibuf(struct anim *anim, int position)
                MEM_freeN(tmp);
        }
        
-       ibuf->profile = IB_PROFILE_SRGB;
        ibuf->rect_colorspace = colormanage_colorspace_get_named(anim->colorspace);
 
        return ibuf;
@@ -646,8 +645,6 @@ static void ffmpeg_postprocess(struct anim *anim)
        ImBuf *ibuf = anim->last_frame;
        int filter_y = 0;
 
-       ibuf->profile = IB_PROFILE_SRGB;
-
        if (!anim->pFrameComplete) {
                return;
        }
@@ -1332,7 +1329,6 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim, int position,
                        if (ibuf) {
                                anim->curposition = position;
                                IMB_convert_rgba_to_abgr(ibuf);
-                               ibuf->profile = IB_PROFILE_SRGB;
                        }
                        break;
                case ANIM_AVI:
index 5e7b1b8..df12f0b 100644 (file)
@@ -200,7 +200,6 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags, char co
 
        if (ibuf) {
                ibuf->ftype = BMP;
-               ibuf->profile = IB_PROFILE_SRGB;
        }
        
        return(ibuf);
index 7548974..7fa14dd 100644 (file)
@@ -830,6 +830,11 @@ void colorspace_set_default_role(char *colorspace, int size, int role)
        }
 }
 
+void colormanage_imbuf_set_default_spaces(ImBuf *ibuf)
+{
+       ibuf->rect_colorspace = colormanage_colorspace_get_named(global_role_default_byte);
+}
+
 void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace)
 {
        if (ibuf->rect_float) {
@@ -841,8 +846,6 @@ void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace)
 
                IMB_colormanagement_transform(ibuf->rect_float, ibuf->x, ibuf->y, ibuf->channels,
                                              from_colorspace, to_colorspace, predivide);
-
-               ibuf->profile = IB_PROFILE_LINEAR_RGB;
        }
 }
 
@@ -912,7 +915,7 @@ static void colormanage_check_colorspace_settings(ColorManagedColorspaceSettings
                ColorSpace *colorspace = colormanage_colorspace_get_named(colorspace_settings->name);
 
                if (!colorspace) {
-                       printf("Color management: %s colorspace \"%s\" not found, setting NONE instead.\n",
+                       printf("Color management: %s colorspace \"%s\" not found, will use default instead.\n",
                               what, colorspace_settings->name);
 
                        BLI_strncpy(colorspace_settings->name, "", sizeof(colorspace_settings->name));
@@ -1013,27 +1016,6 @@ const char *IMB_colormanagement_role_colorspace_name_get(int role)
        return NULL;
 }
 
-void IMB_colormanagement_imbuf_float_from_rect(ImBuf *ibuf)
-{
-       int predivide = ibuf->flags & IB_cm_predivide;
-
-       if (ibuf->rect == NULL)
-               return;
-
-       if (ibuf->rect_float == NULL) {
-               if (imb_addrectfloatImBuf(ibuf) == 0)
-                       return;
-       }
-
-       /* first, create float buffer in non-linear space */
-       IMB_buffer_float_from_byte(ibuf->rect_float, (unsigned char *) ibuf->rect, IB_PROFILE_SRGB, IB_PROFILE_SRGB,
-                                  FALSE, ibuf->x, ibuf->y, ibuf->x, ibuf->x);
-
-       /* then make float be in linear space */
-       IMB_colormanagement_colorspace_to_scene_linear(ibuf->rect_float, ibuf->x, ibuf->y, ibuf->channels,
-                                                      ibuf->rect_colorspace, predivide);
-}
-
 /*********************** Threaded display buffer transform routines *************************/
 
 typedef struct DisplayBufferThread {
@@ -1534,28 +1516,6 @@ void IMB_colormanagement_pixel_to_display_space_v3(float result[3], const float
        IMB_colormanagement_processor_free(cm_processor);
 }
 
-void IMB_colormanagement_imbuf_assign_spaces(ImBuf *ibuf, ColorManagedColorspaceSettings *colorspace_settings)
-{
-       if (colorspace_settings) {
-               if (colorspace_settings->name[0] == '\0') {
-                       /* when opening new image, assign it's color space based on default roles */
-
-                       if (ibuf->rect_float)
-                               BLI_strncpy(colorspace_settings->name, global_role_default_float, MAX_COLORSPACE_NAME);
-                       else
-                               BLI_strncpy(colorspace_settings->name, global_role_default_byte, MAX_COLORSPACE_NAME);
-               }
-
-               ibuf->rect_colorspace = colormanage_colorspace_get_named(colorspace_settings->name);
-       }
-       else {
-               if (ibuf->rect_float)
-                       ibuf->rect_colorspace = colormanage_colorspace_get_named(global_role_default_float);
-               else
-                       ibuf->rect_colorspace = colormanage_colorspace_get_named(global_role_default_byte);
-       }
-}
-
 void IMB_colormanagement_imbuf_assign_float_space(ImBuf *ibuf, ColorManagedColorspaceSettings *colorspace_settings)
 {
        ibuf->float_colorspace = colormanage_colorspace_get_named(colorspace_settings->name);
@@ -1569,7 +1529,7 @@ void IMB_colormanagement_imbuf_make_display_space(ImBuf *ibuf, const ColorManage
                return;
 
        if (global_tot_display == 0 || global_tot_view == 0) {
-               IMB_buffer_float_from_float(ibuf->rect_float, ibuf->rect_float, ibuf->channels, IB_PROFILE_LINEAR_RGB, ibuf->profile,
+               IMB_buffer_float_from_float(ibuf->rect_float, ibuf->rect_float, ibuf->channels, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB,
                                            ibuf->flags & IB_cm_predivide, ibuf->x, ibuf->y, ibuf->x, ibuf->x);
        }
        else {
@@ -2221,17 +2181,13 @@ void IMB_partial_display_buffer_update(ImBuf *ibuf, const float *linear_buffer,
                unsigned char *rect = (unsigned char *) ibuf->rect;
                int predivide = ibuf->flags & IB_cm_predivide;
                int channels = ibuf->channels;
-               int profile_from = ibuf->profile;
                int width = xmax - xmin;
                int height = ymax - ymin;
                int rect_index = (ymin * ibuf->x + xmin) * channels;
                int linear_index = ((ymin - offset_y) * stride + (xmin - offset_x)) * channels;
 
-               if (profile_from == IB_PROFILE_NONE)
-                       profile_from = IB_PROFILE_LINEAR_RGB;
-
                IMB_buffer_byte_from_float(rect + rect_index, linear_buffer + linear_index, channels, ibuf->dither,
-                                          IB_PROFILE_SRGB, profile_from, predivide, width, height, ibuf->x, stride);
+                                          IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB, predivide, width, height, ibuf->x, stride);
        }
 
        if (ibuf->display_buffer_flags) {
index 676dde1..7aacbf2 100644 (file)
@@ -142,7 +142,6 @@ struct ImBuf *imb_load_dds(unsigned char *mem, size_t size, int flags, char colo
        if (ibuf == 0) return(0); /* memory allocation failed */
 
        ibuf->ftype = DDS;
-       ibuf->profile = IB_PROFILE_SRGB;
        ibuf->dds_data.fourcc = dds.fourCC();
        ibuf->dds_data.nummipmaps = dds.mipmapCount();
 
index 5ba08f1..5e38c31 100644 (file)
@@ -40,6 +40,9 @@
 #include "IMB_imbuf.h"
 #include "IMB_allocimbuf.h"
 
+#include "IMB_colormanagement.h"
+#include "IMB_colormanagement_intern.h"
+
 #include "MEM_guardedalloc.h"
 
 /**************************** Interlace/Deinterlace **************************/
@@ -522,32 +525,34 @@ void IMB_buffer_byte_from_byte(uchar *rect_to, const uchar *rect_from,
 void IMB_rect_from_float(ImBuf *ibuf)
 {
        int predivide = (ibuf->flags & IB_cm_predivide);
-       int profile_from;
+       float *buffer;
+       const char *from_colorspace;
 
        /* verify we have a float buffer */
        if (ibuf->rect_float == NULL)
                return;
 
        /* create byte rect if it didn't exist yet */
-       if (ibuf->rect == NULL)
-               imb_addrectImBuf(ibuf);
-
-       /* determine profiles */
-       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
-               profile_from = IB_PROFILE_LINEAR_RGB;
-       }
-       else if (ELEM(ibuf->profile, IB_PROFILE_SRGB, IB_PROFILE_NONE)) {
-               profile_from = IB_PROFILE_SRGB;
-       }
-       else {
-               profile_from = IB_PROFILE_SRGB; /* should never happen */
-               BLI_assert(0);
+       if (ibuf->rect == NULL) {
+               if (imb_addrectImBuf(ibuf) == 0)
+                       return;
        }
 
-       /* do conversion */
-       IMB_buffer_byte_from_float((uchar *)ibuf->rect, ibuf->rect_float,
-                                  ibuf->channels, ibuf->dither, IB_PROFILE_SRGB, profile_from, predivide,
-                                  ibuf->x, ibuf->y, ibuf->x, ibuf->x);
+       if (ibuf->float_colorspace == NULL)
+               from_colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR);
+       else
+               from_colorspace = ibuf->float_colorspace->name;
+
+       buffer = MEM_dupallocN(ibuf->rect_float);
+
+       /* first make float buffer in byte space */
+       IMB_colormanagement_transform(buffer, ibuf->x, ibuf->y, ibuf->channels, from_colorspace, ibuf->rect_colorspace->name, predivide);
+
+       /* convert float to byte */
+       IMB_buffer_byte_from_float((unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB,
+                                  FALSE, ibuf->x, ibuf->y, ibuf->x, ibuf->x);
+
+       MEM_freeN(buffer);
 
        /* ensure user flag is reset */
        ibuf->userflags &= ~IB_RECT_INVALID;
@@ -559,7 +564,7 @@ void IMB_partial_rect_from_float(ImBuf *ibuf, float *buffer, int x, int y, int w
        float *rect_float;
        uchar *rect_byte;
        int predivide = (ibuf->flags & IB_cm_predivide);
-       int profile_from;
+       int profile_from = IB_PROFILE_LINEAR_RGB;
 
        /* verify we have a float buffer */
        if (ibuf->rect_float == NULL || buffer == NULL)
@@ -569,18 +574,6 @@ void IMB_partial_rect_from_float(ImBuf *ibuf, float *buffer, int x, int y, int w
        if (ibuf->rect == NULL)
                imb_addrectImBuf(ibuf);
 
-       /* determine profiles */
-       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
-               profile_from = IB_PROFILE_LINEAR_RGB;
-       }
-       else if (ELEM(ibuf->profile, IB_PROFILE_SRGB, IB_PROFILE_NONE)) {
-               profile_from = IB_PROFILE_SRGB;
-       }
-       else {
-               profile_from = IB_PROFILE_SRGB; /* should never happen */
-               BLI_assert(0);
-       }
-
        /* do conversion */
        rect_float = ibuf->rect_float + (x + y * ibuf->x) * ibuf->channels;
        rect_byte = (uchar *)ibuf->rect + (x + y * ibuf->x) * 4;
@@ -589,6 +582,7 @@ void IMB_partial_rect_from_float(ImBuf *ibuf, float *buffer, int x, int y, int w
                                    ibuf->channels, IB_PROFILE_SRGB, profile_from, predivide,
                                    w, h, w, ibuf->x);
 
+       /* XXX: need to convert to image buffer's rect space */
        IMB_buffer_byte_from_float(rect_byte, buffer,
                                   4, ibuf->dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB, 0,
                                   w, h, ibuf->x, w);
@@ -600,26 +594,23 @@ void IMB_partial_rect_from_float(ImBuf *ibuf, float *buffer, int x, int y, int w
 void IMB_float_from_rect(ImBuf *ibuf)
 {
        int predivide = (ibuf->flags & IB_cm_predivide);
-       int profile_from;
 
        /* verify if we byte and float buffers */
        if (ibuf->rect == NULL)
                return;
 
-       if (ibuf->rect_float == NULL)
+       if (ibuf->rect_float == NULL) {
                if (imb_addrectfloatImBuf(ibuf) == 0)
                        return;
-       
-       /* determine profiles */
-       if (ibuf->profile == IB_PROFILE_NONE)
-               profile_from = IB_PROFILE_LINEAR_RGB;
-       else
-               profile_from = IB_PROFILE_SRGB;
-       
-       /* do conversion */
-       IMB_buffer_float_from_byte(ibuf->rect_float, (uchar *)ibuf->rect,
-                                  IB_PROFILE_LINEAR_RGB, profile_from, predivide,
-                                  ibuf->x, ibuf->y, ibuf->x, ibuf->x);
+       }
+
+       /* first, create float buffer in non-linear space */
+       IMB_buffer_float_from_byte(ibuf->rect_float, (unsigned char *) ibuf->rect, IB_PROFILE_SRGB, IB_PROFILE_SRGB,
+                                  FALSE, ibuf->x, ibuf->y, ibuf->x, ibuf->x);
+
+       /* then make float be in linear space */
+       IMB_colormanagement_colorspace_to_scene_linear(ibuf->rect_float, ibuf->x, ibuf->y, ibuf->channels,
+                                                      ibuf->rect_colorspace, predivide);
 }
 
 /* no profile conversion */
@@ -635,63 +626,19 @@ void IMB_float_from_rect_simple(ImBuf *ibuf)
                                   ibuf->x, ibuf->y, ibuf->x, ibuf->x);
 }
 
-void IMB_convert_profile(ImBuf *ibuf, int profile)
-{
-       int predivide = (ibuf->flags & IB_cm_predivide);
-       int profile_from, profile_to;
-
-       if (ibuf->profile == profile)
-               return;
-
-       /* determine profiles */
-       if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
-               profile_from = IB_PROFILE_LINEAR_RGB;
-       else if (ELEM(ibuf->profile, IB_PROFILE_SRGB, IB_PROFILE_NONE))
-               profile_from = IB_PROFILE_SRGB;
-       else {
-               BLI_assert(0);
-               profile_from = IB_PROFILE_SRGB; /* dummy, should never happen */
-       }
-
-       if (profile == IB_PROFILE_LINEAR_RGB)
-               profile_to = IB_PROFILE_LINEAR_RGB;
-       else if (ELEM(profile, IB_PROFILE_SRGB, IB_PROFILE_NONE))
-               profile_to = IB_PROFILE_SRGB;
-       else {
-               BLI_assert(0);
-               profile_to = IB_PROFILE_SRGB; /* dummy, should never happen */
-       }
-       
-       /* do conversion */
-       if (ibuf->rect_float) {
-               IMB_buffer_float_from_float(ibuf->rect_float, ibuf->rect_float,
-                                           4, profile_to, profile_from, predivide,
-                                           ibuf->x, ibuf->y, ibuf->x, ibuf->x);
-       }
-
-       if (ibuf->rect) {
-               IMB_buffer_byte_from_byte((uchar *)ibuf->rect, (uchar *)ibuf->rect,
-                                         profile_to, profile_from, predivide,
-                                         ibuf->x, ibuf->y, ibuf->x, ibuf->x);
-       }
-
-       /* set new profile */
-       ibuf->profile = profile;
-}
-
 /* use when you need to get a buffer with a certain profile
  * if the return  */
+
+/* OCIO_TODO: used only by Cineon/DPX exporter which is still broken, so can not guarantee
+ *            this function is working properly
+ */
 float *IMB_float_profile_ensure(ImBuf *ibuf, int profile, int *alloc)
 {
        int predivide = (ibuf->flags & IB_cm_predivide);
-       int profile_from, profile_to;
-
-       /* determine profiles */
-       if (ibuf->profile == IB_PROFILE_NONE)
-               profile_from = IB_PROFILE_LINEAR_RGB;
-       else
-               profile_from = IB_PROFILE_SRGB;
+       int profile_from = IB_PROFILE_LINEAR_RGB;
+       int profile_to;
 
+       /* determine profile */
        if (profile == IB_PROFILE_NONE)
                profile_to = IB_PROFILE_LINEAR_RGB;
        else
index 5835593..3fd25ff 100644 (file)
@@ -529,7 +529,6 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags, char colo
        }
 
        ibuf->ftype = IMAGIC;
-       ibuf->profile = IB_PROFILE_SRGB;
 
        test_endian_zbuf(ibuf);
 
index b2221a7..dd559c5 100644 (file)
@@ -647,136 +647,67 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
                switch (prec) {
                        case 8: /* Convert blenders float color channels to 8, 12 or 16bit ints */
                                if (numcomps == 4) {
-                                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[0]));
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[1]));
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[2]));
-                                                       a[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[3]);
-                                               }
-                                               PIXEL_LOOPER_END;
-                                       }
-                                       else {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[0]);
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[1]);
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[2]);
-                                                       a[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[3]);
-                                               }
-                                               PIXEL_LOOPER_END;
+                                       PIXEL_LOOPER_BEGIN(rect_float)
+                                       {
+                                               r[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[0]));
+                                               g[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[1]));
+                                               b[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[2]));
+                                               a[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[3]);
                                        }
+                                       PIXEL_LOOPER_END;
                                }
                                else {
-                                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[0]));
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[1]));
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[2]));
-                                               }
-                                               PIXEL_LOOPER_END;
-                                       }
-                                       else {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[0]);
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[1]);
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[2]);
-                                               }
-                                               PIXEL_LOOPER_END;
+                                       PIXEL_LOOPER_BEGIN(rect_float)
+                                       {
+                                               r[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[0]));
+                                               g[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[1]));
+                                               b[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[2]));
                                        }
+                                       PIXEL_LOOPER_END;
                                }
                                break;
                        
                        case 12:
                                if (numcomps == 4) {
-                                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[0]));
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[1]));
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[2]));
-                                                       a[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[3]);
-                                               }
-                                               PIXEL_LOOPER_END;
-                                       }
-                                       else {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[0]);
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[1]);
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[2]);
-                                                       a[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[3]);
-                                               }
-                                               PIXEL_LOOPER_END;
+                                       PIXEL_LOOPER_BEGIN(rect_float)
+                                       {
+                                               r[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[0]));
+                                               g[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[1]));
+                                               b[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[2]));
+                                               a[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[3]);
                                        }
+                                       PIXEL_LOOPER_END;
                                }
                                else {
-                                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[0]));
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[1]));
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[2]));
-                                               }
-                                               PIXEL_LOOPER_END;
-                                       }
-                                       else {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[0]);
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[1]);
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[2]);
-                                               }
-                                               PIXEL_LOOPER_END;
+                                       PIXEL_LOOPER_BEGIN(rect_float)
+                                       {
+                                               r[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[0]));
+                                               g[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[1]));
+                                               b[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[2]));
                                        }
+                                       PIXEL_LOOPER_END;
                                }
                                break;
 
                        case 16:
                                if (numcomps == 4) {
-                                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[0]));
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[1]));
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[2]));
-                                                       a[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[3]);
-                                               }
-                                               PIXEL_LOOPER_END;
-                                       }
-                                       else {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[0]);
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[1]);
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[2]);
-                                                       a[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[3]);
-                                               }
-                                               PIXEL_LOOPER_END;
+                                       PIXEL_LOOPER_BEGIN(rect_float)
+                                       {
+                                               r[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[0]));
+                                               g[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[1]));
+                                               b[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[2]));
+                                               a[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[3]);
                                        }
+                                       PIXEL_LOOPER_END;
                                }
                                else {
-                                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[0]));
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[1]));
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[2]));
-                                               }
-                                               PIXEL_LOOPER_END;
-                                       }
-                                       else {
-                                               PIXEL_LOOPER_BEGIN(rect_float)
-                                               {
-                                                       r[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[0]);
-                                                       g[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[1]);
-                                                       b[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[2]);
-                                               }
-                                               PIXEL_LOOPER_END;
+                                       PIXEL_LOOPER_BEGIN(rect_float)
+                                       {
+                                               r[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[0]));
+                                               g[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[1]));
+                                               b[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[2]));
                                        }
+                                       PIXEL_LOOPER_END;
                                }
                                break;
                }
index 59cf790..691db96 100644 (file)
@@ -438,7 +438,6 @@ next_stamp_marker:
                jpeg_destroy((j_common_ptr) cinfo);
                if (ibuf) {
                        ibuf->ftype = ibuf_ftype;
-                       ibuf->profile = IB_PROFILE_SRGB;
                }
        }
 
index 4dfa168..1307892 100644 (file)
@@ -382,30 +382,15 @@ static int imb_save_openexr_half(struct ImBuf *ibuf, const char *name, int flags
                else {
                        unsigned char *from;
 
-                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
-                               for (int i = ibuf->y - 1; i >= 0; i--) {
-                                       from = (unsigned char *)ibuf->rect + channels * i * width;
-
-                                       for (int j = ibuf->x; j > 0; j--) {
-                                               to->r = (float)(from[0]) / 255.0f;
-                                               to->g = (float)(from[1]) / 255.0f;
-                                               to->b = (float)(from[2]) / 255.0f;
-                                               to->a = (float)(channels >= 4) ? from[3] / 255.0f : 1.0f;
-                                               to++; from += 4;
-                                       }
-                               }
-                       }
-                       else {
-                               for (int i = ibuf->y - 1; i >= 0; i--) {
-                                       from = (unsigned char *)ibuf->rect + channels * i * width;
-
-                                       for (int j = ibuf->x; j > 0; j--) {
-                                               to->r = srgb_to_linearrgb((float)from[0] / 255.0f);
-                                               to->g = srgb_to_linearrgb((float)from[1] / 255.0f);
-                                               to->b = srgb_to_linearrgb((float)from[2] / 255.0f);
-                                               to->a = channels >= 4 ? (float)from[3] / 255.0f : 1.0f;
-                                               to++; from += 4;
-                                       }
+                       for (int i = ibuf->y - 1; i >= 0; i--) {
+                               from = (unsigned char *)ibuf->rect + channels * i * width;
+
+                               for (int j = ibuf->x; j > 0; j--) {
+                                       to->r = srgb_to_linearrgb((float)from[0] / 255.0f);
+                                       to->g = srgb_to_linearrgb((float)from[1] / 255.0f);
+                                       to->b = srgb_to_linearrgb((float)from[2] / 255.0f);
+                                       to->a = channels >= 4 ? (float)from[3] / 255.0f : 1.0f;
+                                       to++; from += 4;
                                }
                        }
                }
@@ -1169,9 +1154,6 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, size_t size, int flags, char
                        ibuf = IMB_allocImBuf(width, height, is_alpha ? 32 : 24, 0);
                        ibuf->ftype = OPENEXR;
 
-                       /* openEXR is linear as per EXR spec */
-                       ibuf->profile = IB_PROFILE_LINEAR_RGB;
-
                        if (!(flags & IB_test)) {
                                if (is_multi) { /* only enters with IB_multilayer flag set */
                                        /* constructs channels for reading, allocates memory in channels */
index 7db34e2..6310d8e 100644 (file)
@@ -394,10 +394,6 @@ ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags, char colorspace[I
 
        if (ibuf) {
                ibuf->ftype = PNG;
-               if (bit_depth == 16)
-                       ibuf->profile = IB_PROFILE_LINEAR_RGB;
-               else
-                       ibuf->profile = IB_PROFILE_SRGB;
 
                if (png_get_valid(png_ptr, info_ptr, PNG_INFO_pHYs)) {
                        int unit_type;
index 4eb6999..5add372 100644 (file)
@@ -212,7 +212,6 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, size_t size, int flags, char color
 
                        if (ibuf == NULL) return NULL;
                        ibuf->ftype = RADHDR;
-                       ibuf->profile = IB_PROFILE_LINEAR_RGB;
 
                        if (flags & IB_test) return ibuf;
 
index 764c326..a1fa05d 100644 (file)
@@ -80,7 +80,7 @@ ImBuf *IMB_ibImageFromMemory(unsigned char *mem, size_t size, int flags, char co
                                                /* byte buffer is never internally converted to some standard space,
                                                 * store pointer to it's color space descriptor instead
                                                 */
-                                               ibuf->rect_colorspace = colormanage_colorspace_get_named(colorspace);
+                                               ibuf->rect_colorspace = colormanage_colorspace_get_named(effective_colorspace);
                                        }
 
                                        BLI_strncpy(colorspace, effective_colorspace, IM_MAX_SPACE);
index be99050..7b6bca6 100644 (file)
@@ -565,7 +565,6 @@ ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags, char colors
 
        if (ibuf == NULL) return(NULL);
        ibuf->ftype = TGA;
-       ibuf->profile = IB_PROFILE_SRGB;
        mem = mem + 18 + tga.numid;
        
        cp[0] = 0xff;
index 4ee3792..932a494 100644 (file)
@@ -467,8 +467,6 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul)
                _TIFFfree(sbuf);
 
        if (success) {
-               ibuf->profile = (bitspersample == 32) ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB;
-
                /* Code seems to be not needed for 16 bits tif, on PPC G5 OSX (ton) */
                if (bitspersample < 16)
                        if (ENDIAN_ORDER == B_ENDIAN)
@@ -792,10 +790,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
                                /* convert from float source */
                                float rgb[4];
                                
-                               if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
-                                       linearrgb_to_srgb_v3_v3(rgb, &fromf[from_i]);
-                               else
-                                       copy_v3_v3(rgb, &fromf[from_i]);
+                               linearrgb_to_srgb_v3_v3(rgb, &fromf[from_i]);
 
                                rgb[3] = fromf[from_i + 3];
 
index 5861f07..a50cfae 100644 (file)
@@ -294,32 +294,16 @@ float *node_composit_get_float_buffer(RenderData *rd, ImBuf *ibuf, int *alloc)
         *            to new color management system since this code would likely be simply removed soon
         */
        if (rd->color_mgt_flag & R_COLOR_MANAGEMENT) {
-               if (ibuf->profile != IB_PROFILE_NONE) {
-                       rect= ibuf->rect_float;
-               }
-               else {
-                       rect= MEM_mapallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image");
-
-                       IMB_buffer_float_from_float(rect, ibuf->rect_float,
-                               4, IB_PROFILE_LINEAR_RGB, IB_PROFILE_SRGB, predivide,
-                               ibuf->x, ibuf->y, ibuf->x, ibuf->x);
-
-                       *alloc= TRUE;
-               }
+               rect= ibuf->rect_float;
        }
        else {
-               if (ibuf->profile == IB_PROFILE_NONE) {
-                       rect= ibuf->rect_float;
-               }
-               else {
-                       rect= MEM_mapallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image");
+               rect= MEM_mapallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image");
 
-                       IMB_buffer_float_from_float(rect, ibuf->rect_float,
-                               4, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB, predivide,
-                               ibuf->x, ibuf->y, ibuf->x, ibuf->x);
+               IMB_buffer_float_from_float(rect, ibuf->rect_float,
+                       4, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB, predivide,
+                       ibuf->x, ibuf->y, ibuf->x, ibuf->x);
 
                        *alloc= TRUE;
-               }
        }
 
        return rect;
index 06d24e4..656e2a7 100644 (file)
@@ -267,12 +267,6 @@ static void exec_output_file_singlelayer(RenderData *rd, bNode *node, bNodeStack
                        ibuf->rect_float = cbuf->rect;
                        ibuf->dither = rd->dither_intensity;
                        
-                       /* OCIO_TODO: this is a part of legacy compositor, which likely would be removed before next release
-                        *            keep old color management flag untouched for now
-                        */
-                       if (rd->color_mgt_flag & R_COLOR_MANAGEMENT)
-                               ibuf->profile = IB_PROFILE_LINEAR_RGB;
-                       
                        /* get full path */
                        BLI_join_dirfile(path, FILE_MAX, nimf->base_path, sockdata->path);
                        BKE_makepicstring(filename, path, bmain->name, rd->cfra, format->imtype, (rd->scemode & R_EXTENSION), TRUE);
index e30b833..75b9056 100644 (file)
@@ -291,7 +291,6 @@ ImBuf * qtime_fetchibuf (struct anim *anim, int position)
        ibuf = nsImageToiBuf(frameImage,anim->x, anim->y);
        [pool drain];
        
-       ibuf->profile = IB_PROFILE_SRGB;
        return ibuf;
 }
 
index 5b13d77..e44eba2 100644 (file)
@@ -392,8 +392,6 @@ ImBuf *qtime_fetchibuf(struct anim *anim, int position)
        }
 #endif
 
-       ibuf->profile = IB_PROFILE_SRGB;
-       
        IMB_flipy(ibuf);
        return ibuf;
 }
index c6e225c..03eb21d 100644 (file)
@@ -472,8 +472,6 @@ static void render_envmap(Render *re, EnvMap *env)
                        ibuf = IMB_allocImBuf(envre->rectx, envre->recty, 24, IB_rect | IB_rectfloat);
                        memcpy(ibuf->rect_float, rl->rectf, ibuf->channels * ibuf->x * ibuf->y * sizeof(float));
                        
-                       ibuf->profile = IB_PROFILE_LINEAR_RGB;
-                       
                        /* envmap renders without alpha */
                        alpha = ibuf->rect_float + 3;
                        for (y = ibuf->x * ibuf->y - 1; y >= 0; y--, alpha += 4)
index b701964..f11f84c 100644 (file)
@@ -1086,14 +1086,10 @@ ImBuf *render_result_rect_to_ibuf(RenderResult *rr, RenderData *rd)
         * note that sequence editor can generate 8bpc render buffers
         */
        if (ibuf->rect) {
-               ibuf->profile = IB_PROFILE_SRGB;
                if (BKE_imtype_valid_depths(rd->im_format.imtype) & (R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_24 | R_IMF_CHAN_DEPTH_32)) {
-                       IMB_colormanagement_imbuf_float_from_rect(ibuf);
+                       IMB_float_from_rect(ibuf);
                }
        }
-       else {
-               ibuf->profile = IB_PROFILE_LINEAR_RGB;
-       }
 
        /* color -> grayscale */
        /* editing directly would alter the render view */
index 34ff4d6..97a05e6 100644 (file)
@@ -2621,8 +2621,6 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up
                ima->flag&= ~IMA_USED_FOR_RENDER;
                if (ibuf) {
                        ibuf->userdata = NULL; /* use for masking if needed */
-                       if (ibuf->rect_float)
-                               ibuf->profile = IB_PROFILE_LINEAR_RGB;
                }
        }