Code

revert jasper's way overzealous fix in png-write.cpp rev 13700; new fix in item_rende...
[inkscape.git] / src / display / nr-filter-turbulence.cpp
1 /*
2  * feTurbulence 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  */
12 #include "display/nr-filter-turbulence.h"
14 namespace NR {
16 FilterTurbulence::FilterTurbulence()
17 : XbaseFrequency(0),
18   YbaseFrequency(0),
19   numOctaves(1),
20   seed(0)
21 {
22     g_warning("FilterTurbulence::render not implemented.");
23 }
25 FilterPrimitive * FilterTurbulence::create() {
26     return new FilterTurbulence();
27 }
29 FilterTurbulence::~FilterTurbulence()
30 {}
32 void FilterTurbulence::set_baseFrequency(int axis, double freq){
33     if (axis==0) XbaseFrequency=freq;
34     if (axis==1) YbaseFrequency=freq;
35 }
37 void FilterTurbulence::set_numOctaves(int num){
38     numOctaves=num;
39 }
41 void FilterTurbulence::set_seed(double s){
42     seed=s;
43 }
45 void FilterTurbulence::set_stitchTiles(bool st){
46     stitchTiles=st;
47 }
49 void FilterTurbulence::set_type(int t){
50     type=t;
51 }
54 int FilterTurbulence::render(FilterSlot &slot, Matrix const &trans) {
55 /* TODO: Implement this renderer method.
56         Specification: http://www.w3.org/TR/SVG11/filters.html#feTurbulence
58 */
60 /*debug: these are the available parameters
61     printf("XbaseFrequency = %f; ", XbaseFrequency);
62     printf("YbaseFrequency = %f; ", YbaseFrequency);
63     printf("numOctaves = %d;\n", numOctaves);
64     printf("seed = %f; ", seed);
65     printf("stitchTiles = %s; ", stitchTiles ? "stitch" : "noStitch");
66     printf("type = %s;\n\n", type==0 ? "FractalNoise" : "turbulence");
67 */
69 //sample code: the following fills the whole area in semi-transparent red.    
70     NRPixBlock *in = slot.get(_input);
71     NRPixBlock *out = new NRPixBlock;
72     int x,y;
73     int x0 = in->area.x0, y0 = in->area.y0;
74     int x1 = in->area.x1, y1 = in->area.y1;
75     int w = x1 - x0;
76     nr_pixblock_setup_fast(out, in->mode, x0, y0, x1, y1, true);
78     unsigned char *out_data = NR_PIXBLOCK_PX(out);
79     for (x=x0; x < x1; x++){
80         for (y=y0; y < y1; y++){
81             out_data[4*((x - x0)+w*(y - y0)) + 0] = 255;
82             out_data[4*((x - x0)+w*(y - y0)) + 1] = 0;
83             out_data[4*((x - x0)+w*(y - y0)) + 2] = 0;
84             out_data[4*((x - x0)+w*(y - y0)) + 3] = 128;
85         }
86     }
88     out->empty = FALSE;
89     slot.set(_output, out);
90     return 0;
91 }
93 } /* namespace NR */
95 /*
96   Local Variables:
97   mode:c++
98   c-file-style:"stroustrup"
99   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
100   indent-tabs-mode:nil
101   fill-column:99
102   End:
103 */
104 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :