diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop.cpp | 22 | ||||
| -rw-r--r-- | src/desktop.h | 17 | ||||
| -rw-r--r-- | src/display/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/display/grayscale.cpp | 91 | ||||
| -rw-r--r-- | src/display/grayscale.h | 40 | ||||
| -rw-r--r-- | src/display/nr-arena-glyphs.cpp | 14 | ||||
| -rw-r--r-- | src/display/nr-arena-item.cpp | 2 | ||||
| -rw-r--r-- | src/display/nr-arena-shape.cpp | 14 | ||||
| -rw-r--r-- | src/display/nr-arena.cpp | 3 | ||||
| -rw-r--r-- | src/display/nr-arena.h | 1 | ||||
| -rw-r--r-- | src/display/rendermode.h | 9 | ||||
| -rw-r--r-- | src/display/sp-canvas.h | 1 | ||||
| -rw-r--r-- | src/interface.cpp | 59 | ||||
| -rw-r--r-- | src/menus-skeleton.h | 8 | ||||
| -rw-r--r-- | src/sp-gradient.cpp | 50 | ||||
| -rw-r--r-- | src/sp-gradient.h | 2 | ||||
| -rw-r--r-- | src/sp-pattern.cpp | 12 | ||||
| -rw-r--r-- | src/verbs.cpp | 25 | ||||
| -rw-r--r-- | src/verbs.h | 5 | ||||
| -rw-r--r-- | src/widgets/desktop-widget.cpp | 32 |
20 files changed, 344 insertions, 65 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp index b5e7cdd33..f132ec897 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -154,6 +154,7 @@ SPDesktop::SPDesktop() : _layer_hierarchy( 0 ), _reconstruction_old_layer_id( 0 ), _display_mode(Inkscape::RENDERMODE_NORMAL), + _display_color_mode(Inkscape::COLORRENDERMODE_NORMAL), _widget( 0 ), _inkscape( 0 ), _guides_message_context( 0 ), @@ -454,6 +455,13 @@ void SPDesktop::_setDisplayMode(Inkscape::RenderMode mode) { sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (main), _d2w); // redraw _widget->setTitle( sp_desktop_document(this)->getName() ); } +void SPDesktop::_setDisplayColorMode(Inkscape::ColorRenderMode mode) { + SP_CANVAS_ARENA (drawing)->arena->colorrendermode = mode; + canvas->colorrendermode = mode; + _display_color_mode = mode; + sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (main), _d2w); // redraw + _widget->setTitle( sp_desktop_document(this)->getName() ); +} void SPDesktop::displayModeToggle() { switch (_display_mode) { @@ -466,11 +474,23 @@ void SPDesktop::displayModeToggle() { case Inkscape::RENDERMODE_OUTLINE: _setDisplayMode(Inkscape::RENDERMODE_NORMAL); break; -// case Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW: default: _setDisplayMode(Inkscape::RENDERMODE_NORMAL); } } +void SPDesktop::displayColorModeToggle() { + switch (_display_color_mode) { + case Inkscape::COLORRENDERMODE_NORMAL: + _setDisplayColorMode(Inkscape::COLORRENDERMODE_GRAYSCALE); + break; + case Inkscape::COLORRENDERMODE_GRAYSCALE: + _setDisplayColorMode(Inkscape::COLORRENDERMODE_NORMAL); + break; +// case Inkscape::COLORRENDERMODE_PRINT_COLORS_PREVIEW: + default: + _setDisplayColorMode(Inkscape::COLORRENDERMODE_NORMAL); + } +} /** * Returns current root (=bottom) layer. diff --git a/src/desktop.h b/src/desktop.h index 8f89df418..4fdc0b98b 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -206,13 +206,24 @@ public: void setDisplayModeOutline() { _setDisplayMode(Inkscape::RENDERMODE_OUTLINE); } -// void setDisplayModePrintColorsPreview() { -// _setDisplayMode(Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW); -// } void displayModeToggle(); Inkscape::RenderMode _display_mode; Inkscape::RenderMode getMode() const { return _display_mode; } + void _setDisplayColorMode(Inkscape::ColorRenderMode mode); + void setDisplayColorModeNormal() { + _setDisplayColorMode(Inkscape::COLORRENDERMODE_NORMAL); + } + void setDisplayColorModeGrayscale() { + _setDisplayColorMode(Inkscape::COLORRENDERMODE_GRAYSCALE); + } +// void setDisplayColorModePrintColorsPreview() { +// _setDisplayColorMode(Inkscape::COLORRENDERMODE_PRINT_COLORS_PREVIEW); +// } + void displayColorModeToggle(); + Inkscape::ColorRenderMode _display_color_mode; + Inkscape::ColorRenderMode getColorMode() const { return _display_color_mode; } + Inkscape::UI::Widget::Dock* getDock() { return _widget->getDock(); } void set_active (bool new_active); diff --git a/src/display/Makefile_insert b/src/display/Makefile_insert index b50a71033..370e28d6d 100644 --- a/src/display/Makefile_insert +++ b/src/display/Makefile_insert @@ -37,6 +37,8 @@ ink_common_sources += \ display/curve.h \ display/gnome-canvas-acetate.cpp \ display/gnome-canvas-acetate.h \ + display/grayscale.cpp \ + display/grayscale.h \ display/guideline.cpp \ display/guideline.h \ display/nr-plain-stuff-gdk.cpp \ diff --git a/src/display/grayscale.cpp b/src/display/grayscale.cpp new file mode 100644 index 000000000..af3a781b0 --- /dev/null +++ b/src/display/grayscale.cpp @@ -0,0 +1,91 @@ +/** \file + * Provide methods to calculate grayscale values (e.g. convert rgba value to grayscale rgba value) + */ + +/* + * Author: + * Johan Engelen <goejendaagh@zonnet.nl> + * + * Copyright (C) 2011 Author + * + * Released under GNU GPL + */ + +#include "display/grayscale.h" +#include "color.h" + +// for activeDesktopIsGrayscale: +#include "display/rendermode.h" +#include "inkscape.h" +#include "desktop.h" + +namespace Grayscale { + +guint32 process(guint32 rgba) { + return process(SP_RGBA32_R_U(rgba), SP_RGBA32_G_U(rgba), SP_RGBA32_B_U(rgba), SP_RGBA32_A_U(rgba)); +} + +guint32 process(guchar r, guchar g, guchar b, guchar a) { + float red_factor = 0.3; + float green_factor = 0.59; + float blue_factor = 0.11; + + /** To reduce banding in gradients, this calculation is tweaked a bit + * by outputing blue+1 or red+1 or both. The luminance is calculated + * times 4. Then last two bits are used to determine if red and/or blue + * can be increased by one. Then these two bits are discarded. + * So the output color it still looks gray, but has more than 256 steps. + * The assumption is that the eye is most sensitive to green, then red, then blue. + * (hope this trick works :-) Johan) + */ + + guint32 luminance = ( red_factor * (r << 3) + + green_factor * (g << 3) + + blue_factor * (b << 3) ); + unsigned blue_plus_one = (luminance & 0x01) ? 1 : 0; + unsigned red_plus_one = (luminance & 0x02) ? 1 : 0; + unsigned green_plus_one = (luminance & 0x04) ? 1 : 0; + luminance = luminance >> 3; + + if (luminance >= 0xff) { + return SP_RGBA32_U_COMPOSE(0xff, 0xff, 0xff, a); + } else { + return SP_RGBA32_U_COMPOSE(luminance + red_plus_one, luminance + green_plus_one, luminance + blue_plus_one, a); + } +} + +guchar luminance(guchar r, guchar g, guchar b) { + guint32 luminance = ( red_factor * r + + green_factor * g + + blue_factor * b ); + if (luminance > 0xff) { + luminance = 0xff; + } + + return luminance & 0xff; +} + +/** @brief Use this method if there is no other way to find out if grayscale view or not + * + * In some cases, the choice between normal or grayscale is so deep in the code hierarchy, + * that it is not possible to determine whether grayscale is desired or not, without using + * the global SP_ACTIVE_DESKTOP macro. Then use this method, so we know where the abuse is + * happening... + */ +bool activeDesktopIsGrayscale() { + return (SP_ACTIVE_DESKTOP->getColorMode() == Inkscape::COLORRENDERMODE_GRAYSCALE); +} + + +}; + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/display/grayscale.h b/src/display/grayscale.h new file mode 100644 index 000000000..855c9e465 --- /dev/null +++ b/src/display/grayscale.h @@ -0,0 +1,40 @@ +#ifndef SEEN_DISPLAY_GRAYSCALE_H +#define SEEN_DISPLAY_GRAYSCALE_H + +/** \file + * Provide methods to calculate grayscale values (e.g. convert rgba value to grayscale rgba value) + * + * Author: + * Johan Engelen <goejendaagh@zonnet.nl> + * + * Copyright (C) 2011 Author + * + * Released under GNU GPL + */ + +#include <gdk/gdktypes.h> + +namespace Grayscale { + guint32 process(guint32 rgba); + guint32 process(guchar r, guchar g, guchar b, guchar a); + guchar luminance(guchar r, guchar g, guchar b); + + const float red_factor = 0.3; + const float green_factor = 0.59; + const float blue_factor = 0.11; + + bool activeDesktopIsGrayscale(); +}; + +#endif /* !SEEN_DISPLAY_GRAYSCALE_H */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/display/nr-arena-glyphs.cpp b/src/display/nr-arena-glyphs.cpp index 440a87012..42bca7d94 100644 --- a/src/display/nr-arena-glyphs.cpp +++ b/src/display/nr-arena-glyphs.cpp @@ -24,6 +24,7 @@ #include "nr-arena-glyphs.h" #include <cairo.h> #include "inkscape-cairo.h" +#include "display/grayscale.h" #ifdef test_glyph_liv #include "../display/canvas-bpath.h" @@ -444,7 +445,8 @@ nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPi SPStyle const *style = ggroup->style; guint ret = item->state; - bool print_colors_preview = (item->arena->rendermode == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW); + bool print_colors_preview = (item->arena->colorrendermode == Inkscape::COLORRENDERMODE_PRINT_COLORS_PREVIEW); + bool grayscale = (item->arena->colorrendermode == Inkscape::COLORRENDERMODE_GRAYSCALE); if (item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE) { @@ -513,8 +515,11 @@ nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPi rgba = style->fill.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->fill_opacity.value) ); } - if (print_colors_preview) + if (print_colors_preview) { nr_arena_separate_color_plates(&rgba); + } else if (grayscale) { + rgba = Grayscale::process(rgba); + } nr_blit_pixblock_mask_rgba32(pb, &m, rgba); pb->empty = FALSE; @@ -557,8 +562,11 @@ nr_arena_glyphs_group_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPi rgba = style->stroke.value.color.toRGBA32( SP_SCALE24_TO_FLOAT(style->stroke_opacity.value) ); } - if (print_colors_preview) + if (print_colors_preview) { nr_arena_separate_color_plates(&rgba); + } else if (grayscale) { + rgba = Grayscale::process(rgba); + } nr_blit_pixblock_mask_rgba32(pb, &m, rgba); pb->empty = FALSE; diff --git a/src/display/nr-arena-item.cpp b/src/display/nr-arena-item.cpp index c74e2baa0..6a5b7b5ba 100644 --- a/src/display/nr-arena-item.cpp +++ b/src/display/nr-arena-item.cpp @@ -314,7 +314,7 @@ nr_arena_item_invoke_render (cairo_t *ct, NRArenaItem *item, NRRectL const *area bool outline = (item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE); bool filter = (item->arena->rendermode != Inkscape::RENDERMODE_OUTLINE && item->arena->rendermode != Inkscape::RENDERMODE_NO_FILTERS); - bool print_colors = (item->arena->rendermode == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW); + bool print_colors = (item->arena->colorrendermode == Inkscape::COLORRENDERMODE_PRINT_COLORS_PREVIEW); nr_return_val_if_fail (item != NULL, NR_ARENA_ITEM_STATE_INVALID); nr_return_val_if_fail (NR_IS_ARENA_ITEM (item), diff --git a/src/display/nr-arena-shape.cpp b/src/display/nr-arena-shape.cpp index 1f516c066..33a218e99 100644 --- a/src/display/nr-arena-shape.cpp +++ b/src/display/nr-arena-shape.cpp @@ -24,6 +24,7 @@ #include "display/nr-arena.h" #include "display/nr-arena-shape.h" #include "display/curve.h" +#include "display/grayscale.h" #include "libnr/nr-pixops.h" #include "libnr/nr-blit.h" #include "libnr/nr-convert2geom.h" @@ -843,7 +844,8 @@ nr_arena_shape_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock if (!shape->style) return item->state; bool outline = (NR_ARENA_ITEM(shape)->arena->rendermode == Inkscape::RENDERMODE_OUTLINE); - bool print_colors_preview = (NR_ARENA_ITEM(shape)->arena->rendermode == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW); + bool print_colors_preview = (NR_ARENA_ITEM(shape)->arena->colorrendermode == Inkscape::COLORRENDERMODE_PRINT_COLORS_PREVIEW); + bool grayscale = (NR_ARENA_ITEM(shape)->arena->colorrendermode == Inkscape::COLORRENDERMODE_GRAYSCALE); if (outline) { // cairo outline rendering @@ -903,8 +905,11 @@ nr_arena_shape_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock rgba = fill_color->toRGBA32( shape->_fill.opacity ); } - if (print_colors_preview) + if (print_colors_preview) { nr_arena_separate_color_plates(&rgba); + } else if (grayscale) { + rgba = Grayscale::process(rgba); + } nr_blit_pixblock_mask_rgba32(pb, &m, rgba); pb->empty = FALSE; @@ -944,8 +949,11 @@ nr_arena_shape_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock rgba = stroke_color->toRGBA32( shape->_stroke.opacity ); } - if (print_colors_preview) + if (print_colors_preview) { nr_arena_separate_color_plates(&rgba); + } else if (grayscale) { + rgba = Grayscale::process(rgba); + } nr_blit_pixblock_mask_rgba32(pb, &m, rgba); pb->empty = FALSE; diff --git a/src/display/nr-arena.cpp b/src/display/nr-arena.cpp index 85de5c119..837bc0d86 100644 --- a/src/display/nr-arena.cpp +++ b/src/display/nr-arena.cpp @@ -58,6 +58,7 @@ nr_arena_init (NRArena *arena) arena->delta = 0; // to be set by desktop from prefs arena->renderoffscreen = false; // use render values from preferences otherwise render exact arena->rendermode = Inkscape::RENDERMODE_NORMAL; // default is normal render + arena->colorrendermode = Inkscape::COLORRENDERMODE_NORMAL; // default is normal color arena->blurquality = BLUR_QUALITY_NORMAL; arena->filterquality = Inkscape::Filters::FILTER_QUALITY_NORMAL; arena->outlinecolor = 0xff; // black; to be set by desktop from bg color @@ -88,6 +89,7 @@ nr_arena_request_update (NRArena *arena, NRArenaItem *item) arena->blurquality = BLUR_QUALITY_BEST; arena->filterquality = Inkscape::Filters::FILTER_QUALITY_BEST; arena->rendermode = Inkscape::RENDERMODE_NORMAL; + arena->colorrendermode = Inkscape::COLORRENDERMODE_NORMAL; } if (aobject->callbacks) { @@ -119,6 +121,7 @@ nr_arena_request_render_rect (NRArena *arena, NRRectL *area) arena->blurquality = BLUR_QUALITY_BEST; arena->filterquality = Inkscape::Filters::FILTER_QUALITY_BEST; arena->rendermode = Inkscape::RENDERMODE_NORMAL; + arena->colorrendermode = Inkscape::COLORRENDERMODE_NORMAL; } if (aobject->callbacks && area && !nr_rect_l_test_empty_ptr(area)) { for (unsigned int i = 0; i < aobject->callbacks->length; i++) { diff --git a/src/display/nr-arena.h b/src/display/nr-arena.h index d2f9dc246..bd6c3029d 100644 --- a/src/display/nr-arena.h +++ b/src/display/nr-arena.h @@ -48,6 +48,7 @@ struct NRArena : public NRActiveObject { double delta; bool renderoffscreen; // if true then rendering must be exact Inkscape::RenderMode rendermode; + Inkscape::ColorRenderMode colorrendermode; int blurquality; // will be updated during update from preferences int filterquality; // will be updated during update from preferences diff --git a/src/display/rendermode.h b/src/display/rendermode.h index abcdb3db4..8fc022bfb 100644 --- a/src/display/rendermode.h +++ b/src/display/rendermode.h @@ -12,8 +12,13 @@ namespace Inkscape { enum RenderMode { RENDERMODE_NORMAL, RENDERMODE_NO_FILTERS, - RENDERMODE_OUTLINE, - RENDERMODE_PRINT_COLORS_PREVIEW + RENDERMODE_OUTLINE +}; + +enum ColorRenderMode { + COLORRENDERMODE_NORMAL, + COLORRENDERMODE_GRAYSCALE, + COLORRENDERMODE_PRINT_COLORS_PREVIEW }; } diff --git a/src/display/sp-canvas.h b/src/display/sp-canvas.h index 7ecbe0451..3a0b56585 100644 --- a/src/display/sp-canvas.h +++ b/src/display/sp-canvas.h @@ -143,6 +143,7 @@ struct SPCanvas { bool drawing_disabled; int rendermode; + int colorrendermode; #if ENABLE_LCMS bool enable_cms_display_adj; diff --git a/src/interface.cpp b/src/interface.cpp index 3c310b8d1..f69cd5673 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -640,44 +640,49 @@ static void taskToggled(GtkCheckMenuItem *menuitem, gpointer userData) /** - * \brief Callback function to update the status of the radio buttons in the View -> Display mode menu (Normal, No Filters, Outline) + * \brief Callback function to update the status of the radio buttons in the View -> Display mode menu (Normal, No Filters, Outline) and Color display mode */ static gboolean update_view_menu(GtkWidget *widget, GdkEventExpose */*event*/, gpointer user_data) { - SPAction *action = (SPAction *) user_data; - g_assert(action->id != NULL); + SPAction *action = (SPAction *) user_data; + g_assert(action->id != NULL); - Inkscape::UI::View::View *view = (Inkscape::UI::View::View *) g_object_get_data(G_OBJECT(widget), "view"); + Inkscape::UI::View::View *view = (Inkscape::UI::View::View *) g_object_get_data(G_OBJECT(widget), "view"); SPDesktop *dt = static_cast<SPDesktop*>(view); - Inkscape::RenderMode mode = dt->getMode(); - - bool new_state = false; - if (!strcmp(action->id, "ViewModeNormal")) { - new_state = mode == Inkscape::RENDERMODE_NORMAL; - } else if (!strcmp(action->id, "ViewModeNoFilters")) { - new_state = mode == Inkscape::RENDERMODE_NO_FILTERS; + Inkscape::RenderMode mode = dt->getMode(); + Inkscape::ColorRenderMode colormode = dt->getColorMode(); + + bool new_state = false; + if (!strcmp(action->id, "ViewModeNormal")) { + new_state = mode == Inkscape::RENDERMODE_NORMAL; + } else if (!strcmp(action->id, "ViewModeNoFilters")) { + new_state = mode == Inkscape::RENDERMODE_NO_FILTERS; } else if (!strcmp(action->id, "ViewModeOutline")) { - new_state = mode == Inkscape::RENDERMODE_OUTLINE; - } else if (!strcmp(action->id, "ViewModePrintColorsPreview")) { - new_state = mode == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW; + new_state = mode == Inkscape::RENDERMODE_OUTLINE; + } else if (!strcmp(action->id, "ViewColorModeNormal")) { + new_state = colormode == Inkscape::COLORRENDERMODE_NORMAL; + } else if (!strcmp(action->id, "ViewColorModeGrayscale")) { + new_state = colormode == Inkscape::COLORRENDERMODE_GRAYSCALE; + } else if (!strcmp(action->id, "ViewColorModePrintColorsPreview")) { + new_state = colormode == Inkscape::COLORRENDERMODE_PRINT_COLORS_PREVIEW; } else { - g_warning("update_view_menu does not handle this verb"); + g_warning("update_view_menu does not handle this verb"); } - if (new_state) { //only one of the radio buttons has to be activated; the others will automatically be deactivated - if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget))) { - // When the GtkMenuItem version of the "activate" signal has been emitted by a GtkRadioMenuItem, there is a second - // emission as the most recently active item is toggled to inactive. This is dealt with before the original signal is handled. - // This emission however should not invoke any actions, hence we block it here: - temporarily_block_actions = true; - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), TRUE); - temporarily_block_actions = false; - } - } - - return FALSE; + if (new_state) { //only one of the radio buttons has to be activated; the others will automatically be deactivated + if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget))) { + // When the GtkMenuItem version of the "activate" signal has been emitted by a GtkRadioMenuItem, there is a second + // emission as the most recently active item is toggled to inactive. This is dealt with before the original signal is handled. + // This emission however should not invoke any actions, hence we block it here: + temporarily_block_actions = true; + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), TRUE); + temporarily_block_actions = false; + } + } + + return FALSE; } void diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h index 924cc1989..f1b633865 100644 --- a/src/menus-skeleton.h +++ b/src/menus-skeleton.h @@ -112,6 +112,14 @@ static char const menus_skeleton[] = //" <verb verb-id=\"ViewModePrintColorsPreview\" radio=\"yes\"/>\n" //" <verb verb-id=\"DialogPrintColorsPreview\" />\n" " </submenu>\n" +" <submenu name=\"" N_("_Color display mode") "\">\n" +" <verb verb-id=\"ViewColorModeToggle\"/>\n" +" <verb verb-id=\"ViewColorModeNormal\" radio=\"yes\" default=\"yes\"/>\n" +" <verb verb-id=\"ViewColorModeGrayscale\" radio=\"yes\"/>\n" +// Better location in menu needs to be found +//" <verb verb-id=\"ViewColorModePrintColorsPreview\" radio=\"yes\"/>\n" +//" <verb verb-id=\"DialogPrintColorsPreview\" />\n" +" </submenu>\n" " <separator/>\n" " <verb verb-id=\"ToggleGrid\" />\n" " <verb verb-id=\"ToggleGuides\" />\n" diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp index ad422a6ca..830e12f53 100644 --- a/src/sp-gradient.cpp +++ b/src/sp-gradient.cpp @@ -48,6 +48,7 @@ #include "uri.h" #include "xml/repr.h" #include "style.h" +#include "display/grayscale.h" #define SP_MACROS_SILENT #include "macros.h" @@ -1120,6 +1121,7 @@ void SPGradient::rebuildVector() /** * The gradient's color array is newly created and set up from vector. + * Also, the gradient's color_grayscale is created. */ void SPGradient::ensureColors() { @@ -1132,6 +1134,9 @@ void SPGradient::ensureColors() if (!color) { color = g_new(guchar, 4 * NCOLORS); } + if (!color_grayscale) { + color_grayscale = g_new(guchar, 4 * NCOLORS); + } // This assumes that vector is a zero-order B-spline (box function) approximation of the "true" gradient. // This means that the "true" gradient must be prefiltered using a zero order B-spline and then sampled. @@ -1260,6 +1265,15 @@ void SPGradient::ensureColors() color[3] = color[4 * (NCOLORS-1) + 3] = (unsigned char) floor(255*(remainder[3]+remainder_for_end[3]) + .5); break; } + + // Fill color_grayscale array + for (unsigned j = 0; j < NCOLORS; j++) { + guint32 rgba = Grayscale::process(color[4 * j + 0], color[4 * j + 1], color[4 * j + 2], color[4 * j + 3]); + color_grayscale[4 * j + 0] = SP_RGBA32_R_U(rgba); + color_grayscale[4 * j + 1] = SP_RGBA32_G_U(rgba); + color_grayscale[4 * j + 2] = SP_RGBA32_B_U(rgba); + color_grayscale[4 * j + 3] = SP_RGBA32_A_U(rgba); + } } /** @@ -1290,13 +1304,25 @@ sp_gradient_render_vector_line_rgba(SPGradient *const gradient, guchar *buf, gint idx = (pos * 1024 << 8) / span; gint didx = (1024 << 8) / span; - for (gint x = 0; x < len; x++) { - /// \todo Can this be done with 4 byte copies? - *buf++ = gradient->color[4 * (idx >> 8)]; - *buf++ = gradient->color[4 * (idx >> 8) + 1]; - *buf++ = gradient->color[4 * (idx >> 8) + 2]; - *buf++ = gradient->color[4 * (idx >> 8) + 3]; - idx += didx; + bool grayscale = false; // this rendering is for UI items, like the gradient edit dialog + if (grayscale) { + for (gint x = 0; x < len; x++) { + guchar luminance = Grayscale::luminance( gradient->color[4 * (idx >> 8)], gradient->color[4 * (idx >> 8) + 1], gradient->color[4 * (idx >> 8) + 2] ); + *buf++ = luminance; + *buf++ = luminance; + *buf++ = luminance; + *buf++ = gradient->color[4 * (idx >> 8) + 3]; + idx += didx; + } + } else { + for (gint x = 0; x < len; x++) { + /// \todo Can this be done with 4 byte copies? + *buf++ = gradient->color[4 * (idx >> 8)]; + *buf++ = gradient->color[4 * (idx >> 8) + 1]; + *buf++ = gradient->color[4 * (idx >> 8) + 2]; + *buf++ = gradient->color[4 * (idx >> 8) + 3]; + idx += didx; + } } } @@ -1702,6 +1728,11 @@ sp_lg_fill(SPPainter *painter, NRPixBlock *pb) if (lgp->lg->color == NULL) { lgp->lg->ensureColors(); + } + bool grayscale = Grayscale::activeDesktopIsGrayscale(); // TODO: find good way to access the current rendermode + if (grayscale) { + lgp->lgr.vector = lgp->lg->color_grayscale; + } else { lgp->lgr.vector = lgp->lg->color; } @@ -1981,6 +2012,11 @@ sp_rg_fill(SPPainter *painter, NRPixBlock *pb) if (rgp->rg->color == NULL) { rgp->rg->ensureColors(); + } + bool grayscale = Grayscale::activeDesktopIsGrayscale(); // TODO: find good way to access the current rendermode + if (grayscale) { + rgp->rgr.vector = rgp->rg->color_grayscale; + } else { rgp->rgr.vector = rgp->rg->color; } diff --git a/src/sp-gradient.h b/src/sp-gradient.h index b727c38ac..f670cd451 100644 --- a/src/sp-gradient.h +++ b/src/sp-gradient.h @@ -101,6 +101,8 @@ public: /** Rendered color array (4 * 1024 bytes) */ guchar *color; + /** Rendered color array in grayscale (for grayscale viewmode) (4 * 1024 bytes) */ + guchar *color_grayscale; sigc::connection modified_connection; diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index cd2e706f0..9ea0ef891 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -30,6 +30,7 @@ #include "uri.h" #include "sp-pattern.h" #include "xml/repr.h" +#include "display/grayscale.h" #include <sigc++/functors/ptr_fun.h> #include <sigc++/adaptors/bind.h> @@ -915,10 +916,12 @@ sp_pat_fill (SPPainter *painter, NRPixBlock *pb) if (pattern_width (pp->pat) < NR_EPSILON) return; if (pattern_height (pp->pat) < NR_EPSILON) return; + bool grayscale = Grayscale::activeDesktopIsGrayscale(); // TODO: find good way to access the current rendermode + /* Find buffer area in gradient space */ /* fixme: This is suboptimal (Lauris) */ - if ( pp->use_cached_tile ) { + if ( !grayscale && pp->use_cached_tile ) { double pat_w=pattern_width (pp->pat); double pat_h=pattern_height (pp->pat); if ( pb->mode == NR_PIXBLOCK_MODE_R8G8B8A8N || pb->mode == NR_PIXBLOCK_MODE_R8G8B8A8P ) { // same thing because it's filling an empty pixblock @@ -1031,8 +1034,13 @@ sp_pat_fill (SPPainter *painter, NRPixBlock *pb) // fixme: (Lauris) nr_pixblock_setup_extern (&ppb, pb->mode, area.x0, area.y0, area.x1, area.y1, NR_PIXBLOCK_PX (pb), pb->rs, FALSE, FALSE); + Inkscape::ColorRenderMode saved_colormode = pp->root->arena->colorrendermode; + if (grayscale) { + pp->root->arena->colorrendermode = Inkscape::COLORRENDERMODE_GRAYSCALE; + } nr_arena_item_invoke_render (NULL, pp->root, &area, &ppb, 0); - + pp->root->arena->colorrendermode = saved_colormode; + nr_pixblock_release (&ppb); } } diff --git a/src/verbs.cpp b/src/verbs.cpp index 33c52706b..55f5fd8d5 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1715,12 +1715,21 @@ ZoomVerb::perform(SPAction *action, void *data, void */*pdata*/) case SP_VERB_VIEW_MODE_OUTLINE: dt->setDisplayModeOutline(); break; -// case SP_VERB_VIEW_MODE_PRINT_COLORS_PREVIEW: -// dt->setDisplayModePrintColorsPreview(); -// break; case SP_VERB_VIEW_MODE_TOGGLE: dt->displayModeToggle(); break; + case SP_VERB_VIEW_COLOR_MODE_NORMAL: + dt->setDisplayColorModeNormal(); + break; + case SP_VERB_VIEW_COLOR_MODE_GRAYSCALE: + dt->setDisplayColorModeGrayscale(); + break; +// case SP_VERB_VIEW_COLOR_MODE_PRINT_COLORS_PREVIEW: +// dt->setDisplayColorModePrintColorsPreview(); +// break; + case SP_VERB_VIEW_COLOR_MODE_TOGGLE: + dt->displayColorModeToggle(); + break; case SP_VERB_VIEW_CMS_TOGGLE: dt->toggleColorProfAdjust(); break; @@ -2602,10 +2611,16 @@ Verb *Verb::_base_verbs[] = { N_("Switch to normal display without filters"), NULL), new ZoomVerb(SP_VERB_VIEW_MODE_OUTLINE, "ViewModeOutline", N_("_Outline"), N_("Switch to outline (wireframe) display mode"), NULL), -// new ZoomVerb(SP_VERB_VIEW_MODE_PRINT_COLORS_PREVIEW, "ViewModePrintColorsPreview", N_("_Print Colors Preview"), -// N_("Switch to print colors preview mode"), NULL), new ZoomVerb(SP_VERB_VIEW_MODE_TOGGLE, "ViewModeToggle", N_("_Toggle"), N_("Toggle between normal and outline display modes"), NULL), + new ZoomVerb(SP_VERB_VIEW_COLOR_MODE_NORMAL, "ViewColorModeNormal", N_("_Normal"), + N_("Switch to normal color display mode"), NULL), + new ZoomVerb(SP_VERB_VIEW_COLOR_MODE_GRAYSCALE, "ViewColorModeGrayscale", N_("_Grayscale"), + N_("Switch to grayscale display mode"), NULL), +// new ZoomVerb(SP_VERB_VIEW_COLOR_MODE_PRINT_COLORS_PREVIEW, "ViewColorModePrintColorsPreview", N_("_Print Colors Preview"), +// N_("Switch to print colors preview mode"), NULL), + new ZoomVerb(SP_VERB_VIEW_COLOR_MODE_TOGGLE, "ViewColorModeToggle", N_("_Toggle"), + N_("Toggle between normal and grayscale color display modes"), NULL), new ZoomVerb(SP_VERB_VIEW_CMS_TOGGLE, "ViewCmsToggle", N_("Color-managed view"), N_("Toggle color-managed display for this document window"), INKSCAPE_ICON_COLOR_MANAGEMENT), diff --git a/src/verbs.h b/src/verbs.h index f118014d2..0c781f0b6 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -214,8 +214,11 @@ enum { SP_VERB_VIEW_MODE_NORMAL, SP_VERB_VIEW_MODE_NO_FILTERS, SP_VERB_VIEW_MODE_OUTLINE, -// SP_VERB_VIEW_MODE_PRINT_COLORS_PREVIEW, SP_VERB_VIEW_MODE_TOGGLE, + SP_VERB_VIEW_COLOR_MODE_NORMAL, + SP_VERB_VIEW_COLOR_MODE_GRAYSCALE, +// SP_VERB_VIEW_COLOR_MODE_PRINT_COLORS_PREVIEW, + SP_VERB_VIEW_COLOR_MODE_TOGGLE, SP_VERB_VIEW_CMS_TOGGLE, SP_VERB_VIEW_ICON_PREVIEW, SP_VERB_ZOOM_PAGE, diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index be2caa5ee..323a5b08b 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -638,25 +638,37 @@ SPDesktopWidget::updateTitle(gchar const* uri) ? uri : g_basename(uri) ); GString *name = g_string_new (""); + + gchar const *grayscalename = "(grayscale) "; + gchar const *grayscalenamecomma = ", grayscale"; + gchar const *printcolorsname = "(print colors preview) "; + gchar const *printcolorsnamecomma = ", print colors preview"; + gchar const *colormodename = ""; + gchar const *colormodenamecomma = ""; + + if (this->desktop->getColorMode() == Inkscape::COLORRENDERMODE_GRAYSCALE) { + colormodename = grayscalename; + colormodenamecomma = grayscalenamecomma; + } else if (this->desktop->getColorMode() == Inkscape::COLORRENDERMODE_PRINT_COLORS_PREVIEW) { + colormodename = printcolorsname; + colormodenamecomma = printcolorsnamecomma; + } + if (this->desktop->number > 1) { if (this->desktop->getMode() == Inkscape::RENDERMODE_OUTLINE) { - g_string_printf (name, _("%s: %d (outline) - Inkscape"), fname, this->desktop->number); + g_string_printf (name, _("%s: %d (outline%s) - Inkscape"), fname, this->desktop->number, colormodenamecomma); } else if (this->desktop->getMode() == Inkscape::RENDERMODE_NO_FILTERS) { - g_string_printf (name, _("%s: %d (no filters) - Inkscape"), fname, this->desktop->number); - } else if (this->desktop->getMode() == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW) { - g_string_printf (name, _("%s: %d (print colors preview) - Inkscape"), fname, this->desktop->number); + g_string_printf (name, _("%s: %d (no filters%s) - Inkscape"), fname, this->desktop->number, colormodenamecomma); } else { - g_string_printf (name, _("%s: %d - Inkscape"), fname, this->desktop->number); + g_string_printf (name, _("%s: %d %s- Inkscape"), fname, this->desktop->number, colormodename); } } else { if (this->desktop->getMode() == Inkscape::RENDERMODE_OUTLINE) { - g_string_printf (name, _("%s (outline) - Inkscape"), fname); + g_string_printf (name, _("%s (outline%s) - Inkscape"), fname, colormodenamecomma); } else if (this->desktop->getMode() == Inkscape::RENDERMODE_NO_FILTERS) { - g_string_printf (name, _("%s (no filters) - Inkscape"), fname); - } else if (this->desktop->getMode() == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW) { - g_string_printf (name, _("%s (print colors preview) - Inkscape"), fname); + g_string_printf (name, _("%s (no filters%s) - Inkscape"), fname, colormodenamecomma); } else { - g_string_printf (name, _("%s - Inkscape"), fname); + g_string_printf (name, _("%s %s- Inkscape"), fname, colormodename); } } window->set_title (name->str); |
