nr-filter-image.cpp revision 723b4d8bde8ce8503d1d01ee0f2e3548ec0dc88c
2N/A/*
2N/A * feImage filter primitive renderer
2N/A *
2N/A * Authors:
2N/A * Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
2N/A *
2N/A * Copyright (C) 2007 authors
2N/A *
2N/A * Released under GNU GPL, read the file 'COPYING' for more information
2N/A */
2N/A#include "display/nr-arena-item.h"
2N/A#include "display/nr-filter.h"
2N/A#include "display/nr-filter-image.h"
2N/A#include "display/nr-filter-units.h"
2N/A
2N/Anamespace NR {
2N/A
2N/AFilterImage::FilterImage()
2N/A{
2N/A feImageHref=NULL;
2N/A image_pixbuf=NULL;
2N/A}
2N/A
2N/AFilterPrimitive * FilterImage::create() {
2N/A return new FilterImage();
2N/A}
2N/A
2N/AFilterImage::~FilterImage()
2N/A{
2N/A if (feImageHref) g_free(feImageHref);
2N/A if (image_pixbuf) g_free(image_pixbuf);
2N/A}
2N/A
2N/Aint FilterImage::render(FilterSlot &slot, FilterUnits const &/*units*/) {
2N/A if (!feImageHref) return 0;
2N/A
2N/A if (!image_pixbuf){
2N/A if ( (image = Gdk::Pixbuf::create_from_file(feImageHref)) < 0 ) return 0;
2N/A width = image->get_width();
2N/A height = image->get_height();
2N/A rowstride = image->get_rowstride();
2N/A image_pixbuf = image->get_pixels();
2N/A }
2N/A int w,x,y;
2N/A NRPixBlock *in = slot.get(_input);
2N/A NRPixBlock *out = new NRPixBlock;
2N/A
2N/A int x0 = in->area.x0, y0 = in->area.y0;
2N/A int x1 = in->area.x1, y1 = in->area.y1;
2N/A int bbox_x0 = (int) slot.get_arenaitem()->bbox.x0;
2N/A int bbox_y0 = (int) slot.get_arenaitem()->bbox.y0;
2N/A
2N/A nr_pixblock_setup_fast(out, in->mode, x0, y0, x1, y1, true);
2N/A
2N/A w = x1 - x0;
2N/A double scaleX = width/feImageWidth;
2N/A double scaleY = height/feImageHeight;
2N/A int coordx,coordy;
2N/A unsigned char *out_data = NR_PIXBLOCK_PX(out);
2N/A for (x=x0; x < x1; x++){
2N/A for (y=y0; y < y1; y++){
2N/A //TODO: use interpolation
2N/A coordx = int((x - feImageX - bbox_x0)*scaleX);
2N/A coordy = int((y - feImageY - bbox_y0)*scaleY);
2N/A
2N/A if (coordx > 0 && coordx < width && coordy > 0 && coordy < height){
2N/A out_data[4*((x - x0)+w*(y - y0))] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy]; //Red
2N/A out_data[4*((x - x0)+w*(y - y0)) + 1] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy + 1]; //Green
2N/A out_data[4*((x - x0)+w*(y - y0)) + 2] = (unsigned char) image_pixbuf[3*coordx + rowstride*coordy + 2]; //Blue
2N/A out_data[4*((x - x0)+w*(y - y0)) + 3] = 255; //Alpha
2N/A }
2N/A }
2N/A }
2N/A
2N/A out->empty = FALSE;
2N/A slot.set(_output, out);
2N/A return 0;
2N/A}
2N/A
2N/Avoid FilterImage::set_href(const gchar *href){
2N/A if (feImageHref) g_free (feImageHref);
2N/A feImageHref = (href) ? g_strdup (href) : NULL;
2N/A}
2N/A
2N/Avoid FilterImage::set_region(SVGLength x, SVGLength y, SVGLength width, SVGLength height){
2N/A feImageX=x.computed;
2N/A feImageY=y.computed;
2N/A feImageWidth=width.computed;
2N/A feImageHeight=height.computed;
2N/A}
2N/A
2N/AFilterTraits FilterImage::get_input_traits() {
2N/A return TRAIT_PARALLER;
2N/A}
2N/A
2N/A} /* namespace NR */
2N/A
2N/A/*
2N/A Local Variables:
2N/A mode:c++
2N/A c-file-style:"stroustrup"
2N/A c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2N/A indent-tabs-mode:nil
2N/A fill-column:99
2N/A End:
2N/A*/
2N/A// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
2N/A