added alpha and font filter drafts
authorMatthias Kramm <kramm@quiss.org>
Fri, 26 Feb 2010 04:09:28 +0000 (20:09 -0800)
committerMatthias Kramm <kramm@quiss.org>
Fri, 26 Feb 2010 04:10:13 +0000 (20:10 -0800)
lib/Makefile.in
lib/filters/alpha.c [new file with mode: 0644]
lib/filters/remove_font_transform.c [new file with mode: 0644]
lib/gfxfilter.c
lib/gfxfilter.h
lib/gfxtools.c
lib/gfxtools.h
lib/pdf/GFXOutputDev.cc

index e57e0ee..ecc8c64 100644 (file)
@@ -19,7 +19,9 @@ gfxpoly_objects = gfxpoly/active.$(O) gfxpoly/convert.$(O) gfxpoly/poly.$(O) gfx
 rfxswf_modules =  modules/swfbits.c modules/swfaction.c modules/swfdump.c modules/swfcgi.c modules/swfbutton.c modules/swftext.c modules/swffont.c modules/swftools.c modules/swfsound.c modules/swfshape.c modules/swfobject.c modules/swfdraw.c modules/swffilter.c modules/swfrender.c h.263/swfvideo.c modules/swfalignzones.c
 
 base_objects=q.$(O) utf8.$(O) png.$(O) jpeg.$(O) wav.$(O) mp3.$(O) os.$(O) bitio.$(O) log.$(O) mem.$(O) MD5.$(O) xml.$(O) ttf.$(O)
-gfx_objects=gfximage.$(O) gfxtools.$(O) gfxfont.$(O) gfxfilter.$(O) devices/dummy.$(O) devices/file.$(O) devices/render.$(O) devices/text.$(O) devices/record.$(O) devices/ops.$(O) devices/polyops.$(O) devices/bbox.$(O) devices/rescale.$(O) @DEVICE_OPENGL@ @DEVICE_PDF@
+devices=devices/dummy.$(O) devices/file.$(O) devices/render.$(O) devices/text.$(O) devices/record.$(O) devices/ops.$(O) devices/polyops.$(O) devices/bbox.$(O) devices/rescale.$(O) @DEVICE_OPENGL@ @DEVICE_PDF@
+filters=filters/alpha.$(O) filters/remove_font_transform.$(O)
+gfx_objects=gfximage.$(O) gfxtools.$(O) gfxfont.$(O) gfxfilter.$(O) $(devices) $(filters)
 
 rfxswf_objects=modules/swfaction.$(O) modules/swfbits.$(O) modules/swfbutton.$(O) modules/swfcgi.$(O) modules/swfdraw.$(O) modules/swfdump.$(O) modules/swffilter.$(O) modules/swffont.$(O) modules/swfobject.$(O) modules/swfrender.$(O) modules/swfshape.$(O) modules/swfsound.$(O) modules/swftext.$(O) modules/swftools.$(O) modules/swfalignzones.$(O)
 ocr_objects=gocr/box.$(O) gocr/database.$(O) gocr/detect.$(O) gocr/job.$(O) gocr/lines.$(O) gocr/list.$(O) gocr/ocr0.$(O) gocr/ocr0n.$(O) gocr/ocr1.$(O) gocr/otsu.$(O) gocr/output.$(O) gocr/pgm2asc.$(O) gocr/pixel.$(O) gocr/progress.$(O) gocr/remove.$(O) gocr/unicode.$(O)
@@ -145,6 +147,11 @@ devices/lrf.$(O):  devices/lrf.c devices/lrf.h
 devices/ocr.$(O): devices/ocr.c devices/ocr.h gocr/gocr.h
        $(C) devices/ocr.c -o devices/ocr.$(O)
 
+filters/alpha.$(O): filters/alpha.c gfxfilter.h
+       $(C) filters/alpha.c -o filters/alpha.$(O)
+filters/remove_font_transform.$(O): filters/remove_font_transform.c gfxfilter.h
+       $(C) filters/remove_font_transform.c -o filters/remove_font_transform.$(O)
+
 readers/swf2.$(O): readers/swf.c readers/swf.h
        $(C) readers/swf.c -o readers/swf2.$(O)
 readers/image.$(O): readers/image.c readers/image.h
diff --git a/lib/filters/alpha.c b/lib/filters/alpha.c
new file mode 100644 (file)
index 0000000..1dcd328
--- /dev/null
@@ -0,0 +1,116 @@
+/* alpha.c
+
+   Part of the swftools package.
+
+   Copyright (c) 2010 Matthias Kramm <kramm@quiss.org> 
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#include <stdlib.h>
+#include <memory.h>
+#include "../gfxfilter.h"
+#include "../gfxtools.h"
+#include "../types.h"
+#include "../mem.h"
+
+typedef struct _internal {
+    U8 alpha;
+} internal_t;
+
+static inline gfxcolor_t transform_color(internal_t*i, gfxcolor_t*col)
+{
+    gfxcolor_t col2;
+    col2.r = col->r;
+    col2.g = col->g;
+    col2.b = col->b;
+    col2.a = (col->a * i->alpha)/255;
+    return col2;
+}
+
+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)
+{
+    internal_t*i = (internal_t*)f->internal;
+    gfxcolor_t color2 = transform_color(i, color);
+    out->stroke(out, line, width, &color2, cap_style, joint_style, miterLimit);
+}
+static void maketransparent_fill(gfxfilter_t*f, gfxline_t*line, gfxcolor_t*color, gfxdevice_t*out)
+{
+    internal_t*i = (internal_t*)f->internal;
+    gfxcolor_t color2 = transform_color(i, color);
+    out->fill(out, line, &color2);
+}
+static void maketransparent_fillbitmap(gfxfilter_t*f, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform, gfxdevice_t*out)
+{
+    internal_t*i = (internal_t*)f->internal;
+    gfximage_t img2;
+    img2.width = img->width;
+    img2.height = img->height;
+    img2.data = (gfxcolor_t*)rfx_alloc(img->width*img->height*4);
+    int x,y; 
+    for(y=0;y<img->height;y++)  {
+       gfxcolor_t*in = &img->data[y*img->width];
+       gfxcolor_t*out = &img2.data[y*img->width];
+       for(x=0;x<img->width;x++) {
+           out[x] = transform_color(i, &in[x]);
+       }
+    }
+    out->fillbitmap(out, line, &img2, matrix, cxform);
+    rfx_free(img2.data);
+}
+static void maketransparent_drawchar(gfxfilter_t*f, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix, gfxdevice_t*out)
+{
+    internal_t*i = (internal_t*)f->internal;
+    gfxcolor_t color2 = transform_color(i, color);
+    out->drawchar(out, font, glyphnr, color, matrix);
+}
+static void maketransparent_fillgradient(gfxfilter_t*f, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix, gfxdevice_t*out)
+{
+    internal_t*i = (internal_t*)f->internal;
+    
+    gfxgradient_t*g = 0, *prev = 0;
+
+    while(gradient) {
+       gfxgradient_t*n = rfx_alloc(sizeof(gfxgradient_t));
+       n->pos = gradient->pos;
+       n->color = transform_color(i, &gradient->color);
+       n->next = 0;
+       if(prev) {
+           prev->next = n;
+           prev = n;
+       } else {
+           g = prev = n;
+       }
+       gradient = gradient->next;
+    }
+
+    out->fillgradient(out, line, g, type, matrix);
+    gfxgradient_destroy(g);
+}
+
+void gfxfilter_maketransparent(gfxfilter_t*f, U8 alpha)
+{
+    internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
+    i->alpha = alpha;
+
+    memset(f, 0, sizeof(gfxfilter_t));
+    f->name = "maketransparent";
+    f->internal = i;
+    f->stroke = maketransparent_stroke;
+    f->fill = maketransparent_fill;
+    f->fillbitmap = maketransparent_fillbitmap;
+    f->fillgradient = maketransparent_fillgradient;
+    f->drawchar = maketransparent_drawchar;
+}
+
diff --git a/lib/filters/remove_font_transform.c b/lib/filters/remove_font_transform.c
new file mode 100644 (file)
index 0000000..73bfe4d
--- /dev/null
@@ -0,0 +1,55 @@
+/* remove_font_transform.c
+
+   Part of the swftools package.
+
+   Copyright (c) 2010 Matthias Kramm <kramm@quiss.org> 
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#include <stdlib.h>
+#include <memory.h>
+#include "../gfxfilter.h"
+#include "../gfxtools.h"
+#include "../types.h"
+#include "../mem.h"
+
+typedef struct _internal {
+} internal_t;
+
+static void pass1_drawchar(gfxfilter_t*f, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix, gfxdevice_t*out)
+{
+    internal_t*i = (internal_t*)f->internal;
+    out->drawchar(out, font, glyphnr, color, matrix);
+}
+
+static void pass2_drawchar(gfxfilter_t*f, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix, gfxdevice_t*out)
+{
+    internal_t*i = (internal_t*)f->internal;
+    out->drawchar(out, font, glyphnr, color, matrix);
+}
+
+void gfxfilter_normalizefonts(gfxtwopassfilter_t*f)
+{
+    internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
+    memset(f, 0, sizeof(gfxtwopassfilter_t));
+    f->pass1.name = "remove font transform pass 1";
+    f->pass1.drawchar = pass1_drawchar;
+    f->pass1.internal = i;
+
+    f->pass2.name = "remove font transform pass 2";
+    f->pass2.drawchar = pass2_drawchar;
+    f->pass2.internal = i;
+}
+
index 57d6180..c8cc253 100644 (file)
@@ -1,3 +1,23 @@
+/* gfxfilter.c
+
+   Part of the swftools package.
+
+   Copyright (c) 2010 Matthias Kramm <kramm@quiss.org> 
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
index a5d0a6c..07c85c8 100644 (file)
@@ -1,3 +1,23 @@
+/* gfxfilter.h
+
+   Part of the swftools package.
+
+   Copyright (c) 2010 Matthias Kramm <kramm@quiss.org> 
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
 #ifndef __gfxfilter_h__
 #define __gfxfilter_h__
 
index 12717ea..2527675 100644 (file)
@@ -1137,6 +1137,15 @@ gfxline_t* gfxline_reverse(gfxline_t*line)
     return b;
 }
 
+void gfxgradient_destroy(gfxgradient_t*gradient)
+{
+    while(gradient) {
+       gfxgradient_t*next = gradient->next;
+       free(gradient);
+       gradient = next;
+    }
+}
+
 gfxparams_t* gfxparams_new()
 {
     return (gfxparams_t*)rfx_calloc(sizeof(gfxparams_t));
index 5c27e2b..4b83718 100644 (file)
@@ -99,6 +99,8 @@ gfxline_t*gfxline_makerectangle(double x1, double y1, double x2, double y2);
 gfxline_t*gfxline_makecircle(double x,double y,double rx, double ry);
 void gfxline_show(gfxline_t*line, FILE*fi);
 
+void gfxgradient_destroy(gfxgradient_t*gradient);
+
 typedef struct _gfxparam {
     const char*key;
     const char*value;
index bd6af40..dee94f9 100644 (file)
@@ -996,7 +996,8 @@ GBool GFXOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
            colToByte(color2.c[0]), colToByte(color2.c[1]), colToByte(color2.c[2]));
     infofeature("radial shaded fills");
 
-    gfxgradient_t*g = (gfxgradient_t*)malloc(sizeof(gfxgradient_t)*3);
+    gfxgradient_t gr[3];
+    gfxgradient_t*g = &gr[0];
     g[0].next = &g[1];
     g[1].next = &g[2];
     g[2].next = 0;