Revision: 37154
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37154
Author: psy-fi
Date: 2011-06-04 01:38:04 +0000 (Sat, 04 Jun 2011)
Log Message:
-----------
GSOC 2011 - onion branch
Color correction fixes no.4
Painting with color brushes now respects the color profile setting for float
textures.
+ little changes so that code is the same as reviewed patch
http://codereview.appspot.com/4560052/
hoping that I have as few headaches as possible when merging.
When texture sampling fully respects color correction we will have full color
profile support for float textures...
who knows, maybe it's just the beginning :)
Modified Paths:
--------------
branches/soc-2011-onion/source/blender/blenkernel/BKE_brush.h
branches/soc-2011-onion/source/blender/blenkernel/intern/brush.c
branches/soc-2011-onion/source/blender/blenlib/BLI_utildefines.h
branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c
branches/soc-2011-onion/source/blender/gpu/intern/gpu_draw.c
branches/soc-2011-onion/source/blender/imbuf/IMB_imbuf.h
branches/soc-2011-onion/source/blender/imbuf/intern/divers.c
Modified: branches/soc-2011-onion/source/blender/blenkernel/BKE_brush.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/BKE_brush.h
2011-06-04 01:09:38 UTC (rev 37153)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_brush.h
2011-06-04 01:38:04 UTC (rev 37154)
@@ -71,7 +71,7 @@
/* sampling */
void brush_sample_tex(struct Brush *brush, float *xy, float *rgba, const int
thread);
void brush_imbuf_new(struct Brush *brush, short flt, short texfalloff, int
size,
- struct ImBuf **imbuf);
+ struct ImBuf **imbuf, int use_color_correction);
/* painting */
struct BrushPainter;
@@ -82,7 +82,7 @@
void brush_painter_require_imbuf(BrushPainter *painter, short flt,
short texonly, int size);
int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos,
- double time, float pressure, void *user);
+ double time, float pressure, void *user, int use_color_correction);
void brush_painter_break_stroke(BrushPainter *painter);
void brush_painter_free(BrushPainter *painter);
Modified: branches/soc-2011-onion/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/brush.c
2011-06-04 01:09:38 UTC (rev 37153)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/brush.c
2011-06-04 01:38:04 UTC (rev 37154)
@@ -535,7 +535,7 @@
}
-void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize,
ImBuf **outbuf)
+void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize,
ImBuf **outbuf, int use_color_correction)
{
ImBuf *ibuf;
float xy[2], dist, rgba[4], *dstf;
@@ -543,6 +543,7 @@
const int radius= brush_size(brush);
char *dst, crgb[3];
const float alpha= brush_alpha(brush);
+ float brush_rgb[3];
imbflag= (flt)? IB_rectfloat: IB_rect;
xoff = -bufsize/2.0f + 0.5f;
@@ -555,6 +556,11 @@
ibuf= IMB_allocImBuf(bufsize, bufsize, 32, imbflag);
if (flt) {
+ copy_v3_v3(brush_rgb, brush->rgb);
+ if(use_color_correction){
+ srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb);
+ }
+
for (y=0; y < ibuf->y; y++) {
dstf = ibuf->rect_float + y*rowbytes;
@@ -565,7 +571,7 @@
if (texfall == 0) {
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
- VECCOPY(dstf, brush->rgb);
+ VECCOPY(dstf, brush_rgb);
dstf[3]=
alpha*brush_curve_strength_clamp(brush, dist, radius);
}
else if (texfall == 1) {
@@ -575,10 +581,7 @@
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
brush_sample_tex(brush, xy, rgba, 0);
-
- dstf[0] =
rgba[0]*srgb_to_linearrgb(brush->rgb[0]);
- dstf[1] =
rgba[1]*srgb_to_linearrgb(brush->rgb[1]);
- dstf[2] =
rgba[2]*srgb_to_linearrgb(brush->rgb[2]);
+ mul_v3_v3v3(dstf, rgba, brush_rgb);
dstf[3] =
rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius);
}
}
@@ -876,7 +879,7 @@
brush_painter_do_partial(painter, NULL, x1, y2, x2, ibuf->y, 0,
0, pos);
}
-static void brush_painter_refresh_cache(BrushPainter *painter, float *pos)
+static void brush_painter_refresh_cache(BrushPainter *painter, float *pos, int
use_color_correction)
{
Brush *brush= painter->brush;
BrushPainterCache *cache= &painter->cache;
@@ -903,11 +906,11 @@
size= (cache->size)? cache->size: diameter;
if (brush->flag & BRUSH_FIXED_TEX) {
- brush_imbuf_new(brush, flt, 3, size, &cache->maskibuf);
+ brush_imbuf_new(brush, flt, 3, size, &cache->maskibuf,
use_color_correction);
brush_painter_fixed_tex_partial_update(painter, pos);
}
else
- brush_imbuf_new(brush, flt, 2, size, &cache->ibuf);
+ brush_imbuf_new(brush, flt, 2, size, &cache->ibuf,
use_color_correction);
cache->lastsize= diameter;
cache->lastalpha= alpha;
@@ -966,7 +969,7 @@
}
}
-int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos,
double time, float pressure, void *user)
+int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos,
double time, float pressure, void *user, int use_color_correction)
{
Brush *brush= painter->brush;
int totpaintops= 0;
@@ -984,7 +987,7 @@
brush_apply_pressure(painter, brush, pressure);
if (painter->cache.enabled)
- brush_painter_refresh_cache(painter, pos);
+ brush_painter_refresh_cache(painter, pos,
use_color_correction);
totpaintops += func(user, painter->cache.ibuf, pos, pos);
painter->lasttime= time;
@@ -1057,7 +1060,7 @@
brush_jitter_pos(brush, paintpos, finalpos);
if (painter->cache.enabled)
- brush_painter_refresh_cache(painter,
finalpos);
+ brush_painter_refresh_cache(painter,
finalpos, use_color_correction);
totpaintops +=
func(user, painter->cache.ibuf,
painter->lastpaintpos, finalpos);
@@ -1071,7 +1074,7 @@
brush_jitter_pos(brush, pos, finalpos);
if (painter->cache.enabled)
- brush_painter_refresh_cache(painter, finalpos);
+ brush_painter_refresh_cache(painter, finalpos,
use_color_correction);
totpaintops += func(user, painter->cache.ibuf, pos,
finalpos);
@@ -1099,7 +1102,7 @@
brush_jitter_pos(brush, pos, finalpos);
if (painter->cache.enabled)
- brush_painter_refresh_cache(painter,
finalpos);
+ brush_painter_refresh_cache(painter,
finalpos, use_color_correction);
totpaintops +=
func(user, painter->cache.ibuf,
painter->lastmousepos, finalpos);
Modified: branches/soc-2011-onion/source/blender/blenlib/BLI_utildefines.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenlib/BLI_utildefines.h
2011-06-04 01:09:38 UTC (rev 37153)
+++ branches/soc-2011-onion/source/blender/blenlib/BLI_utildefines.h
2011-06-04 01:38:04 UTC (rev 37154)
@@ -104,11 +104,10 @@
#define FTOCHAR(val) ((val)<=0.0f)? 0 : (((val)>(1.0f-0.5f/255.0f))? 255 :
(char)((255.0f*(val))+0.5f))
#define FTOUSHORT(val) ((val >= 1.0f-0.5f/65535)? 65535: (val <= 0.0f)? 0:
(unsigned short)(val*65535.0f + 0.5f))
#define F3TOCHAR3(v2,v1) (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1]));
(v1)[2]=FTOCHAR((v2[2]))
-#define F3TOCHAR4(v2,v1) (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1]));
(v1)[2]=FTOCHAR((v2[2])); \
- (v1)[3]=FTOCHAR((v2[3]));
(v1)[3] = 255
-#define F4TOCHAR4(v2,v1) (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1]));
(v1)[2]=FTOCHAR((v2[2])); \
- (v1)[3]=FTOCHAR((v2[3]));
(v1)[3]=FTOCHAR((v2[3]))
-
+#define F3TOCHAR4(v2,v1) { (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1]));
(v1)[2]=FTOCHAR((v2[2])); \
+ (v1)[3]=FTOCHAR((v2[3]));
(v1)[3] = 255; }
+#define F4TOCHAR4(v2,v1) { (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1]));
(v1)[2]=FTOCHAR((v2[2])); \
+ (v1)[3]=FTOCHAR((v2[3]));
(v1)[3]=FTOCHAR((v2[3])); }
#define VECCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)=
*(v2+2);}
#define VECCOPY2D(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1);}
Modified:
branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c
2011-06-04 01:09:38 UTC (rev 37153)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c
2011-06-04 01:38:04 UTC (rev 37154)
@@ -3693,16 +3693,25 @@
}
}
-static void do_projectpaint_draw_f(ProjPaintState *ps, ProjPixel *projPixel,
float *rgba, float alpha, float mask) {
+static void do_projectpaint_draw_f(ProjPaintState *ps, ProjPixel *projPixel,
float *rgba, float alpha, float mask, int use_color_correction) {
if (ps->is_texbrush) {
- /*rgba already holds a texture result here from higher level function*/
- float rgba_br[3];
- srgb_to_linearrgb_v3_v3(rgba_br, ps->brush->rgb);
- mul_v3_v3(rgba, rgba_br);
+ /* rgba already holds a texture result here from higher level
function */
+ if(use_color_correction){
+ float rgba_br[3];
+ srgb_to_linearrgb_v3_v3(rgba_br, ps->brush->rgb);
+ mul_v3_v3(rgba, rgba_br);
+ }
+ else{
+ mul_v3_v3(rgba, ps->brush->rgb);
+ }
}
else {
- VECCOPY(rgba, ps->brush->rgb);
- srgb_to_linearrgb_v3_v3(rgba, rgba);
+ if(use_color_correction){
+ srgb_to_linearrgb_v3_v3(rgba, ps->brush->rgb);
+ }
+ else {
+ VECCOPY(rgba, ps->brush->rgb);
+ }
rgba[3] = 1.0;
}
@@ -3740,6 +3749,7 @@
float falloff;
int bucket_index;
int is_floatbuf = 0;
+ int use_color_correction = 0;
const short tool = ps->tool;
rctf bucket_bounds;
@@ -3845,6 +3855,7 @@
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;
}
last_partial_redraw_cell = last_projIma->partRedrawRect +
projPixel->bb_cell_index;
@@ -3875,7 +3886,7 @@
else
do_projectpaint_smear(ps, projPixel, alpha, mask, smearArena,
&smearPixels, co);
break;
default:
- if
(is_floatbuf) do_projectpaint_draw_f(ps, projPixel, rgba, alpha, mask);
+ if
(is_floatbuf) do_projectpaint_draw_f(ps, projPixel, rgba, alpha, mask,
use_color_correction);
else
do_projectpaint_draw(ps, projPixel, rgba, alpha, mask);
break;
}
@@ -3991,7 +4002,7 @@
// we may want to use this later
// brush_painter_require_imbuf(painter, ((ibuf->rect_float)? 1: 0), 0,
0);
- if (brush_painter_paint(painter, project_paint_op, pos, time, pressure,
ps)) {
+ if (brush_painter_paint(painter, project_paint_op, pos, time, pressure,
ps, 0)) {
return 1;
}
else return 0;
@@ -4412,7 +4423,7 @@
brush_painter_require_imbuf(painter, ((ibuf->rect_float)? 1: 0), 0, 0);
- if (brush_painter_paint(painter, imapaint_paint_op, pos, time,
pressure, s)) {
+ if (brush_painter_paint(painter, imapaint_paint_op, pos, time,
pressure, s, ibuf->profile == IB_PROFILE_LINEAR_RGB)) {
if (update)
imapaint_image_update(s->sima, image, ibuf, texpaint);
return 1;
Modified: branches/soc-2011-onion/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- branches/soc-2011-onion/source/blender/gpu/intern/gpu_draw.c
2011-06-04 01:09:38 UTC (rev 37153)
+++ branches/soc-2011-onion/source/blender/gpu/intern/gpu_draw.c
2011-06-04 01:38:04 UTC (rev 37154)
@@ -734,16 +734,10 @@
IMB_rect_from_float(ibuf);
}
else {
- /*Do partial drawing. 'buffer' holds only the changed part.
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs