diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2013-01-13 22:10:30 +0000 |
|---|---|---|
| committer | Johan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl> | 2013-01-13 22:10:30 +0000 |
| commit | f591cdba110df5277fd1fee83b4b2d53efa03e3b (patch) | |
| tree | 01e7435c5f6c5966ad8b613daa3c052a9f4ab48c | |
| parent | Fix deprecated pointer grabbing in gimpcolorwheel (diff) | |
| download | inkscape-f591cdba110df5277fd1fee83b4b2d53efa03e3b.tar.gz inkscape-f591cdba110df5277fd1fee83b4b2d53efa03e3b.zip | |
make grayscale viewmode color factors configurable.
(bzr r12022)
| -rw-r--r-- | src/desktop.cpp | 14 | ||||
| -rw-r--r-- | src/display/drawing.cpp | 29 | ||||
| -rw-r--r-- | src/display/drawing.h | 5 |
3 files changed, 34 insertions, 14 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp index a3f607913..ea23ebb9c 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -433,6 +433,20 @@ void SPDesktop::_setDisplayMode(Inkscape::RenderMode mode) { _widget->setTitle( sp_desktop_document(this)->getName() ); } void SPDesktop::_setDisplayColorMode(Inkscape::ColorMode mode) { + // reload grayscale matrix from prefs + if (mode == Inkscape::COLORMODE_GRAYSCALE) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gdouble r = prefs->getDoubleLimited("/options/rendering/grayscale/red-factor",0.21,0.,1.); + gdouble g = prefs->getDoubleLimited("/options/rendering/grayscale/green-factor",0.72,0.,1.); + gdouble b = prefs->getDoubleLimited("/options/rendering/grayscale/blue-factor",0.072,0.,1.); + gdouble grayscale_value_matrix[20] = { r, g, b, 0, 0, + r, g, b, 0, 0, + r, g, b, 0, 0, + 0, 0, 0, 1, 0 }; + g_message("%g",grayscale_value_matrix[0]); + SP_CANVAS_ARENA (drawing)->drawing.setGrayscaleMatrix(grayscale_value_matrix); + } + SP_CANVAS_ARENA (drawing)->drawing.setColorMode(mode); canvas->colorrendermode = mode; _display_color_mode = mode; diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp index 171cc014f..ed56b1617 100644 --- a/src/display/drawing.cpp +++ b/src/display/drawing.cpp @@ -16,16 +16,24 @@ #include "nr-filter-types.h" //grayscale colormode: -#include "nr-filter-colormatrix.h" #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) + , _grayscale_colormatrix(std::vector<gdouble> (grayscale_value_matrix, grayscale_value_matrix + 20 )) , delta(0) , _exact(false) , _rendermode(RENDERMODE_NORMAL) @@ -143,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) { @@ -152,17 +166,6 @@ 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) { @@ -174,7 +177,7 @@ Drawing::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags) // 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); + 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); diff --git a/src/display/drawing.h b/src/display/drawing.h index 8154f0783..74ab57fae 100644 --- a/src/display/drawing.h +++ b/src/display/drawing.h @@ -20,7 +20,7 @@ #include <2geom/rect.h> #include "display/drawing-item.h" #include "display/rendermode.h" - +#include "nr-filter-colormatrix.h" typedef struct _SPCanvasArena SPCanvasArena; @@ -65,6 +65,8 @@ public: OutlineColors const &colors() const { return _colors; } + void setGrayscaleMatrix(gdouble value_matrix[20]); + void update(Geom::IntRect const &area = Geom::IntRect::infinite(), UpdateContext const &ctx = UpdateContext(), unsigned flags = DrawingItem::STATE_ALL, unsigned reset = 0); void render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags = 0); DrawingItem *pick(Geom::Point const &p, double delta, unsigned flags); @@ -97,6 +99,7 @@ private: size_t _cache_budget; ///< maximum allowed size of cache OutlineColors _colors; + Filters::FilterColorMatrix::ColorMatrixMatrix _grayscale_colormatrix; SPCanvasArena *_canvasarena; // may be NULL is this arena is not the screen // but used for export etc. |
