nr-filter-image.cpp revision 5ef6cb9428f2e6f5457e890a1c3b37f53730c07a
/*
* feImage filter primitive renderer
*
* Authors:
* Felipe CorrĂȘa da Silva Sanches <juca@members.fsf.org>
* Tavmjong Bah <tavmjong@free.fr>
*
* Copyright (C) 2007 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "document.h"
#include "sp-item.h"
#include "display/nr-arena.h"
#include "display/nr-arena-item.h"
#include "display/nr-filter.h"
#include "display/nr-filter-image.h"
#include "display/nr-filter-units.h"
#include "libnr/nr-compose-transform.h"
#include "libnr/nr-rect-l.h"
#include "preferences.h"
namespace Inkscape {
namespace Filters {
FilterImage::FilterImage() :
SVGElem(0),
document(0),
feImageHref(0),
image_pixbuf(0)
{ }
return new FilterImage();
}
{
}
if (!feImageHref) return 0;
bool free_pb_on_exit = false;
if(from_element){
if (!SVGElem) return 0;
// prep the document
if (!ai) {
g_warning("feImage renderer: error creating NRArenaItem for SVG Element");
return 0;
}
pb = new NRPixBlock;
free_pb_on_exit = true;
has_alpha = true;
if(image_pixbuf != NULL)
{
/* Update to renderable state */
double sf = 1.0;
}
else
{
g_warning("FilterImage::render: not enough memory to create pixel buffer. Need %ld.", 4L * width * height);
}
}
if (!image_pixbuf){
try {
/* TODO: If feImageHref is absolute, then use that (preferably handling the
* case that it's not a file URI). Otherwise, go up the tree looking
* for an xml:base attribute, and use that as the base URI for resolving
* the relative feImageHref URI. Otherwise, if document && document->base,
* then use that as the base URI. Otherwise, use feImageHref directly
* (i.e. interpreting it as relative to our current working directory).
* (See http://www.w3.org/TR/xmlbase/#resolution .) */
// Try to load from relative postion combined with document base
if( document ) {
}
}
// Should display Broken Image png.
}
}
{
return 0;
}
catch (const Gdk::PixbufError & e)
{
return 0;
}
if ( !image ) return 0;
// Native size of image
}
int w,x,y;
if (!in) {
return 1;
}
// This section needs to be fully tested!!
// Region being drawn on screen
// Get the object bounding box. Image is placed with respect to box.
// Array values: 0: width; 3: height; 4: -x; 5: -y.
// feImage is suppose to use the same parameters as a normal SVG image.
// If a width or height is set to zero, the image is not suppose to be displayed.
// This does not seem to be what Firefox or Opera does, nor does the W3C displacement
// the width and height of the object bounding box.
Geom::Matrix d2s = Geom::Translate(x0, y0) * unit_trans * Geom::Translate(object_bbox[4]-feImageX, object_bbox[5]-feImageY) * Geom::Scale(scaleX, scaleY);
if (has_alpha) {
nr_R8G8B8A8_P_R8G8B8A8_P_R8G8B8A8_N_TRANSFORM(out_data, x1-x0, y1-y0, 4*w, image_pixbuf, width, height, rowstride, d2s, 255, nr_arena_image_x_sample, nr_arena_image_y_sample);
} else {
//TODO: use interpolation
// Temporarily add 0.5 so we sample center of "cell"
// coordx == 0 and coordy == 0 must be included, but we protect
// against negative numbers which round up to 0 with (int).
out_data[4*((x - x0)+w*(y - y0)) ] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy ]; //Red
out_data[4*((x - x0)+w*(y - y0)) + 1] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy + 1]; //Green
out_data[4*((x - x0)+w*(y - y0)) + 2] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy + 2]; //Blue
}
}
}
}
if (free_pb_on_exit) {
delete pb;
}
return 0;
}
}
}
}
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 :