15
15
#include <libnr/nr-compose-transform.h>
16
#include <2geom/transforms.h>
16
17
#include <libnr/nr-blit.h>
17
#include "../prefs-utils.h"
18
#include "../preferences.h"
18
19
#include "nr-arena-image.h"
20
21
#include "display/nr-arena.h"
21
22
#include "display/nr-filter.h"
22
23
#include "display/nr-filter-gaussian.h"
23
#include <livarot/Path.h>
24
#include <livarot/Shape.h>
25
24
#include "sp-filter.h"
26
25
#include "sp-filter-reference.h"
27
26
#include "sp-gaussian-blur.h"
28
#include "sp-feblend.h"
27
#include "filters/blend.h"
29
28
#include "display/nr-filter-blend.h"
31
30
int nr_arena_image_x_sample = 1;
39
// defined in nr-arena-shape.cpp
40
void nr_pixblock_render_shape_mask_or(NRPixBlock &m, Shape *theS);
42
38
static void nr_arena_image_class_init (NRArenaImageClass *klass);
43
39
static void nr_arena_image_init (NRArenaImage *image);
44
40
static void nr_arena_image_finalize (NRObject *object);
46
42
static unsigned int nr_arena_image_update (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int state, unsigned int reset);
47
43
static unsigned int nr_arena_image_render (cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags);
48
static NRArenaItem *nr_arena_image_pick (NRArenaItem *item, NR::Point p, double delta, unsigned int sticky);
44
static NRArenaItem *nr_arena_image_pick (NRArenaItem *item, Geom::Point p, double delta, unsigned int sticky);
50
46
static NRArenaItemClass *parent_class;
111
107
static unsigned int
112
108
nr_arena_image_update( NRArenaItem *item, NRRectL */*area*/, NRGC *gc, unsigned int /*state*/, unsigned int /*reset*/ )
110
Geom::Matrix grid2px;
113
nr_arena_item_request_render(item);
116
115
NRArenaImage *image = NR_ARENA_IMAGE (item);
118
/* Request render old */
119
nr_arena_item_request_render (item);
121
117
/* Copy affine */
122
nr_matrix_invert (&grid2px, &gc->transform);
123
double hscale, vscale; // todo: replace with NR::scale
118
grid2px = gc->transform.inverse();
119
double hscale, vscale; // todo: replace with Geom::Scale
125
121
hscale = image->pxw / image->width;
126
122
vscale = image->pxh / image->height;
132
image->grid2px[0] = grid2px.c[0] * hscale;
133
image->grid2px[2] = grid2px.c[2] * hscale;
134
image->grid2px[4] = grid2px.c[4] * hscale;
135
image->grid2px[1] = grid2px.c[1] * vscale;
136
image->grid2px[3] = grid2px.c[3] * vscale;
137
image->grid2px[5] = grid2px.c[5] * vscale;
128
image->grid2px[0] = grid2px[0] * hscale;
129
image->grid2px[2] = grid2px[2] * hscale;
130
image->grid2px[4] = grid2px[4] * hscale;
131
image->grid2px[1] = grid2px[1] * vscale;
132
image->grid2px[3] = grid2px[3] * vscale;
133
image->grid2px[5] = grid2px[5] * vscale;
139
135
image->grid2px[4] -= image->x * hscale;
140
136
image->grid2px[5] -= image->y * vscale;
148
144
bbox.x1 = image->x + image->width;
149
145
bbox.y1 = image->y + image->height;
151
image->c00 = (NR::Point(bbox.x0, bbox.y0) * gc->transform);
152
image->c01 = (NR::Point(bbox.x0, bbox.y1) * gc->transform);
153
image->c10 = (NR::Point(bbox.x1, bbox.y0) * gc->transform);
154
image->c11 = (NR::Point(bbox.x1, bbox.y1) * gc->transform);
147
image->c00 = (Geom::Point(bbox.x0, bbox.y0) * gc->transform);
148
image->c01 = (Geom::Point(bbox.x0, bbox.y1) * gc->transform);
149
image->c10 = (Geom::Point(bbox.x1, bbox.y0) * gc->transform);
150
image->c11 = (Geom::Point(bbox.x1, bbox.y1) * gc->transform);
156
nr_rect_d_matrix_transform (&bbox, &bbox, &gc->transform);
152
nr_rect_d_matrix_transform (&bbox, &bbox, gc->transform);
158
154
item->bbox.x0 = (int) floor (bbox.x0);
159
155
item->bbox.y0 = (int) floor (bbox.y0);
177
171
static unsigned int
178
172
nr_arena_image_render( cairo_t *ct, NRArenaItem *item, NRRectL */*area*/, NRPixBlock *pb, unsigned int /*flags*/ )
180
nr_arena_image_x_sample = prefs_get_int_attribute ("options.bitmapoversample", "value", 1);
174
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
175
nr_arena_image_x_sample = prefs->getInt("/options/bitmapoversample/value", 1);
181
176
nr_arena_image_y_sample = nr_arena_image_x_sample;
183
bool outline = (item->arena->rendermode == RENDERMODE_OUTLINE);
178
bool outline = (item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE);
185
180
NRArenaImage *image = NR_ARENA_IMAGE (item);
233
228
return item->state;
235
guint32 rgba = prefs_get_int_attribute("options.wireframecolors", "images", 0xff0000ff);
230
guint32 rgba = prefs->getInt("/options/wireframecolors/images", 0xff0000ff);
236
231
// FIXME: we use RGBA buffers but cairo writes BGRA (on i386), so we must cheat
237
232
// by setting color channels in the "wrong" order
238
233
cairo_set_source_rgba(ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba));
240
235
cairo_set_line_width(ct, 0.5);
241
236
cairo_new_path(ct);
243
NR::Point shift(pb->area.x0, pb->area.y0);
244
NR::Point c00 = image->c00 - shift;
245
NR::Point c01 = image->c01 - shift;
246
NR::Point c11 = image->c11 - shift;
247
NR::Point c10 = image->c10 - shift;
238
Geom::Point shift(pb->area.x0, pb->area.y0);
239
Geom::Point c00 = image->c00 - shift;
240
Geom::Point c01 = image->c01 - shift;
241
Geom::Point c11 = image->c11 - shift;
242
Geom::Point c10 = image->c10 - shift;
249
cairo_move_to (ct, c00[NR::X], c00[NR::Y]);
244
cairo_move_to (ct, c00[Geom::X], c00[Geom::Y]);
252
cairo_line_to (ct, c10[NR::X], c10[NR::Y]);
253
cairo_line_to (ct, c11[NR::X], c11[NR::Y]);
254
cairo_line_to (ct, c01[NR::X], c01[NR::Y]);
255
cairo_line_to (ct, c00[NR::X], c00[NR::Y]);
247
cairo_line_to (ct, c10[Geom::X], c10[Geom::Y]);
248
cairo_line_to (ct, c11[Geom::X], c11[Geom::Y]);
249
cairo_line_to (ct, c01[Geom::X], c01[Geom::Y]);
250
cairo_line_to (ct, c00[Geom::X], c00[Geom::Y]);
257
cairo_line_to (ct, c11[NR::X], c11[NR::Y]);
258
cairo_move_to (ct, c10[NR::X], c10[NR::Y]);
259
cairo_line_to (ct, c01[NR::X], c01[NR::Y]);
252
cairo_line_to (ct, c11[Geom::X], c11[Geom::Y]);
253
cairo_move_to (ct, c10[Geom::X], c10[Geom::Y]);
254
cairo_line_to (ct, c01[Geom::X], c01[Geom::Y]);
261
256
cairo_stroke(ct);
269
264
/** Calculates the closest distance from p to the segment a1-a2*/
271
distance_to_segment (NR::Point p, NR::Point a1, NR::Point a2)
266
distance_to_segment (Geom::Point p, Geom::Point a1, Geom::Point a2)
273
268
// calculate sides of the triangle and their squares
274
double d1 = NR::L2(p - a1);
269
double d1 = Geom::L2(p - a1);
275
270
double d1_2 = d1 * d1;
276
double d2 = NR::L2(p - a2);
271
double d2 = Geom::L2(p - a2);
277
272
double d2_2 = d2 * d2;
278
double a = NR::L2(a1 - a2);
273
double a = Geom::L2(a1 - a2);
279
274
double a_2 = a * a;
281
276
// if one of the angles at the base is > 90, return the corresponding side
290
285
static NRArenaItem *
291
nr_arena_image_pick( NRArenaItem *item, NR::Point p, double delta, unsigned int /*sticky*/ )
286
nr_arena_image_pick( NRArenaItem *item, Geom::Point p, double delta, unsigned int /*sticky*/ )
293
288
NRArenaImage *image = NR_ARENA_IMAGE (item);
295
290
if (!image->px) return NULL;
297
bool outline = (item->arena->rendermode == RENDERMODE_OUTLINE);
292
bool outline = (item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE);
316
311
int const width = image->pxw;
317
312
int const height = image->pxh;
318
313
int const rowstride = image->pxrs;
319
NR::Point tp = p * image->grid2px;
320
int const ix = (int)(tp[NR::X]);
321
int const iy = (int)(tp[NR::Y]);
314
Geom::Point tp = p * image->grid2px;
315
int const ix = (int)(tp[Geom::X]);
316
int const iy = (int)(tp[Geom::Y]);
323
318
if ((ix < 0) || (iy < 0) || (ix >= width) || (iy >= height))
372
367
if (style->filter.set && style->getFilter()) {
373
368
if (!image->filter) {
374
369
int primitives = sp_filter_primitive_count(SP_FILTER(style->getFilter()));
375
image->filter = new NR::Filter(primitives);
370
image->filter = new Inkscape::Filters::Filter(primitives);
377
372
sp_filter_build_renderer(SP_FILTER(style->getFilter()), image->filter);