X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fdevices%2Frender.c;h=88b9ce91275ce9500cc482393806f52a6e7e2939;hb=b93de056e0b79f57c8f8fe22985b166c7d2c3dc3;hp=30a0b593fe26d93901c1b3e2e1859e82aec5ce62;hpb=3fb27a120f9fa3bfb4c06d65ca2ae2b3119668a1;p=swftools.git diff --git a/lib/devices/render.c b/lib/devices/render.c index 30a0b59..88b9ce9 100644 --- a/lib/devices/render.c +++ b/lib/devices/render.c @@ -24,11 +24,11 @@ #include #include "../gfxdevice.h" #include "../gfxtools.h" -#include "../png.h" #include "../mem.h" - -typedef unsigned int U32; -typedef unsigned char U8; +#define PNG_INLINE_EXPORTS +#include "../types.h" +#include "../png.c" +#include "render.h" typedef gfxcolor_t RGBA; @@ -273,13 +273,13 @@ static void fill_line_solid(RGBA*line, U32*z, int y, int x1, int x2, RGBA col) col.r = (col.r*col.a)>>8; col.g = (col.g*col.a)>>8; col.b = (col.b*col.a)>>8; - col.a = 255; do { if(z[bitpos]&bit) { line[x].r = ((line[x].r*ainv)>>8)+col.r; line[x].g = ((line[x].g*ainv)>>8)+col.g; line[x].b = ((line[x].b*ainv)>>8)+col.b; - line[x].a = 255; + //line[x].a = 255; + line[x].a = ((line[x].a*ainv)>>8)+col.a; } bit <<= 1; if(!bit) { @@ -446,7 +446,7 @@ void fill_solid(gfxdevice_t*dev, gfxcolor_t* color) int render_setparameter(struct _gfxdevice*dev, const char*key, const char*value) { internal_t*i = (internal_t*)dev->internal; - if(!strcmp(key, "antialize")) { + if(!strcmp(key, "antialize") || !strcmp(key, "antialise")) { i->antialize = atoi(value); i->zoom = i->antialize * i->multiply; return 1; @@ -466,8 +466,8 @@ void newclip(struct _gfxdevice*dev) { internal_t*i = (internal_t*)dev->internal; - clipbuffer_t*c = rfx_calloc(sizeof(clipbuffer_t)); - c->data = rfx_calloc(sizeof(U32) * i->bitwidth * i->height2); + clipbuffer_t*c = (clipbuffer_t*)rfx_calloc(sizeof(clipbuffer_t)); + c->data = (U32*)rfx_calloc(sizeof(U32) * i->bitwidth * i->height2); c->next = i->clipbuf; i->clipbuf = c; if(c->next) @@ -511,14 +511,14 @@ void render_stroke(struct _gfxdevice*dev, gfxline_t*line, gfxcoord_t width, gfxc add_solidline(dev, x1, y1, x3, y3, width * i->multiply); fill_solid(dev, color); } else if(line->type == gfx_splineTo) { - int c,t,parts,qparts; + int t,parts,qparts; double xx,yy; double x1=x*i->zoom,y1=y*i->zoom; double x2=line->sx*i->zoom,y2=line->sy*i->zoom; double x3=line->x*i->zoom,y3=line->y*i->zoom; - c = abs(x3-2*x2+x1) + abs(y3-2*y2+y1); + double c = abs(x3-2*x2+x1) + abs(y3-2*y2+y1); xx=x1; yy=y1; @@ -649,6 +649,8 @@ void render_addfont(struct _gfxdevice*dev, gfxfont_t*font) void render_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix) { internal_t*i = (internal_t*)dev->internal; + if(!font) + return; /* align characters to whole pixels */ matrix->tx = (int)(matrix->tx * i->antialize) / i->antialize; @@ -668,27 +670,74 @@ void render_result_write(gfxresult_t*r, int filedesc) { internal_result_t*i= (internal_result_t*)r->internal; } -int render_result_save(gfxresult_t*r, char*filename) +int render_result_save(gfxresult_t*r, const char*filename) { - /*internal_result_t*i= (internal_result_t*)r->internal; + internal_result_t*i= (internal_result_t*)r->internal; + if(!i) { + return 0; // no pages drawn + } if(i->next) { int nr=0; + char filenamebuf[256]; + char*origname = strdup(filename); + int l = strlen(origname); + if(l>3 && strchr("gG",origname[l-1]) && strchr("nN",filename[l-2]) && + strchr("pP",origname[l-3]) && filename[l-4]=='.') { + origname[l-4] = 0; + } while(i->next) { + sprintf(filenamebuf, "%s.%d.png", origname, nr); writePNG(filename, (unsigned char*)i->img.data, i->img.width, i->img.height); nr++; } + free(origname); } else { writePNG(filename, (unsigned char*)i->img.data, i->img.width, i->img.height); - }*/ + } return 1; } -void*render_result_get(gfxresult_t*r, char*name) +char*gfximage_asXPM(gfximage_t*img, int depth) +{ + int d= 256/depth; + char*str = (char*)malloc(img->width*img->height*4 + 500 + 16*depth*depth*depth); + char*p = str; + p+= sprintf(p, "static char *noname[] = {\n\"%d %d 262144 3\",\n"); + int r,g,b; + for(r=0;rheight;y++) { + p+=sprintf(p, "\""); + gfxcolor_t*col = &img->data[y*img->height]; + int x; + for(x=0;xwidth;x++) { + p+=sprintf(p, "%c%c%c", 32+(col->r/d), 32+(col->g/d), 32+(col->b/d)); + } + p+=sprintf(p, "\",\n"); + } + *p = 0; + return p; +} +void*render_result_get(gfxresult_t*r, const char*name) { internal_result_t*i= (internal_result_t*)r->internal; - if(!strncmp(name,"page",4)) { + if(!strncmp(name,"xpm",3)) { + int pagenr = atoi(&name[3]); + if(pagenr<0) + pagenr=0; + while(pagenr>0) { + i = i->next; + if(!i) + return 0; + } + return gfximage_asXPM(&i->img, 64); + } else if(!strncmp(name,"page",4)) { int pagenr = atoi(&name[4]); if(pagenr<0) - return 0; + pagenr=0; while(pagenr>0) { i = i->next; if(!i) @@ -766,7 +815,7 @@ void render_startpage(struct _gfxdevice*dev, int width, int height) static void store_image(internal_t*i, internal_result_t*ir) { - ir->img.data = malloc(i->width*i->height*sizeof(RGBA)); + ir->img.data = (gfxcolor_t*)malloc(i->width*i->height*sizeof(gfxcolor_t)); ir->img.width = i->width; ir->img.height = i->height; @@ -859,7 +908,7 @@ void render_endpage(struct _gfxdevice*dev) i->height2 = 0; } -void render_drawlink(struct _gfxdevice*dev, gfxline_t*line, char*action) +void render_drawlink(struct _gfxdevice*dev, gfxline_t*line, const char*action) { /* not supported for this output device */ }