nr-filter-blend.cpp revision c73973b946e8f567076c2a67b4e54f3d72b16ce5
/*
* SVG feBlend renderer
*
* "This filter composites two objects together using commonly used
* imaging software blending modes. It performs a pixel-wise combination
* of two input images."
* http://www.w3.org/TR/SVG11/filters.html#feBlend
*
* Authors:
* Niko Kiirala <niko@kiirala.com>
* Jasper van de Gronde <th.v.d.gronde@hccnet.nl>
*
* Copyright (C) 2007-2008 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "display/cairo-templates.h"
#include "display/cairo-utils.h"
#include "display/nr-filter-blend.h"
#include "display/nr-filter-primitive.h"
#include "display/nr-filter-slot.h"
#include "display/nr-filter-types.h"
#include "preferences.h"
namespace Inkscape {
namespace Filters {
/*
* From http://www.w3.org/TR/SVG11/filters.html#feBlend
*
* For all feBlend modes, the result opacity is computed as follows:
* qr = 1 - (1-qa)*(1-qb)
*
* For the compositing formulas below, the following definitions apply:
* cr = Result color (RGB) - premultiplied
* qa = Opacity value at a given pixel for image A
* qb = Opacity value at a given pixel for image B
* ca = Color (RGB) at a given pixel for image A - premultiplied
* cb = Color (RGB) at a given pixel for image B - premultiplied
*/
{}
return new FilterBlend();
}
{}
// cr = (1-qa)*cb + (1-qb)*ca + ca*cb
struct BlendMultiply {
{
return pxout;
}
};
// cr = cb + ca - ca * cb
struct BlendScreen {
{
return pxout;
}
};
// cr = Min ((1 - qa) * cb + ca, (1 - qb) * ca + cb)
struct BlendDarken {
{
return pxout;
}
};
// cr = Max ((1 - qa) * cb + ca, (1 - qb) * ca + cb)
struct BlendLighten {
{
return pxout;
}
};
/*
struct BlendAlpha
static inline void blend_alpha(guint32 in1, guint32 in2, guint32 *out)
{
EXTRACT_ARGB32(in1, a1, a2, a3, a4);
EXTRACT_ARGB32(in2, b1, b2, b3, b4);
guint32 o1 = 255*255 - (255-a1)*(255-b1); o1 = (o1+127) / 255;
guint32 o2 = 255*255 - (255-a2)*(255-b2); o2 = (o2+127) / 255;
guint32 o3 = 255*255 - (255-a3)*(255-b3); o3 = (o3+127) / 255;
guint32 o4 = 255*255 - (255-a4)*(255-b4); o4 = (o4+127) / 255;
ASSEMBLE_ARGB32(pxout, o1, o2, o3, o4);
*out = pxout;
}
*/
{
// input2 is the "background" image
// out should be ARGB32 if any of the inputs is ARGB32
|| _blend_mode == BLEND_NORMAL)
{
} else {
// blend mode != normal and at least 1 surface is not pure alpha
// TODO: convert to Cairo blending operators once we start using the 1.10 series
switch (_blend_mode) {
case BLEND_MULTIPLY:
break;
case BLEND_SCREEN:
break;
case BLEND_DARKEN:
break;
case BLEND_LIGHTEN:
break;
case BLEND_NORMAL:
default:
// this was handled before
break;
}
}
}
{
// blend is a per-pixel primitive and is immutable under transformations
return true;
}
}
}
mode == BLEND_LIGHTEN)
{
_blend_mode = mode;
}
}
} /* 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 :