diff options
| author | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
| commit | 5a4fb2325f60d292b47330f540b26a3279341c90 (patch) | |
| tree | d2aa7967be25450b83e625025366c618101ae49f /src/display/drawing.cpp | |
| parent | The Polar Arrange Tab of the Arrange Dialog now hides the parametric (diff) | |
| parent | Remove Snap menu item and improve grid menu item text (diff) | |
| download | inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.tar.gz inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.zip | |
Commit a merge to trunk, with probabal errors
(bzr r11073.1.36)
Diffstat (limited to 'src/display/drawing.cpp')
| -rw-r--r-- | src/display/drawing.cpp | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp index 77f24caf3..6e728b03d 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) { @@ -146,10 +167,24 @@ Drawing::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned fl } void -Drawing::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags) +Drawing::render(DrawingContext &dc, Geom::IntRect const &area, unsigned flags) { if (_root) { - _root->render(ct, area, flags); + _root->render(dc, area, flags); + } + + if (colorMode() == COLORMODE_GRAYSCALE) { + // apply grayscale filter on top of everything + cairo_surface_t *input = dc.rawTarget(); + cairo_surface_t *out = ink_cairo_surface_create_identical(input); + ink_cairo_surface_filter(input, out, _grayscale_colormatrix); + Geom::Point origin = dc.targetLogicalBounds().min(); + dc.setSource(out, origin[Geom::X], origin[Geom::Y]); + dc.setOperator(CAIRO_OPERATOR_SOURCE); + dc.paint(); + dc.setOperator(CAIRO_OPERATOR_OVER); + + cairo_surface_destroy(out); } } |
