From a9016bc7deeacce3ff8d44d2d09ec512dc662445 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 19 Jan 2013 22:54:44 -0800 Subject: Fix multiple instances of ci_key. (bzr r12045) --- src/display/cairo-utils.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 692e31837..9655fc194 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -27,6 +27,17 @@ #include "style.h" #include "helper/geom-curves.h" +namespace { + +/** + * Key for cairo_surface_t to keep track of current color interpolation value + * Only the address of the structure is used, it is never initialized. See: + * http://www.cairographics.org/manual/cairo-Types.html#cairo-user-data-key-t + */ +cairo_user_data_key_t ci_key; + +} // namespace + namespace Inkscape { CairoGroup::CairoGroup(cairo_t *_ct) : ct(_ct), pushed(false) {} -- cgit v1.2.3 From 7900b2459ca0a6f6e11a367443046582c4852752 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 29 Jan 2013 15:23:22 +0100 Subject: Filter color values always defined as sRGB (or ICC). (bzr r12070) --- src/display/cairo-utils.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 9655fc194..831b37899 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -597,6 +597,15 @@ void ink_cairo_surface_average_color_premul(cairo_surface_t *surface, double &r, a = CLAMP(a, 0.0, 1.0); } +void srgb_to_linear( double* c ) { + + if( *c < 0.04045 ) { + *c /= 12.92; + } else { + *c = pow( (*c+0.055)/1.055, 2.4 ); + } +} + void srgb_to_linear( guint32* c, guint32 a ) { *c = unpremul_alpha( *c, a ); -- cgit v1.2.3 From a7c6061c0b32affc13bfb818161ca7fc002ef210 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Wed, 30 Jan 2013 21:47:35 +0100 Subject: code cleanup. don't use pointers when you don't have to. use const whereever you can. (bzr r12077) --- src/display/cairo-utils.cpp | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 831b37899..8eeee0277 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -597,20 +597,11 @@ void ink_cairo_surface_average_color_premul(cairo_surface_t *surface, double &r, a = CLAMP(a, 0.0, 1.0); } -void srgb_to_linear( double* c ) { +static guint32 srgb_to_linear( const guint32 c, const guint32 a ) { - if( *c < 0.04045 ) { - *c /= 12.92; - } else { - *c = pow( (*c+0.055)/1.055, 2.4 ); - } -} - -void srgb_to_linear( guint32* c, guint32 a ) { - - *c = unpremul_alpha( *c, a ); + const guint32 c1 = unpremul_alpha( c, a ); - double cc = *c/255.0; + double cc = c1/255.0; if( cc < 0.04045 ) { cc /= 12.92; @@ -619,16 +610,16 @@ void srgb_to_linear( guint32* c, guint32 a ) { } cc *= 255.0; - *c = (int)cc; + const guint32 c2 = (int)cc; - *c = premul_alpha( *c, a ); + return premul_alpha( c2, a ); } -void linear_to_srgb( guint32* c, guint32 a ) { +static guint32 linear_to_srgb( const guint32 c, const guint32 a ) { - *c = unpremul_alpha( *c, a ); + const guint32 c1 = unpremul_alpha( c, a ); - double cc = *c/255.0; + double cc = c1/255.0; if( cc < 0.0031308 ) { cc *= 12.92; @@ -637,9 +628,9 @@ void linear_to_srgb( guint32* c, guint32 a ) { } cc *= 255.0; - *c = (int)cc; + const guint32 c2 = (int)cc; - *c = premul_alpha( *c, a ); + return premul_alpha( c2, a ); } int ink_cairo_surface_srgb_to_linear(cairo_surface_t *surface) @@ -656,9 +647,9 @@ int ink_cairo_surface_srgb_to_linear(cairo_surface_t *surface) guint32 px = *reinterpret_cast(data + 4*x); EXTRACT_ARGB32(px, a,r,g,b) ; // Unneeded semi-colon for indenting if( a != 0 ) { - srgb_to_linear( &r, a ); - srgb_to_linear( &g, a ); - srgb_to_linear( &b, a ); + r = srgb_to_linear( r, a ); + g = srgb_to_linear( g, a ); + b = srgb_to_linear( b, a ); } ASSEMBLE_ARGB32(px2, a,r,g,b); *reinterpret_cast(data + 4*x) = px2; @@ -681,9 +672,9 @@ int ink_cairo_surface_linear_to_srgb(cairo_surface_t *surface) guint32 px = *reinterpret_cast(data + 4*x); EXTRACT_ARGB32(px, a,r,g,b) ; // Unneeded semi-colon for indenting if( a != 0 ) { - linear_to_srgb( &r, a ); - linear_to_srgb( &g, a ); - linear_to_srgb( &b, a ); + r = linear_to_srgb( r, a ); + g = linear_to_srgb( g, a ); + b = linear_to_srgb( b, a ); } ASSEMBLE_ARGB32(px2, a,r,g,b); *reinterpret_cast(data + 4*x) = px2; -- cgit v1.2.3