1 /*
2 * Functions for extracting alpha channel from NRPixBlocks.
3 *
4 * Author:
5 * Niko Kiirala <niko@kiirala.com>
6 *
7 * Copyright (C) 2007 Niko Kiirala
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #include "display/nr-filter-getalpha.h"
13 #include "libnr/nr-blit.h"
14 #include "libnr/nr-pixblock.h"
16 namespace Inkscape {
17 namespace Filters {
19 NRPixBlock *filter_get_alpha(NRPixBlock *src)
20 {
21 NRPixBlock *dst = new NRPixBlock;
22 nr_pixblock_setup_fast(dst, NR_PIXBLOCK_MODE_R8G8B8A8P,
23 src->area.x0, src->area.y0,
24 src->area.x1, src->area.y1, false);
25 if (!dst || (dst->size != NR_PIXBLOCK_SIZE_TINY && dst->data.px == NULL)) {
26 g_warning("Memory allocation failed in filter_get_alpha");
27 delete dst;
28 return NULL;
29 }
30 nr_blit_pixblock_pixblock(dst, src);
32 unsigned char *data = NR_PIXBLOCK_PX(dst);
33 int end = dst->rs * (dst->area.y1 - dst->area.y0);
34 for (int i = 0 ; i < end ; i += 4) {
35 data[i + 0] = 0;
36 data[i + 1] = 0;
37 data[i + 2] = 0;
38 }
39 dst->empty = false;
41 return dst;
42 }
44 } /* namespace Filters */
45 } /* namespace Inkscape */
47 /*
48 Local Variables:
49 mode:c++
50 c-file-style:"stroustrup"
51 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
52 indent-tabs-mode:nil
53 fill-column:99
54 End:
55 */
56 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :