cairo-templates.h revision 2ebc6970a180add98db832b7d93d38d8e626d721
/**
* @file
* @brief Cairo software blending templates
*//*
* Authors:
* Krzysztof KosiĆski <tweenk.pl@gmail.com>
*
* Copyright (C) 2010 Authors
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_OPENMP
#include <omp.h>
#include "preferences.h"
#endif
#include <cairo.h>
#include <glib.h>
/**
* @brief Blend two surfaces using the supplied functor.
* This template blends two Cairo image surfaces using a blending functor that takes
* two 32-bit ARGB pixel values and returns a modified 32-bit pixel value.
* Differences in input surface formats are handled transparently. In future, this template
* will also handle software fallback for GL surfaces. */
void ink_cairo_surface_blend(cairo_surface_t *in1, cairo_surface_t *in2, cairo_surface_t *out, Blend blend)
{
// WARNING: code below assumes that:
// 1. Cairo ARGB32 surface strides are always divisible by 4
// 2. We can only receive CAIRO_FORMAT_ARGB32 or CAIRO_FORMAT_A8 surfaces
// 3. Both surfaces are of the same size
// 4. Output surface is ARGB32 if at least one input is ARGB32
int w = cairo_image_surface_get_width(in2);
int h = cairo_image_surface_get_height(in2);
#if HAVE_OPENMP
int num_threads = prefs->getIntLimited("/options/threading/numthreads", omp_get_num_procs(), 1, 256);
#endif
if (bpp1 == 4) {
if (bpp2 == 4) {
#if HAVE_OPENMP
#endif
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
++in1_p;
++in2_p;
++out_p;
}
}
} else {
// bpp2 == 1
#if HAVE_OPENMP
#endif
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
in2_px <<= 24;
++in1_p;
++in2_p;
++out_p;
}
}
}
} else {
if (bpp2 == 4) {
// bpp1 == 1
#if HAVE_OPENMP
#endif
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
in1_px <<= 24;
++in1_p;
++in2_p;
++out_p;
}
}
} else {
// bpp1 == 1 && bpp2 == 1
// don't do anything - this should have been handled via Cairo blending
}
}
}
// helper macros for pixel extraction
#define EXTRACT_ARGB32(px,a,r,g,b) \
guint32 a, r, g, b; \
b = (px & 0x000000ff);
#define ASSEMBLE_ARGB32(px,a,r,g,b) \
#endif
/*
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 :