diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2012-12-13 22:17:51 +0000 |
|---|---|---|
| committer | Johan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl> | 2012-12-13 22:17:51 +0000 |
| commit | ed8bc9e004c3f0fc7aed2459b70e183012d9cdc9 (patch) | |
| tree | f07723280e82c308e60ac41f772d1d305ab12caa /src/display/drawing.cpp | |
| parent | Migrate document metadata from NotbookPage to Gtk::Grid and drop dead code (diff) | |
| download | inkscape-ed8bc9e004c3f0fc7aed2459b70e183012d9cdc9.tar.gz inkscape-ed8bc9e004c3f0fc7aed2459b70e183012d9cdc9.zip | |
re-add Grayscale color mode
Fixed bugs:
- https://launchpad.net/bugs/885048
(bzr r11953)
Diffstat (limited to 'src/display/drawing.cpp')
| -rw-r--r-- | src/display/drawing.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp index 77f24caf3..171cc014f 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,6 +15,12 @@ #include "nr-filter-gaussian.h" #include "nr-filter-types.h" +//grayscale colormode: +#include "nr-filter-colormatrix.h" +#include "cairo-templates.h" +#include "drawing-context.h" + + namespace Inkscape { Drawing::Drawing(SPCanvasArena *arena) @@ -145,12 +152,37 @@ Drawing::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned fl _pickItemsForCaching(); } +// hardcoded grayscale color matrix values. could be turned into preference settings in future. +static const gdouble grayscale_value_matrix[] = { + 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 +}; +static Filters::FilterColorMatrix::ColorMatrixMatrix grayscale_colormatrix( + std::vector<gdouble> (grayscale_value_matrix, grayscale_value_matrix + sizeof(grayscale_value_matrix) / sizeof(grayscale_value_matrix[0]) ) +); + void 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 * |
