Code

Added 'paraller axis' rendering hint to filter primitives, that need it.
[inkscape.git] / src / display / nr-filter-image.cpp
1 /*
2  * feImage filter primitive renderer
3  *
4  * Authors:
5  *   Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
6  *
7  * Copyright (C) 2007 authors
8  *
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
11 #include "display/nr-arena-item.h"
12 #include "display/nr-filter.h"
13 #include "display/nr-filter-image.h"
15 namespace NR {
17 FilterImage::FilterImage()
18 {
19 // Testing with hardcoded xlink:href :  
20     image = Gdk::Pixbuf::create_from_file("../images/image1.jpg");
21     //TODO: handle errors
22     width = image->get_width()+1;
23     height = image->get_height()+1;
24     image_pixbuf = image->get_pixels();
25 }
27 FilterPrimitive * FilterImage::create() {
28     return new FilterImage();
29 }
31 FilterImage::~FilterImage()
32 {}
34 int FilterImage::render(FilterSlot &slot, Matrix const &trans) {
35     int w,x,y;
36     NRPixBlock *in = slot.get(_input);
37     NRPixBlock *out = new NRPixBlock;
39     int x0 = in->area.x0, y0 = in->area.y0;
40     int x1 = in->area.x1, y1 = in->area.y1;
41     int bbox_x0 = (int) slot.get_arenaitem()->bbox.x0;
42     int bbox_y0 = (int) slot.get_arenaitem()->bbox.y0;
43     
44     nr_pixblock_setup_fast(out, in->mode, x0, y0, x1, y1, true);
46     w = x1 - x0;
47     double scaleX = width/feImageWidth;
48     double scaleY = height/feImageHeight;
49     int coordx,coordy;
50     unsigned char *out_data = NR_PIXBLOCK_PX(out);
51     for (x=x0; x < x1; x++){
52         for (y=y0; y < y1; y++){
53             //TODO: use interpolation
54             coordx = int((x - feImageX - bbox_x0)*scaleX);
55             coordy = int((y - feImageY - bbox_y0)*scaleY);
57             if (coordx > 0 && coordx < width && coordy > 0 && coordy < height){
58                 out_data[4*((x - x0)+w*(y - y0))] = (unsigned char) image_pixbuf[3*(coordx + width*coordy)]; //Red
59                 out_data[4*((x - x0)+w*(y - y0)) + 1] = (unsigned char) image_pixbuf[3*(coordx + width*coordy) + 1]; //Green
60                 out_data[4*((x - x0)+w*(y - y0)) + 2] = (unsigned char) image_pixbuf[3*(coordx + width*coordy) + 2]; //Blue
61                 out_data[4*((x - x0)+w*(y - y0)) + 3] = 255; //Alpha
62             }
63         }
64     }
66     out->empty = FALSE;
67     slot.set(_output, out);
68     return 0;
69 }
70 void FilterImage::set_region(SVGLength x, SVGLength y, SVGLength width, SVGLength height){
71         feImageX=x.computed;
72         feImageY=y.computed;
73         feImageWidth=width.computed;
74         feImageHeight=height.computed;
75 }
77 FilterTraits FilterImage::get_input_traits() {
78     return TRAIT_PARALLER;
79 }
80     
81 } /* namespace NR */
83 /*
84   Local Variables:
85   mode:c++
86   c-file-style:"stroustrup"
87   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
88   indent-tabs-mode:nil
89   fill-column:99
90   End:
91 */
92 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :