3 Part of the swftools package.
5 Copyright (c) 2010 Matthias Kramm <kramm@quiss.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
23 #include "../gfxfilter.h"
24 #include "../gfxtools.h"
28 typedef struct _internal {
32 static inline gfxcolor_t transform_color(internal_t*i, gfxcolor_t*col)
38 col2.a = (col->a * i->alpha)/255;
42 static void maketransparent_stroke(gfxfilter_t*f, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit, gfxdevice_t*out)
44 internal_t*i = (internal_t*)f->internal;
45 gfxcolor_t color2 = transform_color(i, color);
46 out->stroke(out, line, width, &color2, cap_style, joint_style, miterLimit);
48 static void maketransparent_fill(gfxfilter_t*f, gfxline_t*line, gfxcolor_t*color, gfxdevice_t*out)
50 internal_t*i = (internal_t*)f->internal;
51 gfxcolor_t color2 = transform_color(i, color);
52 out->fill(out, line, &color2);
54 static void maketransparent_fillbitmap(gfxfilter_t*f, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform, gfxdevice_t*out)
56 internal_t*i = (internal_t*)f->internal;
58 img2.width = img->width;
59 img2.height = img->height;
60 img2.data = (gfxcolor_t*)rfx_alloc(img->width*img->height*4);
62 for(y=0;y<img->height;y++) {
63 gfxcolor_t*in = &img->data[y*img->width];
64 gfxcolor_t*out = &img2.data[y*img->width];
65 for(x=0;x<img->width;x++) {
66 out[x] = transform_color(i, &in[x]);
69 out->fillbitmap(out, line, &img2, matrix, cxform);
72 static void maketransparent_drawchar(gfxfilter_t*f, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix, gfxdevice_t*out)
74 internal_t*i = (internal_t*)f->internal;
75 gfxcolor_t color2 = transform_color(i, color);
76 out->drawchar(out, font, glyphnr, color, matrix);
78 static void maketransparent_fillgradient(gfxfilter_t*f, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix, gfxdevice_t*out)
80 internal_t*i = (internal_t*)f->internal;
82 gfxgradient_t*g = 0, *prev = 0;
85 gfxgradient_t*n = rfx_alloc(sizeof(gfxgradient_t));
86 n->pos = gradient->pos;
87 n->color = transform_color(i, &gradient->color);
95 gradient = gradient->next;
98 out->fillgradient(out, line, g, type, matrix);
99 gfxgradient_destroy(g);
102 void gfxfilter_maketransparent_init(gfxfilter_t*f, U8 alpha)
104 internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
107 memset(f, 0, sizeof(gfxfilter_t));
108 f->name = "maketransparent";
110 f->stroke = maketransparent_stroke;
111 f->fill = maketransparent_fill;
112 f->fillbitmap = maketransparent_fillbitmap;
113 f->fillgradient = maketransparent_fillgradient;
114 f->drawchar = maketransparent_drawchar;