From 53933f5fea9d07d1ba6304b88439fba257ee8c34 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Wed, 2 Feb 2011 22:24:36 +0100 Subject: update to latest 2geom ! (bzr r10025) --- src/sp-gradient.cpp | 60 ++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'src/sp-gradient.cpp') diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp index 1b8f9a111..06008c083 100644 --- a/src/sp-gradient.cpp +++ b/src/sp-gradient.cpp @@ -493,7 +493,7 @@ void SPGradientImpl::setGradientAttr(SPObject *object, unsigned key, gchar const object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_GRADIENTTRANSFORM: { - Geom::Matrix t; + Geom::Affine t; if (value && sp_svg_transform_read(value, &t)) { gr->gradientTransform = t; gr->gradientTransform_set = TRUE; @@ -1390,34 +1390,34 @@ sp_gradient_render_vector_block_rgb(SPGradient *gradient, guchar *buf, } } -Geom::Matrix -sp_gradient_get_g2d_matrix(SPGradient const *gr, Geom::Matrix const &ctm, Geom::Rect const &bbox) +Geom::Affine +sp_gradient_get_g2d_matrix(SPGradient const *gr, Geom::Affine const &ctm, Geom::Rect const &bbox) { if (gr->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) { return ( Geom::Scale(bbox.dimensions()) * Geom::Translate(bbox.min()) - * Geom::Matrix(ctm) ); + * Geom::Affine(ctm) ); } else { return ctm; } } -Geom::Matrix -sp_gradient_get_gs2d_matrix(SPGradient const *gr, Geom::Matrix const &ctm, Geom::Rect const &bbox) +Geom::Affine +sp_gradient_get_gs2d_matrix(SPGradient const *gr, Geom::Affine const &ctm, Geom::Rect const &bbox) { if (gr->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) { return ( gr->gradientTransform * Geom::Scale(bbox.dimensions()) * Geom::Translate(bbox.min()) - * Geom::Matrix(ctm) ); + * Geom::Affine(ctm) ); } else { return gr->gradientTransform * ctm; } } void -sp_gradient_set_gs2d_matrix(SPGradient *gr, Geom::Matrix const &ctm, - Geom::Rect const &bbox, Geom::Matrix const &gs2d) +sp_gradient_set_gs2d_matrix(SPGradient *gr, Geom::Affine const &ctm, + Geom::Rect const &bbox, Geom::Affine const &gs2d) { gr->gradientTransform = gs2d * ctm.inverse(); if (gr->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX ) { @@ -1444,8 +1444,8 @@ struct SPLGPainter { NRLGradientRenderer lgr; static SPPainter * painter_new(SPPaintServer *ps, - Geom::Matrix const &full_transform, - Geom::Matrix const &parent_transform, + Geom::Affine const &full_transform, + Geom::Affine const &parent_transform, NRRect const *bbox); }; @@ -1609,8 +1609,8 @@ sp_lineargradient_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inks * and end < 1. */ SPPainter * SPLGPainter::painter_new(SPPaintServer *ps, - Geom::Matrix const &full_transform, - Geom::Matrix const &/*parent_transform*/, + Geom::Affine const &full_transform, + Geom::Affine const &/*parent_transform*/, NRRect const *bbox) { SPLinearGradient *lg = SP_LINEARGRADIENT(ps); @@ -1634,26 +1634,26 @@ SPPainter * SPLGPainter::painter_new(SPPaintServer *ps, * or something similar. Originally I had 1023.9999 here - not sure * whether we have really to cut out ceil int (Lauris). */ - Geom::Matrix color2norm(Geom::identity()); - Geom::Matrix color2px; + Geom::Affine color2norm(Geom::identity()); + Geom::Affine color2px; if (gr->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) { - Geom::Matrix norm2pos(Geom::identity()); + Geom::Affine norm2pos(Geom::identity()); /* BBox to user coordinate system */ - Geom::Matrix bbox2user(bbox->x1 - bbox->x0, 0, 0, bbox->y1 - bbox->y0, bbox->x0, bbox->y0); + Geom::Affine bbox2user(bbox->x1 - bbox->x0, 0, 0, bbox->y1 - bbox->y0, bbox->x0, bbox->y0); - Geom::Matrix color2pos = color2norm * norm2pos; - Geom::Matrix color2tpos = color2pos * gr->gradientTransform; - Geom::Matrix color2user = color2tpos * bbox2user; + Geom::Affine color2pos = color2norm * norm2pos; + Geom::Affine color2tpos = color2pos * gr->gradientTransform; + Geom::Affine color2user = color2tpos * bbox2user; color2px = color2user * full_transform; } else { /* Problem: What to do, if we have mixed lengths and percentages? */ /* Currently we do ignore percentages at all, but that is not good (lauris) */ - Geom::Matrix norm2pos(Geom::identity()); - Geom::Matrix color2pos = color2norm * norm2pos; - Geom::Matrix color2tpos = color2pos * gr->gradientTransform; + Geom::Affine norm2pos(Geom::identity()); + Geom::Affine color2pos = color2norm * norm2pos; + Geom::Affine color2tpos = color2pos * gr->gradientTransform; color2px = color2tpos * full_transform; } @@ -1721,8 +1721,8 @@ struct SPRGPainter { NRRGradientRenderer rgr; static SPPainter *painter_new(SPPaintServer *ps, - Geom::Matrix const &full_transform, - Geom::Matrix const &parent_transform, + Geom::Affine const &full_transform, + Geom::Affine const &parent_transform, NRRect const *bbox); }; @@ -1893,8 +1893,8 @@ sp_radialgradient_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inks * Create radial gradient context. */ SPPainter *SPRGPainter::painter_new(SPPaintServer *ps, - Geom::Matrix const &full_transform, - Geom::Matrix const &/*parent_transform*/, + Geom::Affine const &full_transform, + Geom::Affine const &/*parent_transform*/, NRRect const *bbox) { SPRadialGradient *rg = SP_RADIALGRADIENT(ps); @@ -1911,7 +1911,7 @@ SPPainter *SPRGPainter::painter_new(SPPaintServer *ps, rgp->rg = rg; - Geom::Matrix gs2px; + Geom::Affine gs2px; if (gr->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) { /** \todo @@ -1920,9 +1920,9 @@ SPPainter *SPRGPainter::painter_new(SPPaintServer *ps, */ /* BBox to user coordinate system */ - Geom::Matrix bbox2user(bbox->x1 - bbox->x0, 0, 0, bbox->y1 - bbox->y0, bbox->x0, bbox->y0); + Geom::Affine bbox2user(bbox->x1 - bbox->x0, 0, 0, bbox->y1 - bbox->y0, bbox->x0, bbox->y0); - Geom::Matrix gs2user = gr->gradientTransform * bbox2user; + Geom::Affine gs2user = gr->gradientTransform * bbox2user; gs2px = gs2user * full_transform; } else { -- cgit v1.2.3 From ccba415bc620a21239f11361078c8c30006106c7 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 20 Feb 2011 23:59:34 -0800 Subject: Finished cleanup of outated SP_OBJECT_DOCUMENT C macro. (bzr r10060) --- src/sp-gradient.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/sp-gradient.cpp') diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp index 06008c083..ad422a6ca 100644 --- a/src/sp-gradient.cpp +++ b/src/sp-gradient.cpp @@ -375,7 +375,7 @@ void SPGradientImpl::classInit(SPGradientClass *klass) */ void SPGradientImpl::init(SPGradient *gr) { - gr->ref = new SPGradientReference(SP_OBJECT(gr)); + gr->ref = new SPGradientReference(gr); gr->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(SPGradientImpl::gradientRefChanged), gr)); /** \todo @@ -447,9 +447,9 @@ void SPGradientImpl::release(SPObject *object) g_print("Releasing gradient %s\n", object->getId()); #endif - if (SP_OBJECT_DOCUMENT(object)) { - /* Unregister ourselves */ - SP_OBJECT_DOCUMENT(object)->removeResource("gradient", SP_OBJECT(object)); + if (object->document) { + // Unregister ourselves + object->document->removeResource("gradient", object); } if (gradient->ref) { @@ -932,7 +932,7 @@ SPGradientUnits SPGradient::fetchUnits() void sp_gradient_repr_clear_vector(SPGradient *gr) { - Inkscape::XML::Node *repr = SP_OBJECT_REPR(gr); + Inkscape::XML::Node *repr = gr->getRepr(); /* Collect stops from original repr */ GSList *sl = NULL; @@ -962,8 +962,8 @@ sp_gradient_repr_write_vector(SPGradient *gr) g_return_if_fail(gr != NULL); g_return_if_fail(SP_IS_GRADIENT(gr)); - Inkscape::XML::Document *xml_doc = SP_OBJECT_DOCUMENT(gr)->getReprDoc(); - Inkscape::XML::Node *repr = SP_OBJECT_REPR(gr); + Inkscape::XML::Document *xml_doc = gr->document->getReprDoc(); + Inkscape::XML::Node *repr = gr->getRepr(); /* We have to be careful, as vector may be our own, so construct repr list at first */ GSList *cl = NULL; @@ -995,7 +995,7 @@ sp_gradient_repr_write_vector(SPGradient *gr) void SPGradientImpl::gradientRefModified(SPObject */*href*/, guint /*flags*/, SPGradient *gradient) { if ( gradient->invalidateVector() ) { - SP_OBJECT(gradient)->requestModified(SP_OBJECT_MODIFIED_FLAG); + gradient->requestModified(SP_OBJECT_MODIFIED_FLAG); // Conditional to avoid causing infinite loop if there's a cycle in the href chain. } } @@ -1427,7 +1427,7 @@ sp_gradient_set_gs2d_matrix(SPGradient *gr, Geom::Affine const &ctm, } gr->gradientTransform_set = TRUE; - SP_OBJECT(gr)->requestModified(SP_OBJECT_MODIFIED_FLAG); + gr->requestModified(SP_OBJECT_MODIFIED_FLAG); } /* @@ -1689,7 +1689,7 @@ sp_lineargradient_set_position(SPLinearGradient *lg, lg->x2.set(SVGLength::NONE, x2, x2); lg->y2.set(SVGLength::NONE, y2, y2); - SP_OBJECT(lg)->requestModified(SP_OBJECT_MODIFIED_FLAG); + lg->requestModified(SP_OBJECT_MODIFIED_FLAG); } /** @@ -1968,7 +1968,7 @@ sp_radialgradient_set_position(SPRadialGradient *rg, rg->fy.set(SVGLength::NONE, fy, fy); rg->r.set(SVGLength::NONE, r, r); - SP_OBJECT(rg)->requestModified(SP_OBJECT_MODIFIED_FLAG); + rg->requestModified(SP_OBJECT_MODIFIED_FLAG); } /** -- cgit v1.2.3 From 4a4047fdd90aede6d16c020ddcd70c57ea4aa218 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 21 Feb 2011 23:28:50 +0100 Subject: NEW: Grayscale color display mode. (toggle assigned keybinding: Shift+keypad5) (bzr r10065) --- src/sp-gradient.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'src/sp-gradient.cpp') 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; } -- cgit v1.2.3