nr-filter-displacement-map.cpp revision 833c08758cda30e603c640ef35ba2da894caef77
/*
* feDisplacementMap filter primitive renderer
*
* Authors:
* Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
*
* Copyright (C) 2007 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "display/nr-filter-displacement-map.h"
#include "display/nr-filter-types.h"
#include "display/nr-filter-units.h"
#include "libnr/nr-pixops.h"
namespace Inkscape {
namespace Filters {
{}
return new FilterDisplacementMap();
}
{}
struct pixel_t {
unsigned char channels[4];
inline unsigned char operator[](int c) const { return channels[c]; }
inline unsigned char& operator[](int c) { return channels[c]; }
pixel_t p;
for(unsigned int i=0; i<4; i++) {
p[i] = 0;
}
return p;
}
};
if ( x < pb->area.x0 || x >= pb->area.x1 || y < pb->area.y0 || y >= pb->area.y1 ) return pixel_t::blank(); // This assumes anything outside the defined range is (0,0,0,0)
}
template<bool PREMULTIPLIED>
unsigned int const sfl = 8u;
unsigned int xf = static_cast<unsigned int>(floor(sf*(x-xi)+.5)), yf = static_cast<unsigned int>(floor(sf*(y-yi)+.5));
pixel_t r;
if (PREMULTIPLIED) {
unsigned int p1[4];
for(size_t i=0; i<4; i++) {
}
for(size_t i=0; i<4; i++) {
}
} else {
// It's a good idea to interpolate premultiplied colors
// Consider two pixels, one being rgb(255,0,0,0), which is fully transparent,
// and the other being rgb(0,255,0,255), or green (fully opaque).
// If these two colors are interpolated the expected result would be greenish pixels containing no red.
unsigned int p0[4];
unsigned int p1[4];
for(size_t i=0; i<3; i++) {
unsigned int c00 = p00[i]*p00[3], c01 = p01[i]*p01[3], c10 = p10[i]*p10[3], c11 = p11[i]*p11[3]; // range [0,255*a]
}
for(size_t i=0; i<3; i++) {
}
}
return r;
}
template<bool MAP_PREMULTIPLIED, bool DATA_PREMULTIPLIED>
static void performDisplacement(NRPixBlock const* texture, NRPixBlock const* map, int Xchannel, int Ychannel, NRPixBlock* out, double scalex, double scaley) {
out_data[(xout-out->area.x0) + (out->area.x1-out->area.x0)*(yout-out->area.y0)] = interpolatePixels<DATA_PREMULTIPLIED>(texture, xtex, ytex);
}
}
}
// Bail out if either one of source images is missing
return 1;
}
//TODO: check whether do we really need this check:
g_warning("Source images without an alpha channel are not supported by feDisplacementMap at the moment.");
return 1;
}
nr_pixblock_setup_fast(out, texture->mode, out->area.x0, out->area.y0, out->area.x1, out->area.y1, true);
// convert to a suitable format
bool free_map_on_exit = false;
map = new NRPixBlock;
false);
free_map_on_exit = true;
}
if (map_premultiplied && data_premultiplied) {
} else if (map_premultiplied && !data_premultiplied) {
} else if (data_premultiplied) {
} else {
}
if (free_map_on_exit) {
delete map;
}
return 0;
}
}
void FilterDisplacementMap::set_scale(double s) {
scale = s;
}
}
void FilterDisplacementMap::set_channel_selector(int s, FilterDisplacementMapChannelSelector channel) {
return;
}
}
{
//I assume scale is in user coordinates (?!?)
//FIXME: trans should be multiplied by some primitiveunits2user, shouldn't it?
//FIXME: no +2 should be there!... (noticable only for big scales at big zoom factor)
}
return TRAIT_PARALLER;
}
} /* namespace Filters */
} /* namespace Inkscape */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :