~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "display/nr-light.h"
23
23
#include "libnr/nr-blit.h"
24
24
#include "libnr/nr-pixblock.h"
25
 
#include "libnr/nr-matrix.h"
26
25
#include "libnr/nr-rect-l.h"
27
26
#include "color.h"
28
27
 
29
 
namespace NR {
 
28
namespace Inkscape {
 
29
namespace Filters {
30
30
 
31
31
FilterDiffuseLighting::FilterDiffuseLighting() 
32
32
{
43
43
FilterDiffuseLighting::~FilterDiffuseLighting()
44
44
{}
45
45
 
46
 
#define COMPUTE_INTER(inter, N, L, kd) \
47
 
do {\
48
 
    (inter) = (kd) * scalar_product((N), (L)); \
49
 
    if ((inter) < 0) (inter) = 0; \
50
 
}while(0)
51
 
 
52
 
 
53
46
int FilterDiffuseLighting::render(FilterSlot &slot, FilterUnits const &units) {
54
47
    NRPixBlock *in = slot.get(_input);
55
48
    if (!in) {
69
62
    int dx = 1; //TODO setup
70
63
    int dy = 1; //TODO setup
71
64
    //surface scale
72
 
    Matrix trans = units.get_matrix_primitiveunits2pb();
 
65
    Geom::Matrix trans = units.get_matrix_primitiveunits2pb();
73
66
    gdouble ss = surfaceScale * trans[0];
74
67
    gdouble kd = diffuseConstant; //diffuse lighting constant
75
68
 
76
 
    Fvector L, N, LC;
 
69
    NR::Fvector L, N, LC;
77
70
    gdouble inter;
78
71
 
79
72
    nr_pixblock_setup_fast(out, in->mode,
91
84
            dl->light_components(LC);
92
85
            //finish the work
93
86
            for (i = 0, j = 0; i < w*h; i++) {
94
 
                compute_surface_normal(N, ss, in, i / w, i % w, dx, dy);
95
 
                COMPUTE_INTER(inter, N, L, kd);
 
87
                NR::compute_surface_normal(N, ss, in, i / w, i % w, dx, dy);
 
88
                inter = kd * NR::scalar_product(N, L);
96
89
 
97
 
                data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_RED]);
 
90
                data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_RED]); // CLAMP includes rounding!
98
91
                data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_GREEN]);
99
92
                data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_BLUE]);
100
93
                data_o[j++] = 255;
113
106
        // pixblock coordinates
114
107
            //finish the work
115
108
            for (i = 0, j = 0; i < w*h; i++) {
116
 
                compute_surface_normal(N, ss, in, i / w, i % w, dx, dy);
 
109
                NR::compute_surface_normal(N, ss, in, i / w, i % w, dx, dy);
117
110
                pl->light_vector(L,
118
111
                        i % w + x0,
119
112
                        i / w + y0,
120
113
                        ss * (double) data_i[4*i+3]/ 255);
121
 
                COMPUTE_INTER(inter, N, L, kd);
 
114
                inter = kd * NR::scalar_product(N, L);
122
115
 
123
116
                data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_RED]);
124
117
                data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_GREEN]);
138
131
        // pixblock coordinates
139
132
            //finish the work
140
133
            for (i = 0, j = 0; i < w*h; i++) {
141
 
                compute_surface_normal(N, ss, in, i / w, i % w, dx, dy);
 
134
                NR::compute_surface_normal(N, ss, in, i / w, i % w, dx, dy);
142
135
                sl->light_vector(L,
143
136
                    i % w + x0,
144
137
                    i / w + y0,
145
138
                    ss * (double) data_i[4*i+3]/ 255);
146
139
                sl->light_components(LC, L);
147
 
                COMPUTE_INTER(inter, N, L, kd);
 
140
                inter = kd * NR::scalar_product(N, L);
148
141
                
149
142
                data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_RED]);
150
143
                data_o[j++] = CLAMP_D_TO_U8(inter * LC[LIGHT_GREEN]);
175
168
    return 0;
176
169
}
177
170
 
 
171
void FilterDiffuseLighting::area_enlarge(NRRectL &area, Geom::Matrix const &trans)
 
172
{
 
173
    // TODO: support kernelUnitLength
 
174
    double scalex = std::fabs(trans[0]) + std::fabs(trans[1]);
 
175
    double scaley = std::fabs(trans[2]) + std::fabs(trans[3]);
 
176
 
 
177
    //FIXME: no +2 should be there!... (noticable only for big scales at big zoom factor)
 
178
    area.x0 -= (int)(scalex) + 2;
 
179
    area.x1 += (int)(scalex) + 2;
 
180
    area.y0 -= (int)(scaley) + 2;
 
181
    area.y1 += (int)(scaley) + 2;
 
182
}
 
183
 
178
184
FilterTraits FilterDiffuseLighting::get_input_traits() {
179
185
    return TRAIT_PARALLER;
180
186
}
181
187
 
182
 
} /* namespace NR */
 
188
} /* namespace Filters */
 
189
} /* namespace Inkscape */
183
190
 
184
191
/*
185
192
  Local Variables: