Fix T37670: Paint mode + procedural map colours error
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 3 Dec 2013 16:13:15 +0000 (22:13 +0600)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 3 Dec 2013 16:13:15 +0000 (22:13 +0600)
Summary:
Seems to be known TODO in the code, but no idea why it
was never solved, especially since tweak is so much easy.

It might be arguable that we need to support painting
color space, but it's still much better to convert to
sRGB space. It's gonna to cover 90% of cases anyway.

Reviewers: campbellbarton, brecht

Reviewed By: brecht

Maniphest Tasks: T37670

Differential Revision: http://developer.blender.org/D65

source/blender/blenkernel/intern/brush.c
source/blender/editors/sculpt_paint/paint_image_2d.c
source/blender/editors/sculpt_paint/paint_image_proj.c

index 33c6f3eb7c05190dca8a1a4eb241d81195229fe4..de81ef179d7570fb45d952a1a1d3e51bdcb2d9b7 100644 (file)
@@ -45,6 +45,7 @@
 #include "BKE_texture.h"
 #include "BKE_icons.h"
 
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
@@ -639,6 +640,16 @@ float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br,
                rgba[2] = intensity;
                rgba[3] = 1.0f;
        }
+       else {
+               if (br->mtex.tex->type == TEX_IMAGE && br->mtex.tex->ima) {
+                       ImBuf *tex_ibuf = BKE_image_pool_acquire_ibuf(br->mtex.tex->ima, &br->mtex.tex->iuser, pool);
+                       /* For consistency, sampling always returns color in linear space */
+                       if (tex_ibuf->rect_float == NULL) {
+                               IMB_colormanagement_colorspace_to_scene_linear_v3(rgba, tex_ibuf->rect_colorspace);
+                       }
+                       BKE_image_pool_release_ibuf(br->mtex.tex->ima, tex_ibuf, pool);
+               }
+       }
 
        return intensity;
 }
index 1a19341aceca2c3bc39ae58de1cc6ab512576c18..5f4594703ee4c0483221c2a8c47f64f805448f46 100644 (file)
@@ -275,6 +275,10 @@ static ImBuf *brush_painter_imbuf_new(BrushPainter *painter, int size)
                        if (is_texbrush) {
                                brush_imbuf_tex_co(&tex_mapping, x, y, texco);
                                BKE_brush_sample_tex_3D(scene, brush, texco, rgba, thread, pool);
+                               /* TODO(sergey): Support texture paint color space. */
+                               if (!use_float) {
+                                       linearrgb_to_srgb_v3_v3(rgba, rgba);
+                               }
                                mul_v3_v3(rgba, brush_rgb);
                        }
                        else {
@@ -362,6 +366,10 @@ static void brush_painter_imbuf_update(BrushPainter *painter, ImBuf *oldtexibuf,
                                if (is_texbrush) {
                                        brush_imbuf_tex_co(&tex_mapping, x, y, texco);
                                        BKE_brush_sample_tex_3D(scene, brush, texco, rgba, thread, pool);
+                                       /* TODO(sergey): Support texture paint color space. */
+                                       if (!use_float) {
+                                               linearrgb_to_srgb_v3_v3(rgba, rgba);
+                                       }
                                        mul_v3_v3(rgba, brush_rgb);
                                }
                                else {
index 59f398a8719596ebed3c9d2c1b52580e713ee6be..fccd9cf0a19584f7eb1a22f751d2778ad7920153 100644 (file)
@@ -3758,8 +3758,9 @@ static void do_projectpaint_draw(ProjPaintState *ps, ProjPixel *projPixel, const
        copy_v3_v3(rgb, ps->brush->rgb);
 
        if (ps->is_texbrush) {
-               /* XXX actually should convert texrgb from linear to srgb here */
                mul_v3_v3(rgb, texrgb);
+               /* TODO(sergey): Support texture paint color space. */
+               linearrgb_to_srgb_v3_v3(rgb, rgb);
        }
 
        rgb_float_to_uchar(rgba_ub, rgb);