nr-filter-displacement-map.cpp revision 800e9c0276fae9083ec7815b748ee3fa20c2f3cc
/*
* 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));
/* It's a good idea to interpolate premultiplied colors:
*
* Consider two pixels, one being rgba(255,0,0,0), which is fully transparent,
* and the other being rgba(0,0,255,255), or blue (fully opaque).
* If these two colors are interpolated the expected result would be bluish pixels
* containing no red.
*
* However, if our final alpha value is zero, then the RGB values aren't really determinate.
* We might as well avoid premultiplication in this case, which still gives us a fully
* transparent result, but with interpolated RGB parts. */
/* First calculate interpolated alpha value. */
unsigned ra = 0;
if (!PREMULTIPLIED) {
}
pixel_t r;
if (ra == 0) {
/* Either premultiplied or the interpolated alpha value is zero,
* so do simple interpolation. */
for (unsigned i = 0; i != 4; ++i) {
// y0,y1 have range [0,a*sf]
}
} else {
/* Do premultiplication ourselves. */
for (unsigned i = 0; i != 3; ++i) {
// Premultiplied versions. Range [0,255*a].
// Interpolation.
}
}
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) {
double xtex = xout + (Xneedsdemul ? // Although the value of the pixel corresponds to the MIDDLE of the pixel, no +0.5 is needed because we're interpolating pixels anyway (so to get the actual pixel locations 0.5 would have to be subtracted again).
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 :