~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

Viewing changes to src/display/nr-filter-morphology.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * feMorphology 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
 
 
12
#include "display/nr-filter-morphology.h"
 
13
#include "display/nr-filter-units.h"
 
14
 
 
15
namespace NR {
 
16
 
 
17
FilterMorphology::FilterMorphology()
 
18
{
 
19
}
 
20
 
 
21
FilterPrimitive * FilterMorphology::create() {
 
22
    return new FilterMorphology();
 
23
}
 
24
 
 
25
FilterMorphology::~FilterMorphology()
 
26
{}
 
27
 
 
28
int FilterMorphology::render(FilterSlot &slot, FilterUnits const &/*units*/) {
 
29
    NRPixBlock *in = slot.get(_input);
 
30
    if (!in) {
 
31
        g_warning("Missing source image for feMorphology (in=%d)", _input);
 
32
        return 1;
 
33
    }
 
34
 
 
35
    NRPixBlock *out = new NRPixBlock;
 
36
 
 
37
    int x0=in->area.x0;
 
38
    int y0=in->area.y0;
 
39
    int x1=in->area.x1;
 
40
    int y1=in->area.y1;
 
41
    int w=x1-x0, h=y1-y0;
 
42
    int x,y,i,j;
 
43
    int rmax,gmax,bmax,amax;
 
44
    int rmin,gmin,bmin,amin;
 
45
 
 
46
    nr_pixblock_setup_fast(out, in->mode, x0, y0, x1, y1, true);
 
47
 
 
48
    unsigned char *in_data = NR_PIXBLOCK_PX(in);
 
49
    unsigned char *out_data = NR_PIXBLOCK_PX(out);
 
50
 
 
51
    for(x=xradius; x<w-xradius; x++){
 
52
        for(y=yradius; y<h-yradius; y++){
 
53
            rmin=rmax=in_data[4*(x + w*y)];
 
54
            gmin=gmax=in_data[4*(x + w*y)+1];
 
55
            bmin=bmax=in_data[4*(x + w*y)+2];
 
56
            amin=amax=in_data[4*(x + w*y)+3];
 
57
            for(i=x-xradius;i<x+xradius;i++){
 
58
                for(j=y-yradius;j<y+yradius;j++){
 
59
                    if(in_data[4*(i + w*j)]>rmax) rmax = in_data[4*(i + w*j)];
 
60
                    if(in_data[4*(i + w*j)+1]>gmax) gmax = in_data[4*(i + w*j)+1];
 
61
                    if(in_data[4*(i + w*j)+2]>bmax) bmax = in_data[4*(i + w*j)+2];
 
62
                    if(in_data[4*(i + w*j)+3]>amax) amax = in_data[4*(i + w*j)+3];
 
63
 
 
64
                    if(in_data[4*(i + w*j)]<rmin) rmin = in_data[4*(i + w*j)];
 
65
                    if(in_data[4*(i + w*j)+1]<gmin) gmin = in_data[4*(i + w*j)+1];
 
66
                    if(in_data[4*(i + w*j)+2]<bmin) bmin = in_data[4*(i + w*j)+2];
 
67
                    if(in_data[4*(i + w*j)+3]<amin) amin = in_data[4*(i + w*j)+3];
 
68
                }
 
69
            }
 
70
            if (Operator==MORPHOLOGY_OPERATOR_DILATE){
 
71
                out_data[4*(x + w*y)]=rmax;
 
72
                out_data[4*(x + w*y)+1]=gmax;
 
73
                out_data[4*(x + w*y)+2]=bmax;
 
74
                out_data[4*(x + w*y)+3]=amax;
 
75
            } else {
 
76
                out_data[4*(x + w*y)]=rmin;
 
77
                out_data[4*(x + w*y)+1]=gmin;
 
78
                out_data[4*(x + w*y)+2]=bmin;
 
79
                out_data[4*(x + w*y)+3]=amin;
 
80
            }
 
81
        }
 
82
    }
 
83
 
 
84
    out->empty = FALSE;
 
85
    slot.set(_output, out);
 
86
    return 0;
 
87
}
 
88
 
 
89
void FilterMorphology::area_enlarge(NRRectL &area, Matrix const &/*trans*/)
 
90
{
 
91
    area.x0-=xradius;
 
92
    area.x1+=xradius;
 
93
    area.y0-=yradius;
 
94
    area.y1+=yradius;
 
95
}
 
96
 
 
97
void FilterMorphology::set_operator(FilterMorphologyOperator &o){
 
98
    Operator = o;
 
99
}
 
100
 
 
101
void FilterMorphology::set_xradius(int x){
 
102
    xradius = x;
 
103
}
 
104
 
 
105
void FilterMorphology::set_yradius(int y){
 
106
    yradius = y;
 
107
}
 
108
 
 
109
FilterTraits FilterMorphology::get_input_traits() {
 
110
    return TRAIT_PARALLER;
 
111
}
 
112
 
 
113
} /* namespace NR */
 
114
 
 
115
/*
 
116
  Local Variables:
 
117
  mode:c++
 
118
  c-file-style:"stroustrup"
 
119
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
120
  indent-tabs-mode:nil
 
121
  fill-column:99
 
122
  End:
 
123
*/
 
124
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :