summaryrefslogtreecommitdiffstats
path: root/src/display/cairo-utils.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2013-02-06 08:19:53 +0000
committerJabiertxo Arraiza Cenoz <jtx@jtx.marker.es>2013-02-06 08:19:53 +0000
commit549a79b5367ffd259a23fbd18e93199d1c0149b7 (patch)
tree9c4ce4a0217afa63b59f32d02a60b848f43a9520 /src/display/cairo-utils.cpp
parentMerge from branch (diff)
parentSupress Pango error message. (diff)
downloadinkscape-549a79b5367ffd259a23fbd18e93199d1c0149b7.tar.gz
inkscape-549a79b5367ffd259a23fbd18e93199d1c0149b7.zip
Merge from branch
(bzr r11950.1.19)
Diffstat (limited to 'src/display/cairo-utils.cpp')
-rw-r--r--src/display/cairo-utils.cpp43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp
index 692e31837..8eeee0277 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) {}
@@ -586,11 +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( guint32* c, guint32 a ) {
+static guint32 srgb_to_linear( 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.04045 ) {
cc /= 12.92;
@@ -599,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;
@@ -617,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)
@@ -636,9 +647,9 @@ int ink_cairo_surface_srgb_to_linear(cairo_surface_t *surface)
guint32 px = *reinterpret_cast<guint32*>(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<guint32*>(data + 4*x) = px2;
@@ -661,9 +672,9 @@ int ink_cairo_surface_linear_to_srgb(cairo_surface_t *surface)
guint32 px = *reinterpret_cast<guint32*>(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<guint32*>(data + 4*x) = px2;