diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2010-08-14 19:22:11 +0000 |
|---|---|---|
| committer | Krzysztof KosiĆski <tweenk.pl@gmail.com> | 2010-08-14 19:22:11 +0000 |
| commit | aa844be794b36b44b624e579db7f0945b5d3927b (patch) | |
| tree | f83306b1ac51d8089373023162945eb25951bf68 /src | |
| parent | Fix paint bucket tool (diff) | |
| download | inkscape-aa844be794b36b44b624e579db7f0945b5d3927b.tar.gz inkscape-aa844be794b36b44b624e579db7f0945b5d3927b.zip | |
Completely remove NRPixBlock
(bzr r9508.1.67)
Diffstat (limited to 'src')
36 files changed, 193 insertions, 1553 deletions
diff --git a/src/color-rgba.h b/src/color-rgba.h index fc52b193d..8c21d5e52 100644 --- a/src/color-rgba.h +++ b/src/color-rgba.h @@ -14,7 +14,6 @@ #include <glib.h> // g_assert() #include <glib/gmessages.h> -#include "libnr/nr-pixops.h" #include "decimal-round.h" /** @@ -56,12 +55,12 @@ public: TODO : maybe get rid of the NR_RGBA32_x C-style functions and replace the calls with the bitshifting they do */ - ColorRGBA(unsigned int intcolor) + ColorRGBA(guint32 intcolor) { - _c[0] = NR_RGBA32_R(intcolor)/255.0; - _c[1] = NR_RGBA32_G(intcolor)/255.0; - _c[2] = NR_RGBA32_B(intcolor)/255.0; - _c[3] = NR_RGBA32_A(intcolor)/255.0; + _c[0] = ((intcolor & 0xff000000) >> 24) / 255.0; + _c[1] = ((intcolor & 0x00ff0000) >> 16) / 255.0; + _c[2] = ((intcolor & 0x0000ff00) >> 8) / 255.0; + _c[3] = ((intcolor & 0x000000ff) >> 0) / 255.0; } diff --git a/src/dialogs/clonetiler.cpp b/src/dialogs/clonetiler.cpp index 2be5b2ddc..3fe6b59e3 100644 --- a/src/dialogs/clonetiler.cpp +++ b/src/dialogs/clonetiler.cpp @@ -901,45 +901,17 @@ clonetiler_trace_pick (Geom::Rect box) /* Find visible area */ int width = ibox.x1 - ibox.x0; int height = ibox.y1 - ibox.y0; + double R = 0, G = 0, B = 0, A = 0; cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t *ct = cairo_create(s); - /* Render */ nr_arena_item_invoke_render(ct, trace_root, &ibox, NULL, NR_ARENA_ITEM_RENDER_NO_CACHE ); - cairo_surface_flush(s); cairo_destroy(ct); - - double R = 0, G = 0, B = 0, A = 0; - double count = 0; - - /* TODO convert this to OpenMP somehow */ - unsigned char *data = cairo_image_surface_get_data(s); - int stride = cairo_image_surface_get_stride(s); - for (int y=0; y < height; ++y, data += stride) { - for (int x=0; x < width; ++x) { - guint32 px = *reinterpret_cast<guint32*>(data + 4*x); - EXTRACT_ARGB32(px, a,r,g,b) - count += 1.0; - R += r / 255.0; - G += g / 255.0; - B += b / 255.0; - A += a / 255.0; - } - } + ink_cairo_surface_average_color(s, R, G, B, A); cairo_surface_destroy(s); - R = R / A; - G = G / A; - B = B / A; - A = A / count; - - R = CLAMP (R, 0.0, 1.0); - G = CLAMP (G, 0.0, 1.0); - B = CLAMP (B, 0.0, 1.0); - A = CLAMP (A, 0.0, 1.0); - return SP_RGBA32_F_COMPOSE (R, G, B, A); } diff --git a/src/display/Makefile_insert b/src/display/Makefile_insert index a860c6a44..916dd6dc3 100644 --- a/src/display/Makefile_insert +++ b/src/display/Makefile_insert @@ -89,10 +89,6 @@ ink_common_sources += \ display/nr-light.cpp \ display/nr-light.h \ display/nr-light-types.h \ - display/nr-plain-stuff.cpp \ - display/nr-plain-stuff.h \ - display/nr-plain-stuff-gdk.cpp \ - display/nr-plain-stuff-gdk.h \ display/nr-style.cpp \ display/nr-style.h \ display/nr-svgfonts.cpp \ diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 96219e834..ed4de8afc 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -464,11 +464,76 @@ ink_cairo_surface_get_height(cairo_surface_t *surface) return cairo_image_surface_get_height(surface); } +static int ink_cairo_surface_average_color_internal(cairo_surface_t *surface, double &rf, double &gf, double &bf, double &af) +{ + rf = gf = bf = af = 0.0; + cairo_surface_flush(surface); + int width = cairo_image_surface_get_width(surface); + int height = cairo_image_surface_get_height(surface); + int stride = cairo_image_surface_get_stride(surface); + unsigned char *data = cairo_image_surface_get_data(surface); + + /* TODO convert this to OpenMP somehow */ + for (int y = 0; y < height; ++y, data += stride) { + for (int x = 0; x < width; ++x) { + guint32 px = *reinterpret_cast<guint32*>(data + 4*x); + EXTRACT_ARGB32(px, a,r,g,b) + rf += r / 255.0; + gf += g / 255.0; + bf += b / 255.0; + af += a / 255.0; + } + } + return width * height; +} + +guint32 ink_cairo_surface_average_color(cairo_surface_t *surface) +{ + double rf,gf,bf,af; + ink_cairo_surface_average_color_premul(surface, rf,gf,bf,af); + guint32 r = round(rf * 255); + guint32 g = round(gf * 255); + guint32 b = round(bf * 255); + guint32 a = round(af * 255); + ASSEMBLE_ARGB32(px, a,r,g,b); + return px; +} + +void ink_cairo_surface_average_color(cairo_surface_t *surface, double &r, double &g, double &b, double &a) +{ + int count = ink_cairo_surface_average_color_internal(surface, r,g,b,a); + + r /= a; + g /= a; + b /= a; + a /= count; + + r = CLAMP(r, 0.0, 1.0); + g = CLAMP(g, 0.0, 1.0); + b = CLAMP(b, 0.0, 1.0); + a = CLAMP(a, 0.0, 1.0); +} + +void ink_cairo_surface_average_color_premul(cairo_surface_t *surface, double &r, double &g, double &b, double &a) +{ + int count = ink_cairo_surface_average_color_internal(surface, r,g,b,a); + + r /= count; + g /= count; + b /= count; + a /= count; + + r = CLAMP(r, 0.0, 1.0); + g = CLAMP(g, 0.0, 1.0); + b = CLAMP(b, 0.0, 1.0); + a = CLAMP(a, 0.0, 1.0); +} + cairo_pattern_t * ink_cairo_pattern_create_checkerboard() { - int const w = 8; - int const h = 8; + int const w = 6; + int const h = 6; cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 2*w, 2*h); diff --git a/src/display/cairo-utils.h b/src/display/cairo-utils.h index aa441f0c5..d563cfb75 100644 --- a/src/display/cairo-utils.h +++ b/src/display/cairo-utils.h @@ -95,6 +95,9 @@ cairo_surface_t *ink_cairo_surface_create_output(cairo_surface_t *image, cairo_s void ink_cairo_surface_blit(cairo_surface_t *src, cairo_surface_t *dest); int ink_cairo_surface_get_width(cairo_surface_t *surface); int ink_cairo_surface_get_height(cairo_surface_t *surface); +guint32 ink_cairo_surface_average_color(cairo_surface_t *surface); +void ink_cairo_surface_average_color(cairo_surface_t *surface, double &r, double &g, double &b, double &a); +void ink_cairo_surface_average_color_premul(cairo_surface_t *surface, double &r, double &g, double &b, double &a); cairo_pattern_t *ink_cairo_pattern_create_checkerboard(); diff --git a/src/display/canvas-arena.cpp b/src/display/canvas-arena.cpp index 6f85573d1..f1355b9c4 100644 --- a/src/display/canvas-arena.cpp +++ b/src/display/canvas-arena.cpp @@ -21,7 +21,6 @@ #include "display/nr-arena-group.h" #include "display/canvas-arena.h" #include "display/cairo-utils.h" -#include "libnr/nr-pixblock.h" enum { ARENA_EVENT, @@ -358,22 +357,14 @@ sp_canvas_arena_set_sticky (SPCanvasArena *ca, gboolean sticky) } void -sp_canvas_arena_render_pixblock (SPCanvasArena *ca, NRPixBlock *pb) +sp_canvas_arena_render_surface (SPCanvasArena *ca, cairo_surface_t *surface, NRRectL const &r) { - NRRectL area; - g_return_if_fail (ca != NULL); g_return_if_fail (SP_IS_CANVAS_ARENA (ca)); - /* fixme: */ - pb->empty = FALSE; - - area.x0 = pb->area.x0; - area.y0 = pb->area.y0; - area.x1 = pb->area.x1; - area.y1 = pb->area.y1; - - nr_arena_item_invoke_render (NULL, ca->root, &area, pb, 0); + cairo_t *ct = cairo_create(surface); + nr_arena_item_invoke_render (ct, ca->root, &r, NULL, 0); + cairo_destroy(ct); } diff --git a/src/display/canvas-arena.h b/src/display/canvas-arena.h index 34bc19946..df484197a 100644 --- a/src/display/canvas-arena.h +++ b/src/display/canvas-arena.h @@ -13,8 +13,10 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "../display/sp-canvas.h" -#include "nr-arena-item.h" +#include <cairo.h> +#include <2geom/rect.h> +#include "display/sp-canvas.h" +#include "display/nr-arena-item.h" G_BEGIN_DECLS @@ -55,7 +57,7 @@ GtkType sp_canvas_arena_get_type (void); void sp_canvas_arena_set_pick_delta (SPCanvasArena *ca, gdouble delta); void sp_canvas_arena_set_sticky (SPCanvasArena *ca, gboolean sticky); -void sp_canvas_arena_render_pixblock (SPCanvasArena *ca, NRPixBlock *pb); +void sp_canvas_arena_render_surface (SPCanvasArena *ca, cairo_surface_t *surface, NRRectL const &area); G_END_DECLS diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 1383f7f4e..00a577635 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -28,7 +28,6 @@ #include "document.h" #include "helper/units.h" #include "inkscape.h" -#include "libnr/nr-pixops.h" #include "preferences.h" #include "sp-namedview.h" #include "sp-object.h" diff --git a/src/display/canvas-bpath.cpp b/src/display/canvas-bpath.cpp index ac2980de5..bd24881f7 100644 --- a/src/display/canvas-bpath.cpp +++ b/src/display/canvas-bpath.cpp @@ -21,22 +21,12 @@ #include "display/display-forward.h" #include "display/curve.h" #include "display/cairo-utils.h" -#include <libnr/nr-pixops.h> #include "helper/geom.h" #include <sstream> #include <string.h> #include <desktop.h> -/** -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include <color.h> - -#include <libnr/nr-pixops.h> -**/ - void nr_pixblock_render_bpath_rgba (Shape* theS,uint32_t color,NRRectL &area,char* destBuf,int stride); static void sp_canvas_bpath_class_init (SPCanvasBPathClass *klass); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 5dae228b4..b04dc4483 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -23,7 +23,6 @@ #include "document.h" #include "helper/units.h" #include "inkscape.h" -#include "libnr/nr-pixops.h" #include "preferences.h" #include "sp-namedview.h" #include "sp-object.h" diff --git a/src/display/canvas-text.cpp b/src/display/canvas-text.cpp index 90f7c47c6..ab49d1fe3 100644 --- a/src/display/canvas-text.cpp +++ b/src/display/canvas-text.cpp @@ -13,20 +13,19 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <sstream> +#include <string.h> + #include "display-forward.h" #include "sp-canvas-util.h" #include "canvas-text.h" #include "display/cairo-utils.h" -#include <sstream> -#include <string.h> #include "desktop.h" - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include <color.h> - -#include <libnr/nr-pixops.h> +#include "color.h" static void sp_canvastext_class_init (SPCanvasTextClass *klass); static void sp_canvastext_init (SPCanvasText *canvastext); @@ -124,13 +123,11 @@ sp_canvastext_render (SPCanvasItem *item, SPCanvasBuf *buf) cairo_set_font_size(buf->ct, cl->fontsize); cairo_text_path(buf->ct, cl->text); - cairo_set_source_rgba(buf->ct, SP_RGBA32_B_F(cl->rgba_stroke), SP_RGBA32_G_F(cl->rgba_stroke), SP_RGBA32_R_F(cl->rgba_stroke), SP_RGBA32_A_F(cl->rgba_stroke)); + ink_cairo_set_source_rgba32(buf->ct, cl->rgba_stroke); cairo_set_line_width (buf->ct, 2.0); cairo_stroke_preserve(buf->ct); - cairo_set_source_rgba(buf->ct, SP_RGBA32_B_F(cl->rgba), SP_RGBA32_G_F(cl->rgba), SP_RGBA32_R_F(cl->rgba), SP_RGBA32_A_F(cl->rgba)); + ink_cairo_set_source_rgba32(buf->ct, cl->rgba); cairo_fill(buf->ct); - - cairo_new_path(buf->ct); } static void diff --git a/src/display/nr-light.cpp b/src/display/nr-light.cpp index a3373aadb..3d441a8ec 100644 --- a/src/display/nr-light.cpp +++ b/src/display/nr-light.cpp @@ -13,12 +13,12 @@ #include <cmath> -#include "libnr/nr-pixops.h" #include "display/nr-light.h" #include "display/nr-3dutils.h" #include "filters/distantlight.h" #include "filters/pointlight.h" #include "filters/spotlight.h" +#include "color.h" namespace Inkscape { namespace Filters { @@ -38,9 +38,9 @@ void DistantLight::light_vector(NR::Fvector &v) { } void DistantLight::light_components(NR::Fvector &lc) { - lc[LIGHT_RED] = NR_RGBA32_R(color); - lc[LIGHT_GREEN] = NR_RGBA32_G(color); - lc[LIGHT_BLUE] = NR_RGBA32_B(color); + lc[LIGHT_RED] = SP_RGBA32_R_U(color); + lc[LIGHT_GREEN] = SP_RGBA32_G_U(color); + lc[LIGHT_BLUE] = SP_RGBA32_B_U(color); } PointLight::PointLight(SPFePointLight *light, guint32 lighting_color, const Geom::Matrix &trans) { @@ -61,9 +61,9 @@ void PointLight::light_vector(NR::Fvector &v, gdouble x, gdouble y, gdouble z) { } void PointLight::light_components(NR::Fvector &lc) { - lc[LIGHT_RED] = NR_RGBA32_R(color); - lc[LIGHT_GREEN] = NR_RGBA32_G(color); - lc[LIGHT_BLUE] = NR_RGBA32_B(color); + lc[LIGHT_RED] = SP_RGBA32_R_U(color); + lc[LIGHT_GREEN] = SP_RGBA32_G_U(color); + lc[LIGHT_BLUE] = SP_RGBA32_B_U(color); } SpotLight::SpotLight(SPFeSpotLight *light, guint32 lighting_color, const Geom::Matrix &trans) { @@ -101,9 +101,9 @@ void SpotLight::light_components(NR::Fvector &lc, const NR::Fvector &L) { spmod = 0; else spmod = std::pow(spmod, speExp); - lc[LIGHT_RED] = spmod * NR_RGBA32_R(color); - lc[LIGHT_GREEN] = spmod * NR_RGBA32_G(color); - lc[LIGHT_BLUE] = spmod * NR_RGBA32_B(color); + lc[LIGHT_RED] = spmod * SP_RGBA32_R_U(color); + lc[LIGHT_GREEN] = spmod * SP_RGBA32_G_U(color); + lc[LIGHT_BLUE] = spmod * SP_RGBA32_B_U(color); } } /* namespace Filters */ diff --git a/src/display/nr-plain-stuff-gdk.cpp b/src/display/nr-plain-stuff-gdk.cpp deleted file mode 100644 index d5b43f4ea..000000000 --- a/src/display/nr-plain-stuff-gdk.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#define __NR_PLAIN_STUFF_GDK_C__ - -/* - * Miscellaneous simple rendering utilities - * - * Author: - * Lauris Kaplinski <lauris@ximian.com> - * - * Copyright (C) 2001 Lauris Kaplinski and Ximian, Inc. - * - * Released under GNU GPL - */ - -#include <libnr/nr-pixblock-pattern.h> -#include "nr-plain-stuff.h" -#include "nr-plain-stuff-gdk.h" - -void -nr_gdk_draw_rgba32_solid (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint w, gint h, guint32 rgba) -{ - NRPixBlock pb; - - nr_pixblock_setup_fast (&pb, NR_PIXBLOCK_MODE_R8G8B8A8N, 0, 0, w, h, FALSE); - - nr_render_rgba32_rgb (NR_PIXBLOCK_PX (&pb), w, h, pb.rs, x, y, rgba); - gdk_draw_rgb_image (drawable, gc, x, y, w, h, GDK_RGB_DITHER_MAX, NR_PIXBLOCK_PX (&pb), pb.rs); - - nr_pixblock_release (&pb); -} - -void -nr_gdk_draw_gray_garbage (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint w, gint h) -{ - for (gint yy = y; yy < y + h; yy += 64) { - for (gint xx = x; xx < x + w; xx += 64) { - NRPixBlock pb; - gint ex = MIN (xx + 64, x + w); - gint ey = MIN (yy + 64, y + h); - nr_pixblock_setup_fast (&pb, NR_PIXBLOCK_MODE_R8G8B8, xx, yy, ex, ey, FALSE); - nr_pixblock_render_gray_noise (&pb, NULL); - gdk_draw_rgb_image (drawable, gc, xx, yy, ex - xx, ey - yy, GDK_RGB_DITHER_NONE, NR_PIXBLOCK_PX (&pb), pb.rs); - nr_pixblock_release (&pb); - } - } -} - diff --git a/src/display/nr-plain-stuff-gdk.h b/src/display/nr-plain-stuff-gdk.h deleted file mode 100644 index 7c83792a8..000000000 --- a/src/display/nr-plain-stuff-gdk.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __NR_PLAIN_STUFF_GDK_H__ -#define __NR_PLAIN_STUFF_GDK_H__ - -/* - * Miscellaneous simple rendering utilities - * - * Author: - * Lauris Kaplinski <lauris@ximian.com> - * - * Copyright (C) 2001 Lauris Kaplinski and Ximian, Inc. - * - * Released under GNU GPL - */ - -#include <gdk/gdk.h> - -void nr_gdk_draw_rgba32_solid (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint w, gint h, guint32 rgba); - -void nr_gdk_draw_gray_garbage (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint w, gint h); - -#endif - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/display/nr-plain-stuff.cpp b/src/display/nr-plain-stuff.cpp deleted file mode 100644 index 62a61102e..000000000 --- a/src/display/nr-plain-stuff.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#define __NR_PLAIN_STUFF_C__ - -/* - * Miscellaneous simple rendering utilities - * - * Author: - * Lauris Kaplinski <lauris@ximian.com> - * - * Copyright (C) 2001 Lauris Kaplinski and Ximian, Inc. - * - * Released under GNU GPL - */ - -#include <glib/gmessages.h> -#include <libnr/nr-pixops.h> -#include "nr-plain-stuff.h" - -#define NR_DEFAULT_CHECKERSIZEP2 2 -#define NR_DEFAULT_CHECKERCOLOR0 0xbfbfbfff -#define NR_DEFAULT_CHECKERCOLOR1 0x808080ff - -void -nr_render_checkerboard_rgb (guchar *px, gint w, gint h, gint rs, gint xoff, gint yoff) -{ - g_return_if_fail (px != NULL); - - nr_render_checkerboard_rgb_custom (px, w, h, rs, xoff, yoff, NR_DEFAULT_CHECKERCOLOR0, NR_DEFAULT_CHECKERCOLOR1, NR_DEFAULT_CHECKERSIZEP2); -} - -void -nr_render_checkerboard_rgb_custom (guchar *px, gint w, gint h, gint rs, gint xoff, gint yoff, guint32 c0, guint32 c1, gint sizep2) -{ - gint x, y, m; - guint r0, g0, b0; - guint r1, g1, b1; - - g_return_if_fail (px != NULL); - g_return_if_fail (sizep2 >= 0); - g_return_if_fail (sizep2 <= 8); - - xoff &= 0x1ff; - yoff &= 0x1ff; - m = 0x1 << sizep2; - r0 = NR_RGBA32_R (c0); - g0 = NR_RGBA32_G (c0); - b0 = NR_RGBA32_B (c0); - r1 = NR_RGBA32_R (c1); - g1 = NR_RGBA32_G (c1); - b1 = NR_RGBA32_B (c1); - - for (y = 0; y < h; y++) { - guchar *p; - p = px; - for (x = 0; x < w; x++) { - if (((x + xoff) ^ (y + yoff)) & m) { - *p++ = r0; - *p++ = g0; - *p++ = b0; - } else { - *p++ = r1; - *p++ = g1; - *p++ = b1; - } - } - px += rs; - } -} - -void -nr_render_rgba32_rgb (guchar *px, gint w, gint h, gint rs, gint xoff, gint yoff, guint32 c) -{ - guint32 c0, c1; - gint a, r, g, b, cr, cg, cb; - - g_return_if_fail (px != NULL); - - r = NR_RGBA32_R (c); - g = NR_RGBA32_G (c); - b = NR_RGBA32_B (c); - a = NR_RGBA32_A (c); - - cr = NR_COMPOSEN11_1111 (r, a, NR_RGBA32_R (NR_DEFAULT_CHECKERCOLOR0)); - cg = NR_COMPOSEN11_1111 (g, a, NR_RGBA32_G (NR_DEFAULT_CHECKERCOLOR0)); - cb = NR_COMPOSEN11_1111 (b, a, NR_RGBA32_B (NR_DEFAULT_CHECKERCOLOR0)); - c0 = (cr << 24) | (cg << 16) | (cb << 8) | 0xff; - - cr = NR_COMPOSEN11_1111 (r, a, NR_RGBA32_R (NR_DEFAULT_CHECKERCOLOR1)); - cg = NR_COMPOSEN11_1111 (g, a, NR_RGBA32_G (NR_DEFAULT_CHECKERCOLOR1)); - cb = NR_COMPOSEN11_1111 (b, a, NR_RGBA32_B (NR_DEFAULT_CHECKERCOLOR1)); - c1 = (cr << 24) | (cg << 16) | (cb << 8) | 0xff; - - nr_render_checkerboard_rgb_custom (px, w, h, rs, xoff, yoff, c0, c1, NR_DEFAULT_CHECKERSIZEP2); -} - diff --git a/src/display/nr-plain-stuff.h b/src/display/nr-plain-stuff.h deleted file mode 100644 index c568f38a6..000000000 --- a/src/display/nr-plain-stuff.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __NR_PLAIN_STUFF_H__ -#define __NR_PLAIN_STUFF_H__ - -/* - * Miscellaneous simple rendering utilities - * - * Author: - * Lauris Kaplinski <lauris@ximian.com> - * - * Copyright (C) 2001 Lauris Kaplinski and Ximian, Inc. - * - * Released under GNU GPL - */ - -#include <glib/gtypes.h> - -void nr_render_checkerboard_rgb (guchar *px, gint w, gint h, gint rs, gint xoff, gint yoff); -void nr_render_checkerboard_rgb_custom (guchar *px, gint w, gint h, gint rs, gint xoff, gint yoff, guint32 c0, guint32 c1, gint sizep2); - -void nr_render_rgba32_rgb (guchar *px, gint w, gint h, gint rs, gint xoff, gint yoff, guint32 c); - -#endif - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/display/sodipodi-ctrl.cpp b/src/display/sodipodi-ctrl.cpp index 37685c5da..28488e7c3 100644 --- a/src/display/sodipodi-ctrl.cpp +++ b/src/display/sodipodi-ctrl.cpp @@ -12,7 +12,6 @@ #include "sp-canvas-util.h" #include "display-forward.h" #include "sodipodi-ctrl.h" -#include "libnr/nr-pixops.h" #include "display/cairo-utils.h" enum { diff --git a/src/display/sp-canvas-util.cpp b/src/display/sp-canvas-util.cpp index 83604a1bf..1e7ba49ac 100644 --- a/src/display/sp-canvas-util.cpp +++ b/src/display/sp-canvas-util.cpp @@ -14,7 +14,6 @@ #include <2geom/matrix.h> -#include "libnr/nr-pixops.h" #include "sp-canvas-util.h" #include <string.h> /* for memset */ diff --git a/src/dropper-context.cpp b/src/dropper-context.cpp index 3898cd169..88d1c4561 100644 --- a/src/dropper-context.cpp +++ b/src/dropper-context.cpp @@ -26,6 +26,7 @@ #include "display/canvas-bpath.h" #include "display/canvas-arena.h" #include "display/curve.h" +#include "display/cairo-utils.h" #include "svg/svg-color.h" #include "color.h" #include "color-rgba.h" @@ -36,7 +37,6 @@ #include "desktop-handles.h" #include "selection.h" #include "document.h" -#include "libnr/nr-pixblock.h" #include "pixmaps/cursor-dropper.xpm" @@ -202,7 +202,7 @@ static gint sp_dropper_context_root_handler(SPEventContext *event_context, GdkEv // otherwise, constantly calculate color no matter is any button pressed or not double rw = 0.0; - double W(0), R(0), G(0), B(0), A(0); + double R(0), G(0), B(0), A(0); if (dc->dragging) { // calculate average @@ -222,56 +222,32 @@ static gint sp_dropper_context_root_handler(SPEventContext *event_context, GdkEv sp_canvas_item_show(dc->area); /* Get buffer */ - const int x0 = (int) floor(dc->centre[Geom::X] - rw); - const int y0 = (int) floor(dc->centre[Geom::Y] - rw); - const int x1 = (int) ceil(dc->centre[Geom::X] + rw); - const int y1 = (int) ceil(dc->centre[Geom::Y] + rw); - - if ((x1 > x0) && (y1 > y0)) { - NRPixBlock pb; - nr_pixblock_setup_fast(&pb, NR_PIXBLOCK_MODE_R8G8B8A8P, x0, y0, x1, y1, TRUE); - /* fixme: (Lauris) */ - sp_canvas_arena_render_pixblock(SP_CANVAS_ARENA(sp_desktop_drawing(desktop)), &pb); - for (int y = y0; y < y1; y++) { - const unsigned char *s = NR_PIXBLOCK_PX(&pb) + (y - y0) * pb.rs; - for (int x = x0; x < x1; x++) { - const double dx = x - dc->centre[Geom::X]; - const double dy = y - dc->centre[Geom::Y]; - const double w = exp(-((dx * dx) + (dy * dy)) / (rw * rw)); - W += w; - R += w * s[0]; - G += w * s[1]; - B += w * s[2]; - A += w * s[3]; - s += 4; - } - } - nr_pixblock_release(&pb); - - R = (R + 0.001) / (255.0 * W); - G = (G + 0.001) / (255.0 * W); - B = (B + 0.001) / (255.0 * W); - A = (A + 0.001) / (255.0 * W); - - R = CLAMP(R, 0.0, 1.0); - G = CLAMP(G, 0.0, 1.0); - B = CLAMP(B, 0.0, 1.0); - A = CLAMP(A, 0.0, 1.0); + Geom::Rect r(dc->centre, dc->centre); + r.expandBy(rw); + if (!r.hasZeroArea()) { + NRRectL area; + area.x0 = r[Geom::X].min(); + area.y0 = r[Geom::Y].min(); + area.x1 = r[Geom::X].max(); + area.y1 = r[Geom::Y].max(); + int w = area.x1 - area.x0; + int h = area.y1 - area.y0; + cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); + sp_canvas_arena_render_surface(SP_CANVAS_ARENA(sp_desktop_drawing(desktop)), s, area); + ink_cairo_surface_average_color_premul(s, R, G, B, A); + cairo_surface_destroy(s); } - } else { // pick single pixel - NRPixBlock pb; - int x = (int) floor(event->button.x); - int y = (int) floor(event->button.y); - nr_pixblock_setup_fast(&pb, NR_PIXBLOCK_MODE_R8G8B8A8P, x, y, x+1, y+1, TRUE); - sp_canvas_arena_render_pixblock(SP_CANVAS_ARENA(sp_desktop_drawing(desktop)), &pb); - const unsigned char *s = NR_PIXBLOCK_PX(&pb); - - R = s[0] / 255.0; - G = s[1] / 255.0; - B = s[2] / 255.0; - A = s[3] / 255.0; + NRRectL area; + area.x0 = floor(event->button.x); + area.y0 = floor(event->button.y); + area.x1 = area.x0 + 1; + area.y1 = area.y0 + 1; + cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); + sp_canvas_arena_render_surface(SP_CANVAS_ARENA(sp_desktop_drawing(desktop)), s, area); + ink_cairo_surface_average_color_premul(s, R, G, B, A); + cairo_surface_destroy(s); } if (pick == SP_DROPPER_PICK_VISIBLE) { diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp index de6c151c3..468124bb7 100644 --- a/src/dyna-draw-context.cpp +++ b/src/dyna-draw-context.cpp @@ -34,6 +34,7 @@ #include "svg/svg.h" #include "display/canvas-bpath.h" +#include "display/cairo-utils.h" #include <2geom/isnan.h> #include <2geom/pathvector.h> #include <2geom/bezier-utils.h> @@ -62,7 +63,6 @@ #include "display/canvas-bpath.h" #include "display/canvas-arena.h" #include "livarot/Shape.h" -#include "libnr/nr-pixblock.h" #include "dyna-draw-context.h" @@ -438,16 +438,16 @@ sp_dyna_draw_brush(SPDynaDrawContext *dc) double trace_thick = 1; if (dc->trace_bg) { // pick single pixel - NRPixBlock pb; - int x = (int) floor(brush_w[Geom::X]); - int y = (int) floor(brush_w[Geom::Y]); - nr_pixblock_setup_fast(&pb, NR_PIXBLOCK_MODE_R8G8B8A8P, x, y, x+1, y+1, TRUE); - sp_canvas_arena_render_pixblock(SP_CANVAS_ARENA(sp_desktop_drawing(SP_EVENT_CONTEXT(dc)->desktop)), &pb); - const unsigned char *s = NR_PIXBLOCK_PX(&pb); - double R = s[0] / 255.0; - double G = s[1] / 255.0; - double B = s[2] / 255.0; - double A = s[3] / 255.0; + double R, G, B, A; + NRRectL area; + area.x0 = floor(brush_w[Geom::X]); + area.y0 = floor(brush_w[Geom::Y]); + area.x1 = area.x0 + 1; + area.y1 = area.y0 + 1; + cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); + sp_canvas_arena_render_surface(SP_CANVAS_ARENA(sp_desktop_drawing(SP_EVENT_CONTEXT(dc)->desktop)), s, area); + ink_cairo_surface_average_color_premul(s, R, G, B, A); + cairo_surface_destroy(s); double max = MAX (MAX (R, G), B); double min = MIN (MIN (R, G), B); double L = A * (max + min)/2 + (1 - A); // blend with white bg diff --git a/src/file.cpp b/src/file.cpp index 50fcd3642..b6bc4c876 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -29,7 +29,6 @@ #include <gtk/gtk.h> #include <glib/gmem.h> #include <glibmm/i18n.h> -#include <libnr/nr-pixops.h> #include "application/application.h" #include "application/editor.h" diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 437c39649..20870086a 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -17,8 +17,6 @@ #endif #include "interface.h" -#include "libnr/nr-pixops.h" -#include "libnr/nr-pixblock.h" #include <2geom/rect.h> #include <glib/gmessages.h> #include <png.h> @@ -479,15 +477,12 @@ sp_export_png_file(SPDocument *doc, gchar const *filename, ebp.status = status; ebp.data = data; - bool write_status; - if ((width < 256) || ((width * height) < 32768)) { - ebp.px = nr_pixelstore_64K_new(FALSE, 0); - ebp.sheight = 65536 / (4 * width); - write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp); - nr_pixelstore_64K_free(ebp.px); - } else { - ebp.sheight = 64; - ebp.px = g_try_new(guchar, 4 * ebp.sheight * width); + bool write_status = false;; + + ebp.sheight = 64; + ebp.px = g_try_new(guchar, 4 * ebp.sheight * width); + + if (ebp.px) { write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp); g_free(ebp.px); } diff --git a/src/libnr/Makefile_insert b/src/libnr/Makefile_insert index 2da8e36fb..1027e0600 100644 --- a/src/libnr/Makefile_insert +++ b/src/libnr/Makefile_insert @@ -10,11 +10,6 @@ ink_common_sources += \ libnr/nr-macros.h \ libnr/nr-object.cpp \ libnr/nr-object.h \ - libnr/nr-pixblock-pattern.cpp \ - libnr/nr-pixblock-pattern.h \ - libnr/nr-pixblock.cpp \ - libnr/nr-pixblock.h \ - libnr/nr-pixops.h \ libnr/nr-point-fns.cpp \ libnr/nr-point-fns.h \ libnr/nr-point-l.h \ diff --git a/src/libnr/nr-pixblock-pattern.cpp b/src/libnr/nr-pixblock-pattern.cpp deleted file mode 100644 index aa3246297..000000000 --- a/src/libnr/nr-pixblock-pattern.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#define __NR_PIXBLOCK_PATTERN_C__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - - -#include <glib/gmem.h> -#include "nr-pixops.h" -#include "nr-pixblock-pattern.h" - -#define NR_NOISE_SIZE 1024 - -void -nr_pixblock_render_gray_noise (NRPixBlock *pb, NRPixBlock *mask) -{ - static unsigned char *noise = NULL; - static unsigned int seed = 0; - unsigned int v; - NRRectL clip; - int x, y, bpp; - - if (mask) { - if (mask->empty) return; - nr_rect_l_intersect (&clip, &pb->area, &mask->area); - if (nr_rect_l_test_empty(clip)) return; - } else { - clip = pb->area; - } - - if (!noise) { - int i; - noise = g_new (unsigned char, NR_NOISE_SIZE); - for (i = 0; i < NR_NOISE_SIZE; i++) noise[i] = (rand () / (RAND_MAX >> 8)) & 0xff; - } - - bpp = NR_PIXBLOCK_BPP (pb); - - v = (rand () / (RAND_MAX >> 8)) & 0xff; - - if (mask) { - for (y = clip.y0; y < clip.y1; y++) { - unsigned char *d, *m; - d = NR_PIXBLOCK_PX (pb) + (y - pb->area.y0) * pb->rs + (clip.x0 - pb->area.x0) * bpp; - m = NR_PIXBLOCK_PX (mask) + (y - mask->area.y0) * pb->rs + (clip.x0 - mask->area.x0); - for (x = clip.x0; x < clip.x1; x++) { - v = v ^ noise[seed]; - switch (pb->mode) { - case NR_PIXBLOCK_MODE_A8: - d[0] = NR_COMPOSEA_111(m[0], d[0]); - break; - case NR_PIXBLOCK_MODE_R8G8B8: - d[0] = NR_COMPOSEN11_1111 (v, m[0], d[0]); - d[1] = NR_COMPOSEN11_1111 (v, m[0], d[1]); - d[2] = NR_COMPOSEN11_1111 (v, m[0], d[2]); - break; - case NR_PIXBLOCK_MODE_R8G8B8A8N: - if (m[0] != 0) { - unsigned int ca; - ca = NR_COMPOSEA_112(m[0], d[3]); - d[0] = NR_COMPOSENNN_111121 (v, m[0], d[0], d[3], ca); - d[1] = NR_COMPOSENNN_111121 (v, m[0], d[1], d[3], ca); - d[2] = NR_COMPOSENNN_111121 (v, m[0], d[2], d[3], ca); - d[3] = NR_NORMALIZE_21(ca); - } - break; - case NR_PIXBLOCK_MODE_R8G8B8A8P: - d[0] = NR_COMPOSENPP_1111 (v, m[0], d[0]); - d[1] = NR_COMPOSENPP_1111 (v, m[0], d[1]); - d[2] = NR_COMPOSENPP_1111 (v, m[0], d[2]); - d[3] = NR_COMPOSEA_111(d[3], m[0]); - break; - default: - break; - } - d += bpp; - m += 1; - if (++seed >= NR_NOISE_SIZE) { - int i; - i = (rand () / (RAND_MAX / NR_NOISE_SIZE)) % NR_NOISE_SIZE; - noise[i] ^= v; - seed = i % (NR_NOISE_SIZE >> 2); - } - } - } - } else { - for (y = clip.y0; y < clip.y1; y++) { - unsigned char *d; - d = NR_PIXBLOCK_PX (pb) + (y - pb->area.y0) * pb->rs + (clip.x0 - pb->area.x0) * bpp; - for (x = clip.x0; x < clip.x1; x++) { - v = v ^ noise[seed]; - switch (pb->mode) { - case NR_PIXBLOCK_MODE_A8: - d[0] = 255; - break; - case NR_PIXBLOCK_MODE_R8G8B8: - d[0] = v; - d[1] = v; - d[2] = v; - break; - case NR_PIXBLOCK_MODE_R8G8B8A8N: - case NR_PIXBLOCK_MODE_R8G8B8A8P: - d[0] = v; - d[1] = v; - d[2] = v; - d[3] = 255; - default: - break; - } - d += bpp; - if (++seed >= NR_NOISE_SIZE) { - int i; - i = (rand () / (RAND_MAX / NR_NOISE_SIZE)) % NR_NOISE_SIZE; - noise[i] ^= v; - seed = i % (NR_NOISE_SIZE >> 2); - } - } - } - } - - pb->empty = 0; -} diff --git a/src/libnr/nr-pixblock-pattern.h b/src/libnr/nr-pixblock-pattern.h deleted file mode 100644 index 463a24379..000000000 --- a/src/libnr/nr-pixblock-pattern.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __NR_PIXBLOCK_PATTERN_H__ -#define __NR_PIXBLOCK_PATTERN_H__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -#include <libnr/nr-pixblock.h> - -void nr_pixblock_render_gray_noise (NRPixBlock *pb, NRPixBlock *mask); - -#endif - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-pixblock.cpp b/src/libnr/nr-pixblock.cpp deleted file mode 100644 index 6b2b12b7b..000000000 --- a/src/libnr/nr-pixblock.cpp +++ /dev/null @@ -1,457 +0,0 @@ -#define __NR_PIXBLOCK_C__ - -/** \file - * \brief Allocation/Setup of NRPixBlock objects. Pixel store functions. - * - * Authors: - * (C) 1999-2002 Lauris Kaplinski <lauris@kaplinski.com> - * 2008, Jasper van de Gronde <th.v.d.gonde@hccnet.nl> - * - * This code is in the Public Domain - */ - -#include <cstring> -#include <string> -#include <string.h> -#include <glib/gmem.h> -#include "nr-pixblock.h" - -/// Size of buffer that needs no allocation (default 4). -#define NR_TINY_MAX sizeof (unsigned char *) - -/** - * Pixbuf initialisation using homegrown memory handling ("pixelstore"). - * - * Pixbuf sizes are differentiated into tiny, <4K, <16K, <64K, and more, - * with each type having its own method of memory handling. After allocating - * memory, the buffer is cleared if the clear flag is set. Intended to - * reduce memory fragmentation. - * \param pb Pointer to the pixbuf struct. - * \param mode Indicates grayscale/RGB/RGBA. - * \param clear True if buffer should be cleared. - * \pre x1>=x0 && y1>=y0 && pb!=NULL - */ -void -nr_pixblock_setup_fast (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear) -{ - int w, h, bpp; - size_t size; - - w = x1 - x0; - h = y1 - y0; - bpp = (mode == NR_PIXBLOCK_MODE_A8) ? 1 : (mode == NR_PIXBLOCK_MODE_R8G8B8) ? 3 : 4; - - size = bpp * w * h; - - if (size <= NR_TINY_MAX) { - pb->size = NR_PIXBLOCK_SIZE_TINY; - if (clear) memset (pb->data.p, 0x0, size); - } else if (size <= 4096) { - pb->size = NR_PIXBLOCK_SIZE_4K; - pb->data.px = nr_pixelstore_4K_new (clear, 0x0); - } else if (size <= 16384) { - pb->size = NR_PIXBLOCK_SIZE_16K; - pb->data.px = nr_pixelstore_16K_new (clear, 0x0); - } else if (size <= 65536) { - pb->size = NR_PIXBLOCK_SIZE_64K; - pb->data.px = nr_pixelstore_64K_new (clear, 0x0); - } else if (size <= 262144) { - pb->size = NR_PIXBLOCK_SIZE_256K; - pb->data.px = nr_pixelstore_256K_new (clear, 0x0); - } else if (size <= 1048576) { - pb->size = NR_PIXBLOCK_SIZE_1M; - pb->data.px = nr_pixelstore_1M_new (clear, 0x0); - } else { - pb->size = NR_PIXBLOCK_SIZE_BIG; - pb->data.px = NULL; - if (size > 100000000) { // Don't even try to allocate more than 100Mb (5000x5000 RGBA - // pixels). It'll just bog the system down even if successful. FIXME: - // Can anyone suggest something better than the magic number? - g_warning ("%lu bytes requested for pixel buffer, I won't try to allocate that.", (long unsigned) size); - return; - } - pb->data.px = g_try_new (unsigned char, size); - if (pb->data.px == NULL) { // memory allocation failed - g_warning ("Could not allocate %lu bytes for pixel buffer!", (long unsigned) size); - return; - } - if (clear) memset (pb->data.px, 0x0, size); - } - - pb->mode = mode; - pb->empty = 1; - pb->visible_area.x0 = pb->area.x0 = x0; - pb->visible_area.y0 = pb->area.y0 = y0; - pb->visible_area.x1 = pb->area.x1 = x1; - pb->visible_area.y1 = pb->area.y1 = y1; - pb->rs = bpp * w; -} - -/** - * Pixbuf initialisation using g_new. - * - * After allocating memory, the buffer is cleared if the clear flag is set. - * \param pb Pointer to the pixbuf struct. - * \param mode Indicates grayscale/RGB/RGBA. - * \param clear True if buffer should be cleared. - * \pre x1>=x0 && y1>=y0 && pb!=NULL - FIXME: currently unused except for nr_pixblock_new and pattern tiles, replace with _fast and delete? - */ -void -nr_pixblock_setup (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear) -{ - int w, h, bpp; - size_t size; - - w = x1 - x0; - h = y1 - y0; - bpp = (mode == NR_PIXBLOCK_MODE_A8) ? 1 : (mode == NR_PIXBLOCK_MODE_R8G8B8) ? 3 : 4; - - size = bpp * w * h; - - if (size <= NR_TINY_MAX) { - pb->size = NR_PIXBLOCK_SIZE_TINY; - if (clear) memset (pb->data.p, 0x0, size); - } else { - pb->size = NR_PIXBLOCK_SIZE_BIG; - pb->data.px = g_new (unsigned char, size); - if (clear) memset (pb->data.px, 0x0, size); - } - - pb->mode = mode; - pb->empty = 1; - pb->visible_area.x0 = pb->area.x0 = x0; - pb->visible_area.y0 = pb->area.y0 = y0; - pb->visible_area.x1 = pb->area.x1 = x1; - pb->visible_area.y1 = pb->area.y1 = y1; - pb->rs = bpp * w; -} - -/** - * Pixbuf initialisation with preset values. - * - * After copying all parameters into the NRPixBlock struct, the pixel buffer is cleared if the clear flag is set. - * \param pb Pointer to the pixbuf struct. - * \param mode Indicates grayscale/RGB/RGBA. - * \param clear True if buffer should be cleared. - * \pre x1>=x0 && y1>=y0 && pb!=NULL - */ -void -nr_pixblock_setup_extern (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, unsigned char *px, int rs, bool empty, bool clear) -{ - int w, bpp; - - w = x1 - x0; - bpp = (mode == NR_PIXBLOCK_MODE_A8) ? 1 : (mode == NR_PIXBLOCK_MODE_R8G8B8) ? 3 : 4; - - pb->size = NR_PIXBLOCK_SIZE_STATIC; - pb->mode = mode; - pb->empty = empty; - pb->visible_area.x0 = pb->area.x0 = x0; - pb->visible_area.y0 = pb->area.y0 = y0; - pb->visible_area.x1 = pb->area.x1 = x1; - pb->visible_area.y1 = pb->area.y1 = y1; - pb->data.px = px; - pb->rs = rs; - - g_assert (pb->data.px != NULL); - if (clear) { - if (rs == bpp * w) { - /// \todo How do you recognise if - /// px was an uncleared tiny buffer? - if (pb->data.px) - memset (pb->data.px, 0x0, bpp * (y1 - y0) * w); - } else { - int y; - for (y = y0; y < y1; y++) { - memset (pb->data.px + (y - y0) * rs, 0x0, bpp * w); - } - } - } -} - -/** - * Frees memory taken by pixel data in NRPixBlock. - * \param pb Pointer to pixblock. - * \pre pb and pb->data.px point to valid addresses. - * - * According to pb->size, one of the functions for freeing the pixelstore - * is called. May be called regardless of how pixbuf was set up. - */ -void -nr_pixblock_release (NRPixBlock *pb) -{ - switch (pb->size) { - case NR_PIXBLOCK_SIZE_TINY: - break; - case NR_PIXBLOCK_SIZE_4K: - nr_pixelstore_4K_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_16K: - nr_pixelstore_16K_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_64K: - nr_pixelstore_64K_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_256K: - nr_pixelstore_256K_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_1M: - nr_pixelstore_1M_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_BIG: - g_free (pb->data.px); - break; - case NR_PIXBLOCK_SIZE_STATIC: - break; - default: - break; - } -} - -/** - * Allocates NRPixBlock and sets it up. - * - * \return Pointer to fresh pixblock. - * Calls g_new() and nr_pixblock_setup(). -FIXME: currently unused, delete? JG: Should be used more often! (To simplify memory management.) - */ -NRPixBlock * -nr_pixblock_new (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear) -{ - NRPixBlock *pb; - - pb = g_new (NRPixBlock, 1); - if (!pb) return 0; - - nr_pixblock_setup (pb, mode, x0, y0, x1, y1, clear); - if (pb->size!=NR_PIXBLOCK_SIZE_TINY && !pb->data.px) { - g_free(pb); - return 0; - } - - return pb; -} - -/** - * Allocates NRPixBlock and sets it up. - * - * \return Pointer to fresh pixblock. - * Calls g_new() and nr_pixblock_setup(). - */ -NRPixBlock * -nr_pixblock_new_fast (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear) -{ - NRPixBlock *pb; - - pb = g_new (NRPixBlock, 1); - if (!pb) return 0; - - nr_pixblock_setup_fast (pb, mode, x0, y0, x1, y1, clear); - if (pb->size!=NR_PIXBLOCK_SIZE_TINY && !pb->data.px) { - g_free(pb); - return 0; - } - - return pb; -} - -/** - * Frees all memory taken by pixblock. - * - * \return NULL - */ -NRPixBlock * -nr_pixblock_free (NRPixBlock *pb) -{ - nr_pixblock_release (pb); - - g_free (pb); - - return NULL; -} - -/* PixelStore operations */ - -#define NR_4K_BLOCK 32 -static unsigned char **nr_4K_px = NULL; -static unsigned int nr_4K_len = 0; -static unsigned int nr_4K_size = 0; - -unsigned char * -nr_pixelstore_4K_new (bool clear, unsigned char val) -{ - unsigned char *px; - - if (nr_4K_len != 0) { - nr_4K_len -= 1; - px = nr_4K_px[nr_4K_len]; - } else { - px = g_new (unsigned char, 4096); - } - - if (clear) memset (px, val, 4096); - - return px; -} - -void -nr_pixelstore_4K_free (unsigned char *px) -{ - if (nr_4K_len == nr_4K_size) { - nr_4K_size += NR_4K_BLOCK; - nr_4K_px = g_renew (unsigned char *, nr_4K_px, nr_4K_size); - } - - nr_4K_px[nr_4K_len] = px; - nr_4K_len += 1; -} - -#define NR_16K_BLOCK 32 -static unsigned char **nr_16K_px = NULL; -static unsigned int nr_16K_len = 0; -static unsigned int nr_16K_size = 0; - -unsigned char * -nr_pixelstore_16K_new (bool clear, unsigned char val) -{ - unsigned char *px; - - if (nr_16K_len != 0) { - nr_16K_len -= 1; - px = nr_16K_px[nr_16K_len]; - } else { - px = g_new (unsigned char, 16384); - } - - if (clear) memset (px, val, 16384); - - return px; -} - -void -nr_pixelstore_16K_free (unsigned char *px) -{ - if (nr_16K_len == nr_16K_size) { - nr_16K_size += NR_16K_BLOCK; - nr_16K_px = g_renew (unsigned char *, nr_16K_px, nr_16K_size); - } - - nr_16K_px[nr_16K_len] = px; - nr_16K_len += 1; -} - -#define NR_64K_BLOCK 32 -static unsigned char **nr_64K_px = NULL; -static unsigned int nr_64K_len = 0; -static unsigned int nr_64K_size = 0; - -unsigned char * -nr_pixelstore_64K_new (bool clear, unsigned char val) -{ - unsigned char *px; - - if (nr_64K_len != 0) { - nr_64K_len -= 1; - px = nr_64K_px[nr_64K_len]; - } else { - px = g_new (unsigned char, 65536); - } - - if (clear) memset (px, val, 65536); - - return px; -} - -void -nr_pixelstore_64K_free (unsigned char *px) -{ - if (nr_64K_len == nr_64K_size) { - nr_64K_size += NR_64K_BLOCK; - nr_64K_px = g_renew (unsigned char *, nr_64K_px, nr_64K_size); - } - - nr_64K_px[nr_64K_len] = px; - nr_64K_len += 1; -} - -#define NR_256K_BLOCK 32 -#define NR_256K 262144 -static unsigned char **nr_256K_px = NULL; -static unsigned int nr_256K_len = 0; -static unsigned int nr_256K_size = 0; - -unsigned char * -nr_pixelstore_256K_new (bool clear, unsigned char val) -{ - unsigned char *px; - - if (nr_256K_len != 0) { - nr_256K_len -= 1; - px = nr_256K_px[nr_256K_len]; - } else { - px = g_new (unsigned char, NR_256K); - } - - if (clear) memset (px, val, NR_256K); - - return px; -} - -void -nr_pixelstore_256K_free (unsigned char *px) -{ - if (nr_256K_len == nr_256K_size) { - nr_256K_size += NR_256K_BLOCK; - nr_256K_px = g_renew (unsigned char *, nr_256K_px, nr_256K_size); - } - - nr_256K_px[nr_256K_len] = px; - nr_256K_len += 1; -} - -#define NR_1M_BLOCK 32 -#define NR_1M 1048576 -static unsigned char **nr_1M_px = NULL; -static unsigned int nr_1M_len = 0; -static unsigned int nr_1M_size = 0; - -unsigned char * -nr_pixelstore_1M_new (bool clear, unsigned char val) -{ - unsigned char *px; - - if (nr_1M_len != 0) { - nr_1M_len -= 1; - px = nr_1M_px[nr_1M_len]; - } else { - px = g_new (unsigned char, NR_1M); - } - - if (clear) memset (px, val, NR_1M); - - return px; -} - -void -nr_pixelstore_1M_free (unsigned char *px) -{ - if (nr_1M_len == nr_1M_size) { - nr_1M_size += NR_1M_BLOCK; - nr_1M_px = g_renew (unsigned char *, nr_1M_px, nr_1M_size); - } - - nr_1M_px[nr_1M_len] = px; - nr_1M_len += 1; -} - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-pixblock.h b/src/libnr/nr-pixblock.h deleted file mode 100644 index cedc2ad3d..000000000 --- a/src/libnr/nr-pixblock.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef __NR_PIXBLOCK_H__ -#define __NR_PIXBLOCK_H__ - -/** \file - * \brief Pixel block structure. Used for low-level rendering. - * - * Authors: - * (C) 1999-2002 Lauris Kaplinski <lauris@kaplinski.com> - * (C) 2005 Ralf Stephan <ralf@ark.in-berlin.de> (some cleanup) - * - * This code is in the Public Domain. - */ - -#include <libnr/nr-rect-l.h> -#include <libnr/nr-forward.h> - -/// Size indicator. Hardcoded to max. 3 bits. -typedef enum { - NR_PIXBLOCK_SIZE_TINY, ///< Fits in (unsigned char *) - NR_PIXBLOCK_SIZE_4K, ///< Pixelstore - NR_PIXBLOCK_SIZE_16K, ///< Pixelstore - NR_PIXBLOCK_SIZE_64K, ///< Pixelstore - NR_PIXBLOCK_SIZE_256K, ///< Pixelstore - NR_PIXBLOCK_SIZE_1M, ///< Pixelstore - NR_PIXBLOCK_SIZE_BIG, ///< Normally allocated - NR_PIXBLOCK_SIZE_STATIC ///< Externally managed -} NR_PIXBLOCK_SIZE; - -/// Mode indicator. Hardcoded to max. 2 bits. -typedef enum { - NR_PIXBLOCK_MODE_A8, ///< Grayscale - NR_PIXBLOCK_MODE_R8G8B8, ///< 8 bit RGB - NR_PIXBLOCK_MODE_R8G8B8A8N, ///< Normal 8 bit RGBA - NR_PIXBLOCK_MODE_R8G8B8A8P ///< Premultiplied 8 bit RGBA -} NR_PIXBLOCK_MODE; - -/// The pixel block struct. -struct NRPixBlock { - NR_PIXBLOCK_SIZE size : 3; ///< Size indicator - NR_PIXBLOCK_MODE mode : 2; ///< Mode indicator - bool empty : 1; ///< Empty flag - unsigned int rs; ///< Size of line in bytes - NRRectL area; - NRRectL visible_area; - union { - unsigned char *px; ///< Pointer to buffer - unsigned char p[sizeof (unsigned char *)]; ///< Tiny buffer - } data; -}; - -/// Returns number of bytes per pixel (1, 3, or 4). -inline int -NR_PIXBLOCK_BPP (NRPixBlock *pb) -{ - return ((pb->mode == NR_PIXBLOCK_MODE_A8) ? 1 : - (pb->mode == NR_PIXBLOCK_MODE_R8G8B8) ? 3 : 4); -} - -/// Returns pointer to pixel data. -inline unsigned char* -NR_PIXBLOCK_PX (NRPixBlock *pb) -{ - return ((pb->size == NR_PIXBLOCK_SIZE_TINY) ? - pb->data.p : pb->data.px); -} -inline unsigned char const* -NR_PIXBLOCK_PX (NRPixBlock const *pb) -{ - return ((pb->size == NR_PIXBLOCK_SIZE_TINY) ? - pb->data.p : pb->data.px); -} - -void nr_pixblock_setup (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear); -void nr_pixblock_setup_fast (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear); -void nr_pixblock_setup_extern (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, unsigned char *px, int rs, bool empty, bool clear); -void nr_pixblock_release (NRPixBlock *pb); - -NRPixBlock *nr_pixblock_new (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear); -NRPixBlock *nr_pixblock_new_fast (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear); -NRPixBlock *nr_pixblock_free (NRPixBlock *pb); - -unsigned char *nr_pixelstore_4K_new (bool clear, unsigned char val); -void nr_pixelstore_4K_free (unsigned char *px); -unsigned char *nr_pixelstore_16K_new (bool clear, unsigned char val); -void nr_pixelstore_16K_free (unsigned char *px); -unsigned char *nr_pixelstore_64K_new (bool clear, unsigned char val); -void nr_pixelstore_64K_free (unsigned char *px); -unsigned char *nr_pixelstore_256K_new (bool clear, unsigned char val); -void nr_pixelstore_256K_free (unsigned char *px); -unsigned char *nr_pixelstore_1M_new (bool clear, unsigned char val); -void nr_pixelstore_1M_free (unsigned char *px); - -#endif -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/libnr/nr-pixops.h b/src/libnr/nr-pixops.h deleted file mode 100644 index 7eafd1a9d..000000000 --- a/src/libnr/nr-pixops.h +++ /dev/null @@ -1,148 +0,0 @@ -#ifndef __NR_PIXOPS_H__ -#define __NR_PIXOPS_H__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * bulia byak <buliabyak@users.sf.net> - * - * This code is in public domain - */ - -#define NR_RGBA32_R(v) (unsigned char) (((v) >> 24) & 0xff) -#define NR_RGBA32_G(v) (unsigned char) (((v) >> 16) & 0xff) -#define NR_RGBA32_B(v) (unsigned char) (((v) >> 8) & 0xff) -#define NR_RGBA32_A(v) (unsigned char) ((v) & 0xff) - -// FAST_DIVIDE assumes that 0<=num<=256*denom -// (this covers the case that num=255*denom+denom/2, which is used by DIV_ROUND) -template<unsigned int divisor> static inline unsigned int FAST_DIVIDE(unsigned int v) { return v/divisor; } -template<> inline unsigned int FAST_DIVIDE<255>(unsigned int v) { return ((v+1)*0x101) >> 16; } -template<> inline unsigned int FAST_DIVIDE<255*255>(unsigned int v) { v=(v+1)<<1; v=v+(v>>7)+((v*0x3)>>16)+(v>>22); return (v>>16)>>1; } -// FAST_DIV_ROUND assumes that 0<=num<=255*denom (DIV_ROUND should work upto num=2^32-1-(denom/2), -// but FAST_DIVIDE_BY_255 already fails at num=65790=258*255, which is not too far above 255.5*255) -template<unsigned int divisor> static inline unsigned int FAST_DIV_ROUND(unsigned int v) { return FAST_DIVIDE<divisor>(v+(divisor)/2); } -static inline unsigned int DIV_ROUND(unsigned int v, unsigned int divisor) { return (v+divisor/2)/divisor; } - -#define INK_COMPOSE(f,a,b) ( ( ((guchar) (b)) * ((guchar) (0xff - (a))) + ((guchar) (((b) ^ ~(f)) + (b)/4 - ((b)>127? 63 : 0))) * ((guchar) (a)) ) >>8) - -// Naming: OPb_i+o -// OP = operation, for example: NORMALIZE, COMPOSEA, COMPOSENNN, PREMUL, etc. -// i+o = range of input/output as powers of 2^8-1 -// for example, 213 means 0<=a<=255^2, 0<=b<=255, 0<=output<=255^3 - -// Normalize -static inline unsigned int NR_NORMALIZE_11(unsigned int v) { return v; } -static inline unsigned int NR_NORMALIZE_21(unsigned int v) { return FAST_DIV_ROUND<255>(v); } -static inline unsigned int NR_NORMALIZE_31(unsigned int v) { return FAST_DIV_ROUND<255*255>(v); } -static inline unsigned int NR_NORMALIZE_41(unsigned int v) { return FAST_DIV_ROUND<255*255*255>(v); } - -// Compose alpha channel using (1 - (1-a)*(1-b)) -// Note that these can also be rewritten to NR_COMPOSENPP(255, a, b), slightly slower, but could help if someone -// decides to use SSE or something similar (for allowing the four components to be treated the same way). -static inline unsigned int NR_COMPOSEA_213(unsigned int a, unsigned int b) { return 255*255*255 - (255*255-a)*(255-b); } -static inline unsigned int NR_COMPOSEA_112(unsigned int a, unsigned int b) { return 255*255 - (255-a)*(255-b); } -static inline unsigned int NR_COMPOSEA_211(unsigned int a, unsigned int b) { return NR_NORMALIZE_31(NR_COMPOSEA_213(a, b)); } -static inline unsigned int NR_COMPOSEA_111(unsigned int a, unsigned int b) { return NR_NORMALIZE_21(NR_COMPOSEA_112(a, b)); } - -// Operation: (1 - fa) * bc * ba + fa * fc -static inline unsigned int NR_COMPOSENNP_12114(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return (255*255 - fa) * ba * bc + 255 * fa * fc; } -static inline unsigned int NR_COMPOSENNP_11113(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return (255 - fa) * ba * bc + 255 * fa * fc; } -static inline unsigned int NR_COMPOSENNP_11111(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return NR_NORMALIZE_31(NR_COMPOSENNP_11113(fc, fa, bc, ba)); } - -// Operation: (1 - fa) * bc * ba + fc -static inline unsigned int NR_COMPOSEPNP_32114(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return (255*255 - fa) * ba * bc + 255 * fc; } -static inline unsigned int NR_COMPOSEPNP_22114(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return (255*255 - fa) * ba * bc + 255*255 * fc; } -static inline unsigned int NR_COMPOSEPNP_11113(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return (255 - fa) * ba * bc + 255*255 * fc; } -static inline unsigned int NR_COMPOSEPNP_22111(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return NR_NORMALIZE_41(NR_COMPOSEPNP_22114(fc, fa, bc, ba)); } -static inline unsigned int NR_COMPOSEPNP_11111(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba) { return NR_NORMALIZE_31(NR_COMPOSEPNP_11113(fc, fa, bc, ba)); } - -// Operation: ((1 - fa) * bc * ba + fa * fc)/a -// Reuses non-normalized versions of NR_COMPOSENNP -static inline unsigned int NR_COMPOSENNN_121131(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba, unsigned int a) { return DIV_ROUND(NR_COMPOSENNP_12114(fc, fa, bc, ba), a); } -static inline unsigned int NR_COMPOSENNN_111121(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba, unsigned int a) { return DIV_ROUND(NR_COMPOSENNP_11113(fc, fa, bc, ba), a); } - -// Operation: ((1 - fa) * bc * ba + fc)/a -// Reuses non-normalized versions of NR_COMPOSEPNP -static inline unsigned int NR_COMPOSEPNN_321131(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba, unsigned int a) { return DIV_ROUND(NR_COMPOSEPNP_32114(fc, fa, bc, ba), a); } -static inline unsigned int NR_COMPOSEPNN_221131(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba, unsigned int a) { return DIV_ROUND(NR_COMPOSEPNP_22114(fc, fa, bc, ba), a); } -static inline unsigned int NR_COMPOSEPNN_111121(unsigned int fc, unsigned int fa, unsigned int bc, unsigned int ba, unsigned int a) { return DIV_ROUND(NR_COMPOSEPNP_11113(fc, fa, bc, ba), a); } - -// Operation: (1 - fa) * bc + fa * fc -// (1-fa)*bc+fa*fc = bc-fa*bc+fa*fc = bc+fa*(fc-bc) -// For some reason it's faster to leave the initial 255*bc term in the non-normalized version instead of factoring it out... -static inline unsigned int NR_COMPOSENPP_1213(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*255*bc + fa*(fc-bc); } -static inline unsigned int NR_COMPOSENPP_1123(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*bc + fa*(255*fc-bc); } -static inline unsigned int NR_COMPOSENPP_1112(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*bc + fa*(fc-bc); } -static inline unsigned int NR_COMPOSENPP_1211(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_31(NR_COMPOSENPP_1213(fc, fa, bc)); } -static inline unsigned int NR_COMPOSENPP_1121(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_31(NR_COMPOSENPP_1123(fc, fa, bc)); } -static inline unsigned int NR_COMPOSENPP_1111(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_21(NR_COMPOSENPP_1112(fc, fa, bc)); } - -// Operation: (1 - fa) * bc + fc -// (1-fa)*bc+fc = bc-fa*bc+fc = (bc+fc)-fa*bc -// This rewritten form results in faster code (found out through testing) -static inline unsigned int NR_COMPOSEPPP_2224(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*255*(bc+fc) - fa*bc; } // Note that this can temporarily overflow (but it probably doesn't cause problems) - // NR_COMPOSEPPP_2224 assumes that fa and fc have a common component (fa=a*x and fc=c*x), because then the maximum value is: - // (255*255-255*x)*255*255 + 255*x*255*255 = 255*255*( (255*255-255*x) + 255*x ) = 255*255*255*( (255-x)+x ) = 255*255*255*255 -static inline unsigned int NR_COMPOSEPPP_3213(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*255*bc + fc - fa*bc; } -static inline unsigned int NR_COMPOSEPPP_2213(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*(255*bc+fc) - fa*bc; } -static inline unsigned int NR_COMPOSEPPP_1213(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*255*(bc+fc) - fa*bc; } -static inline unsigned int NR_COMPOSEPPP_1112(unsigned int fc, unsigned int fa, unsigned int bc) { return 255*(bc+fc) - fa*bc; } -static inline unsigned int NR_COMPOSEPPP_2221(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_41(NR_COMPOSEPPP_2224(fc, fa, bc)); } -static inline unsigned int NR_COMPOSEPPP_3211(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_31(NR_COMPOSEPPP_3213(fc, fa, bc)); } -static inline unsigned int NR_COMPOSEPPP_2211(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_31(NR_COMPOSEPPP_2213(fc, fa, bc)); } -static inline unsigned int NR_COMPOSEPPP_1211(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_21(NR_COMPOSEPPP_1213(fc, fa, bc)); } -static inline unsigned int NR_COMPOSEPPP_1111(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_21(NR_COMPOSEPPP_1112(fc, fa, bc)); } - -#define NR_COMPOSEN11_1211 NR_COMPOSENPP_1211 -#define NR_COMPOSEN11_1111 NR_COMPOSENPP_1111 -//inline unsigned int NR_COMPOSEN11_1111(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_21((255 - fa) * bc + fa * fc ); } - -#define NR_COMPOSEP11_2211 NR_COMPOSEPPP_2211 -#define NR_COMPOSEP11_1211 NR_COMPOSEPPP_1211 -#define NR_COMPOSEP11_1111 NR_COMPOSEPPP_1111 -//inline unsigned int NR_COMPOSEP11_1111(unsigned int fc, unsigned int fa, unsigned int bc) { return NR_NORMALIZE_21((255 - fa) * bc + fc * 255); } - -// Premultiply using c*a -static inline unsigned int NR_PREMUL_134(unsigned int c, unsigned int a) { return c * a; } -static inline unsigned int NR_PREMUL_224(unsigned int c, unsigned int a) { return c * a; } -static inline unsigned int NR_PREMUL_123(unsigned int c, unsigned int a) { return c * a; } -static inline unsigned int NR_PREMUL_112(unsigned int c, unsigned int a) { return c * a; } -static inline unsigned int NR_PREMUL_314(unsigned int c, unsigned int a) { return NR_PREMUL_134(c, a); } -static inline unsigned int NR_PREMUL_213(unsigned int c, unsigned int a) { return NR_PREMUL_123(c, a); } -static inline unsigned int NR_PREMUL_131(unsigned int c, unsigned int a) { return NR_NORMALIZE_41(NR_PREMUL_134(c, a)); } -static inline unsigned int NR_PREMUL_221(unsigned int c, unsigned int a) { return NR_NORMALIZE_41(NR_PREMUL_224(c, a)); } -static inline unsigned int NR_PREMUL_121(unsigned int c, unsigned int a) { return NR_NORMALIZE_31(NR_PREMUL_123(c, a)); } -static inline unsigned int NR_PREMUL_111(unsigned int c, unsigned int a) { return NR_NORMALIZE_21(NR_PREMUL_112(c, a)); } -static inline unsigned int NR_PREMUL_311(unsigned int c, unsigned int a) { return NR_NORMALIZE_41(NR_PREMUL_314(c, a)); } -static inline unsigned int NR_PREMUL_211(unsigned int c, unsigned int a) { return NR_NORMALIZE_31(NR_PREMUL_213(c, a)); } - -// Demultiply using c/a -static inline unsigned int NR_DEMUL_131(unsigned int c, unsigned int a) { return DIV_ROUND(255 * 255 * 255 * c, a); } -static inline unsigned int NR_DEMUL_231(unsigned int c, unsigned int a) { return DIV_ROUND(255 * 255 * c, a); } -static inline unsigned int NR_DEMUL_121(unsigned int c, unsigned int a) { return DIV_ROUND(255 * 255 * c, a); } -static inline unsigned int NR_DEMUL_331(unsigned int c, unsigned int a) { return DIV_ROUND(255 * c, a); } -static inline unsigned int NR_DEMUL_221(unsigned int c, unsigned int a) { return DIV_ROUND(255 * c, a); } -static inline unsigned int NR_DEMUL_111(unsigned int c, unsigned int a) { return DIV_ROUND(255 * c, a); } -static inline unsigned int NR_DEMUL_431(unsigned int c, unsigned int a) { return DIV_ROUND(c, a); } -static inline unsigned int NR_DEMUL_321(unsigned int c, unsigned int a) { return DIV_ROUND(c, a); } -static inline unsigned int NR_DEMUL_211(unsigned int c, unsigned int a) { return DIV_ROUND(c, a); } -static inline unsigned int NR_DEMUL_421(unsigned int c, unsigned int a) { return DIV_ROUND(c, 255 * a); } -static inline unsigned int NR_DEMUL_311(unsigned int c, unsigned int a) { return DIV_ROUND(c, 255 * a); } -static inline unsigned int NR_DEMUL_411(unsigned int c, unsigned int a) { return DIV_ROUND(c, 255 * 255 * a); } - - -#endif - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/ui/cache/svg_preview_cache.cpp b/src/ui/cache/svg_preview_cache.cpp index d4c8d0d0c..aead24236 100644 --- a/src/ui/cache/svg_preview_cache.cpp +++ b/src/ui/cache/svg_preview_cache.cpp @@ -28,7 +28,7 @@ #include "document-private.h" #include "display/nr-arena.h" #include "display/nr-arena-item.h" -#include "libnr/nr-pixblock.h" +#include "display/cairo-utils.h" #include "ui/cache/svg_preview_cache.h" @@ -45,10 +45,10 @@ GdkPixbuf* render_pixbuf(NRArenaItem* root, double scale_factor, const Geom::Rec /* Item integer bbox in points */ NRRectL ibox; - ibox.x0 = (int) floor(scale_factor * dbox.min()[Geom::X] + 0.5); - ibox.y0 = (int) floor(scale_factor * dbox.min()[Geom::Y] + 0.5); - ibox.x1 = (int) floor(scale_factor * dbox.max()[Geom::X] + 0.5); - ibox.y1 = (int) floor(scale_factor * dbox.max()[Geom::Y] + 0.5); + ibox.x0 = floor(scale_factor * dbox.min()[Geom::X]); + ibox.y0 = floor(scale_factor * dbox.min()[Geom::Y]); + ibox.x1 = ceil(scale_factor * dbox.max()[Geom::X]); + ibox.y1 = ceil(scale_factor * dbox.max()[Geom::Y]); /* Find visible area */ int width = ibox.x1 - ibox.x0; @@ -64,34 +64,23 @@ GdkPixbuf* render_pixbuf(NRArenaItem* root, double scale_factor, const Geom::Rec area.x1 = area.x0 + psize; area.y1 = area.y0 + psize; - /* Actual renderable area */ - NRRectL ua; - ua.x0 = std::max(ibox.x0, area.x0); - ua.y0 = std::max(ibox.y0, area.y0); - ua.x1 = std::min(ibox.x1, area.x1); - ua.y1 = std::min(ibox.y1, area.y1); - - /* Set up pixblock */ - guchar *px = g_new(guchar, 4 * psize * psize); - memset(px, 0x00, 4 * psize * psize); - /* Render */ - NRPixBlock B; - nr_pixblock_setup_extern( &B, NR_PIXBLOCK_MODE_R8G8B8A8N, - ua.x0, ua.y0, ua.x1, ua.y1, - px + 4 * psize * (ua.y0 - area.y0) + - 4 * (ua.x0 - area.x0), - 4 * psize, FALSE, FALSE ); - nr_arena_item_invoke_render(NULL, root, &ua, &B, + cairo_surface_t *s = cairo_image_surface_create( + CAIRO_FORMAT_ARGB32, psize, psize); + cairo_t *ct = cairo_create(s); + + nr_arena_item_invoke_render(ct, root, &area, NULL, NR_ARENA_ITEM_RENDER_NO_CACHE ); - nr_pixblock_release(&B); + cairo_surface_flush(s); + cairo_destroy(ct); - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(px, + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(cairo_image_surface_get_data(s), GDK_COLORSPACE_RGB, TRUE, - 8, psize, psize, psize * 4, - (GdkPixbufDestroyNotify)g_free, + 8, psize, psize, cairo_image_surface_get_stride(s), + (GdkPixbufDestroyNotify)cairo_surface_destroy, NULL); + convert_pixbuf_argb32_to_normal(pixbuf); return pixbuf; } diff --git a/src/ui/dialog/filedialogimpl-win32.cpp b/src/ui/dialog/filedialogimpl-win32.cpp index 7b96f2a9e..cd9db2fac 100644 --- a/src/ui/dialog/filedialogimpl-win32.cpp +++ b/src/ui/dialog/filedialogimpl-win32.cpp @@ -33,7 +33,6 @@ #include "extension/output.h" #include "extension/db.h" -#include "libnr/nr-pixops.h" #include "display/nr-arena-item.h" #include "display/nr-arena.h" #include "sp-item.h" @@ -882,6 +881,10 @@ void FileOpenDialogImplWin32::free_preview() bool FileOpenDialogImplWin32::set_svg_preview() { + return false; + // NOTE: it's not worth the effort to fix this to use Cairo. + // Native file dialogs are unmaintainable and should be removed anyway. + #if 0 const int PreviewSize = 512; gchar *utf8string = g_utf16_to_utf8((const gunichar2*)_path_string, @@ -980,6 +983,7 @@ bool FileOpenDialogImplWin32::set_svg_preview() _mutex->unlock(); return true; + #endif } void FileOpenDialogImplWin32::destroy_svg_rendering(const guint8 *buffer) diff --git a/src/ui/widget/color-preview.cpp b/src/ui/widget/color-preview.cpp index add596444..a4212c7ba 100644 --- a/src/ui/widget/color-preview.cpp +++ b/src/ui/widget/color-preview.cpp @@ -11,8 +11,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "display/nr-plain-stuff-gdk.h" -#include "color-preview.h" +#include "ui/widget/color-preview.h" +#include "display/cairo-utils.h" #define SPCP_DEFAULT_WIDTH 32 #define SPCP_DEFAULT_HEIGHT 12 @@ -76,6 +76,9 @@ ColorPreview::paint (GdkRectangle *area) if (!gdk_rectangle_intersect (area, &warea, &wpaint)) return; + GtkWidget *widget = GTK_WIDGET(this->gobj()); + cairo_t *ct = gdk_cairo_create(widget->window); + /* Transparent area */ w2 = warea.width / 2; @@ -86,11 +89,15 @@ ColorPreview::paint (GdkRectangle *area) carea.height = warea.height; if (gdk_rectangle_intersect (area, &carea, &cpaint)) { - nr_gdk_draw_rgba32_solid (get_window()->gobj(), - get_style()->get_black_gc()->gobj(), - cpaint.x, cpaint.y, - cpaint.width, cpaint.height, - _rgba); + cairo_pattern_t *checkers = ink_cairo_pattern_create_checkerboard(); + + cairo_rectangle(ct, carea.x, carea.y, carea.width, carea.height); + cairo_set_source(ct, checkers); + cairo_fill_preserve(ct); + ink_cairo_set_source_rgba32(ct, _rgba); + cairo_fill(ct); + + cairo_pattern_destroy(checkers); } /* Solid area */ @@ -101,12 +108,12 @@ ColorPreview::paint (GdkRectangle *area) carea.height = warea.height; if (gdk_rectangle_intersect (area, &carea, &cpaint)) { - nr_gdk_draw_rgba32_solid (get_window()->gobj(), - get_style()->get_black_gc()->gobj(), - cpaint.x, cpaint.y, - cpaint.width, cpaint.height, - _rgba | 0xff); + cairo_rectangle(ct, carea.x, carea.y, carea.width, carea.height); + ink_cairo_set_source_rgba32(ct, _rgba | 0xff); + cairo_fill(ct); } + + cairo_destroy(ct); } }}} diff --git a/src/widgets/Makefile_insert b/src/widgets/Makefile_insert index 313e27528..968bbf073 100644 --- a/src/widgets/Makefile_insert +++ b/src/widgets/Makefile_insert @@ -42,8 +42,6 @@ ink_common_sources += \ widgets/sp-color-icc-selector.h \ widgets/sp-color-notebook.cpp \ widgets/sp-color-notebook.h \ - widgets/sp-color-preview.cpp \ - widgets/sp-color-preview.h \ widgets/sp-color-scales.cpp \ widgets/sp-color-scales.h \ widgets/sp-color-selector.cpp \ diff --git a/src/widgets/gradient-image.cpp b/src/widgets/gradient-image.cpp index c4b7216c6..ef05ad381 100644 --- a/src/widgets/gradient-image.cpp +++ b/src/widgets/gradient-image.cpp @@ -12,7 +12,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include <libnr/nr-pixblock-pattern.h> #include "macros.h" #include "display/cairo-utils.h" #include "gradient-image.h" diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 7f0256665..f37158eec 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -420,7 +420,7 @@ void SPGradientVectorSelector::setSwatched() ##################################################################*/ #include "../widgets/sp-color-notebook.h" -#include "../widgets/sp-color-preview.h" +#include "ui/widget/color-preview.h" #include "../widgets/widget-sizes.h" #include "../xml/node-event-vector.h" #include "../svg/svg-color.h" @@ -558,7 +558,8 @@ static void update_stop_list( GtkWidget *mnu, SPGradient *gradient, SPStop *new_ gtk_widget_show(i); g_object_set_data(G_OBJECT(i), "stop", stop); GtkWidget *hb = gtk_hbox_new(FALSE, 4); - GtkWidget *cpv = sp_color_preview_new(sp_stop_get_rgba32(stop)); + GtkWidget *cpv = GTK_WIDGET(Gtk::manage( + new Inkscape::UI::Widget::ColorPreview(sp_stop_get_rgba32(stop)))->gobj()); gtk_widget_show(cpv); gtk_container_add( GTK_CONTAINER(hb), cpv ); g_object_set_data( G_OBJECT(i), "preview", cpv ); @@ -1190,8 +1191,8 @@ static void sp_gradient_vector_color_changed(SPColorSelector *csel, GtkObject *o blocked = FALSE; - SPColorPreview *cpv = static_cast<SPColorPreview *>(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "preview")); - sp_color_preview_set_rgba32(cpv, sp_stop_get_rgba32(stop)); + Inkscape::UI::Widget::ColorPreview *cpv = static_cast<Inkscape::UI::Widget::ColorPreview *>(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "preview")); + cpv->setRgba32(sp_stop_get_rgba32(stop)); } /* diff --git a/src/widgets/sp-color-preview.cpp b/src/widgets/sp-color-preview.cpp deleted file mode 100644 index ddeb5d123..000000000 --- a/src/widgets/sp-color-preview.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* - * A simple color preview widget - * - * Author: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * Copyright (C) 2001-2002 Lauris Kaplinski - * Copyright (C) 2001 Ximian, Inc. - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "../display/nr-plain-stuff-gdk.h" -#include "sp-color-preview.h" - -#define SPCP_DEFAULT_WIDTH 32 -#define SPCP_DEFAULT_HEIGHT 11 - -static void sp_color_preview_class_init (SPColorPreviewClass *klass); -static void sp_color_preview_init (SPColorPreview *image); -static void sp_color_preview_destroy (GtkObject *object); - -static void sp_color_preview_size_request (GtkWidget *widget, GtkRequisition *requisition); -static void sp_color_preview_size_allocate (GtkWidget *widget, GtkAllocation *allocation); -static gint sp_color_preview_expose (GtkWidget *widget, GdkEventExpose *event); - -static void sp_color_preview_paint (SPColorPreview *cp, GdkRectangle *area); - -static GtkWidgetClass *parent_class; - -GType sp_color_preview_get_type(void) -{ - static GType type = 0; - if (!type) { - static const GTypeInfo info = { - sizeof(SPColorPreviewClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_color_preview_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(SPColorPreview), - 0, /* n_preallocs */ - (GInstanceInitFunc) sp_color_preview_init, - 0, /* value_table */ - }; - - type = g_type_register_static( GTK_TYPE_WIDGET, - "SPColorPreview", - &info, - static_cast< GTypeFlags > (0) ); - } - return type; -} - -static void -sp_color_preview_class_init (SPColorPreviewClass *klass) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) klass; - widget_class = (GtkWidgetClass *) klass; - - parent_class = (GtkWidgetClass*)gtk_type_class (GTK_TYPE_WIDGET); - - object_class->destroy = sp_color_preview_destroy; - - widget_class->size_request = sp_color_preview_size_request; - widget_class->size_allocate = sp_color_preview_size_allocate; - widget_class->expose_event = sp_color_preview_expose; -} - -static void -sp_color_preview_init (SPColorPreview *image) -{ - GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW); - - image->rgba = 0xffffffff; -} - -static void -sp_color_preview_destroy (GtkObject *object) -{ - SPColorPreview *image; - - image = SP_COLOR_PREVIEW (object); - - if (((GtkObjectClass *) (parent_class))->destroy) - (* ((GtkObjectClass *) (parent_class))->destroy) (object); -} - -static void -sp_color_preview_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - SPColorPreview *slider; - - slider = SP_COLOR_PREVIEW (widget); - - requisition->width = SPCP_DEFAULT_WIDTH; - requisition->height = SPCP_DEFAULT_HEIGHT; -} - -static void -sp_color_preview_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - SPColorPreview *image; - - image = SP_COLOR_PREVIEW (widget); - - widget->allocation = *allocation; - - if (GTK_WIDGET_DRAWABLE (image)) { - gtk_widget_queue_draw (GTK_WIDGET (image)); - } -} - -static gint -sp_color_preview_expose (GtkWidget *widget, GdkEventExpose *event) -{ - SPColorPreview *cp; - - cp = SP_COLOR_PREVIEW (widget); - - if (GTK_WIDGET_DRAWABLE (widget)) { - sp_color_preview_paint (cp, &event->area); - } - - return TRUE; -} - -GtkWidget * -sp_color_preview_new (guint32 rgba) -{ - SPColorPreview *image; - - image = (SPColorPreview*)gtk_type_new (SP_TYPE_COLOR_PREVIEW); - - sp_color_preview_set_rgba32 (image, rgba); - - return (GtkWidget *) image; -} - -void -sp_color_preview_set_rgba32 (SPColorPreview *cp, guint32 rgba) -{ - cp->rgba = rgba; - - if (GTK_WIDGET_DRAWABLE (cp)) { - gtk_widget_queue_draw (GTK_WIDGET (cp)); - } -} - -static void -sp_color_preview_paint (SPColorPreview *cp, GdkRectangle *area) -{ - GtkWidget *widget; - GdkRectangle warea, carea; - GdkRectangle wpaint, cpaint; - gint w2; - - widget = GTK_WIDGET (cp); - - warea.x = widget->allocation.x; - warea.y = widget->allocation.y; - warea.width = widget->allocation.width; - warea.height = widget->allocation.height; - - if (!gdk_rectangle_intersect (area, &warea, &wpaint)) return; - - /* Transparent area */ - - w2 = warea.width / 2; - - carea.x = warea.x; - carea.y = warea.y; - carea.width = w2; - carea.height = warea.height; - - if (gdk_rectangle_intersect (area, &carea, &cpaint)) { - nr_gdk_draw_rgba32_solid (widget->window, widget->style->black_gc, - cpaint.x, cpaint.y, - cpaint.width, cpaint.height, - cp->rgba); - } - - /* Solid area */ - - carea.x = warea.x + w2; - carea.y = warea.y; - carea.width = warea.width - w2; - carea.height = warea.height; - - if (gdk_rectangle_intersect (area, &carea, &cpaint)) { - nr_gdk_draw_rgba32_solid (widget->window, widget->style->black_gc, - cpaint.x, cpaint.y, - cpaint.width, cpaint.height, - cp->rgba | 0xff); - } -} - -/* - 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:encoding=utf-8:textwidth=99 : diff --git a/src/widgets/sp-color-preview.h b/src/widgets/sp-color-preview.h deleted file mode 100644 index 873e59d80..000000000 --- a/src/widgets/sp-color-preview.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef SEEN_COLOR_PREVIEW_H -#define SEEN_COLOR_PREVIEW_H - -/* - * A simple color preview widget - * - * Author: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * Copyright (C) 2001-2002 Lauris Kaplinski - * Copyright (C) 2001 Ximian, Inc. - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include <gtk/gtkwidget.h> - -#include <glib.h> - - - -#define SP_TYPE_COLOR_PREVIEW (sp_color_preview_get_type ()) -#define SP_COLOR_PREVIEW(o) (GTK_CHECK_CAST ((o), SP_TYPE_COLOR_PREVIEW, SPColorPreview)) -#define SP_COLOR_PREVIEW_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), SP_TYPE_COLOR_PREVIEW, SPColorPreviewClass)) -#define SP_IS_COLOR_PREVIEW(o) (GTK_CHECK_TYPE ((o), SP_TYPE_COLOR_PREVIEW)) -#define SP_IS_COLOR_PREVIEW_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), SP_TYPE_COLOR_PREVIEW)) - -struct SPColorPreview { - GtkWidget widget; - - guint32 rgba; -}; - -struct SPColorPreviewClass { - GtkWidgetClass parent_class; -}; - -GType sp_color_preview_get_type(void); - -GtkWidget *sp_color_preview_new(guint32 rgba); - -void sp_color_preview_set_rgba32(SPColorPreview *cp, guint32 color); - - -#endif // SEEN_COLOR_PREVIEW_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:encoding=utf-8:textwidth=99 : |
