summaryrefslogtreecommitdiffstats
path: root/src/display/drawing.cpp
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-03-29 23:52:42 +0000
committerMarkus Engel <markus.engel@tum.de>2013-03-29 23:52:42 +0000
commita168040d5a452544328a1e6ad35aaac351f94d44 (patch)
treefae1ba829f543a473da281bd5fa6e4deabbf6912 /src/display/drawing.cpp
parentRemoved function pointers from SPObject and subclasses. (diff)
parentDutch translation update (diff)
downloadinkscape-a168040d5a452544328a1e6ad35aaac351f94d44.tar.gz
inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.zip
merged from trunk
(bzr r11608.1.56)
Diffstat (limited to 'src/display/drawing.cpp')
-rw-r--r--src/display/drawing.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp
index 77f24caf3..c192e4565 100644
--- a/src/display/drawing.cpp
+++ b/src/display/drawing.cpp
@@ -4,8 +4,9 @@
*//*
* Authors:
* Krzysztof KosiƄski <tweenk.pl@gmail.com>
+ * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
*
- * Copyright (C) 2011 Authors
+ * Copyright (C) 2011-2012 Authors
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -14,8 +15,21 @@
#include "nr-filter-gaussian.h"
#include "nr-filter-types.h"
+//grayscale colormode:
+#include "cairo-templates.h"
+#include "drawing-context.h"
+
+
namespace Inkscape {
+// hardcoded grayscale color matrix values as default
+static const gdouble grayscale_value_matrix[20] = {
+ 0.21, 0.72, 0.072, 0, 0,
+ 0.21, 0.72, 0.072, 0, 0,
+ 0.21, 0.72, 0.072, 0, 0,
+ 0 , 0 , 0 , 1, 0
+};
+
Drawing::Drawing(SPCanvasArena *arena)
: _root(NULL)
, outlinecolor(0x000000ff)
@@ -27,6 +41,7 @@ Drawing::Drawing(SPCanvasArena *arena)
, _filter_quality(Filters::FILTER_QUALITY_BEST)
, _cache_score_threshold(50000.0)
, _cache_budget(0)
+ , _grayscale_colormatrix(std::vector<gdouble> (grayscale_value_matrix, grayscale_value_matrix + 20 ))
, _canvasarena(arena)
{
@@ -136,6 +151,12 @@ Drawing::setCacheBudget(size_t bytes)
}
void
+Drawing::setGrayscaleMatrix(gdouble value_matrix[20]) {
+ _grayscale_colormatrix = Filters::FilterColorMatrix::ColorMatrixMatrix(
+ std::vector<gdouble> (value_matrix, value_matrix + 20) );
+}
+
+void
Drawing::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned flags, unsigned reset)
{
if (_root) {
@@ -151,6 +172,20 @@ Drawing::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags)
if (_root) {
_root->render(ct, area, flags);
}
+
+ if (colorMode() == COLORMODE_GRAYSCALE) {
+ // apply grayscale filter on top of everything
+ cairo_surface_t *input = ct.rawTarget();
+ cairo_surface_t *out = ink_cairo_surface_create_identical(input);
+ ink_cairo_surface_filter(input, out, _grayscale_colormatrix);
+ Geom::Point origin = ct.targetLogicalBounds().min();
+ ct.setSource(out, origin[Geom::X], origin[Geom::Y]);
+ ct.setOperator(CAIRO_OPERATOR_SOURCE);
+ ct.paint();
+ ct.setOperator(CAIRO_OPERATOR_OVER);
+
+ cairo_surface_destroy(out);
+ }
}
DrawingItem *