+ArtSVP* gfxstrokeToSVP(gfxline_t*line, gfxcoord_t width, gfx_capType cap_style, gfx_joinType joint_style, double miterLimit)
+{
+ ArtVpath *vec = NULL;
+ ArtSVP *svp = NULL;
+ int pos=0,len=0;
+ gfxline_t*l2;
+ double x=0,y=0;
+
+ l2 = line;
+ while(l2) {
+ if(l2->type == gfx_moveTo) {
+ pos ++;
+ } if(l2->type == gfx_lineTo) {
+ pos ++;
+ } if(l2->type == gfx_splineTo) {
+ int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))/3);
+ if(!parts) parts = 1;
+ pos += parts + 1;
+ }
+ x = l2->x;
+ y = l2->y;
+ l2 = l2->next;
+ }
+ pos++;
+ len = pos;
+
+ vec = art_new (ArtVpath, len);
+
+ pos = 0;
+ l2 = line;
+ while(l2) {
+ if(l2->type == gfx_moveTo) {
+ vec[pos].code = ART_MOVETO;
+ vec[pos].x = l2->x;
+ vec[pos].y = l2->y;
+ pos++;
+ assert(pos<=len);
+ } else if(l2->type == gfx_lineTo) {
+ vec[pos].code = ART_LINETO;
+ vec[pos].x = l2->x;
+ vec[pos].y = l2->y;
+ pos++;
+ assert(pos<=len);
+ } else if(l2->type == gfx_splineTo) {
+ int i;
+ int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))/3);
+ if(!parts) parts = 1;
+ for(i=0;i<=parts;i++) {
+ double t = (double)i/(double)parts;
+ vec[pos].code = ART_LINETO;
+ vec[pos].x = l2->x*t*t + 2*l2->sx*t*(1-t) + x*(1-t)*(1-t);
+ vec[pos].y = l2->y*t*t + 2*l2->sy*t*(1-t) + y*(1-t)*(1-t);
+ pos++;
+ assert(pos<=len);
+ }
+ }
+ x = l2->x;
+ y = l2->y;
+ l2 = l2->next;
+ }
+ vec[pos].code = ART_END;
+
+ svp = art_svp_vpath_stroke (vec,
+ (joint_style==gfx_joinMiter)?ART_PATH_STROKE_JOIN_MITER:
+ ((joint_style==gfx_joinRound)?ART_PATH_STROKE_JOIN_ROUND:
+ ((joint_style==gfx_joinBevel)?ART_PATH_STROKE_JOIN_BEVEL:ART_PATH_STROKE_JOIN_BEVEL)),
+ (cap_style==gfx_capButt)?ART_PATH_STROKE_CAP_BUTT:
+ ((cap_style==gfx_capRound)?ART_PATH_STROKE_CAP_ROUND:
+ ((cap_style==gfx_capSquare)?ART_PATH_STROKE_CAP_SQUARE:ART_PATH_STROKE_CAP_SQUARE)),
+ width, //line_width
+ miterLimit, //miter_limit
+ 0.05 //flatness
+ );
+ free(vec);
+ return svp;
+}
+
+gfxline_t* SVPtogfxline(ArtSVP*svp)
+{
+ int size = 0;
+ int t;
+ int pos = 0;
+ for(t=0;t<svp->n_segs;t++) {
+ size += svp->segs[t].n_points + 1;
+ }
+ gfxline_t* lines = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)*size);
+
+ for(t=0;t<svp->n_segs;t++) {
+ ArtSVPSeg* seg = &svp->segs[t];
+ int p;
+ for(p=0;p<seg->n_points;p++) {
+ lines[pos].type = p==0?gfx_moveTo:gfx_lineTo;
+ ArtPoint* point = &seg->points[p];
+ lines[pos].x = point->x;
+ lines[pos].y = point->y;
+ lines[pos].next = &lines[pos+1];
+ pos++;
+ }
+ }
+ if(pos) {
+ lines[pos-1].next = 0;
+ return lines;
+ } else {
+ return 0;
+ }
+}
+
+
+
+static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int targetheight, int* newwidth, int* newheight)
+{
+ RGBA*newpic = 0;
+ RGBA*mem = (RGBA*)img->data;
+ int bitid = ++i->currentswfid;
+
+ int sizex = img->width;
+ int sizey = img->height;
+ int num_colors = swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,0);
+ int has_alpha = swf_ImageHasAlpha(mem,sizex,sizey);
+ int is_jpeg = i->jpeg;
+ i->jpeg = 0;
+
+ int newsizex=sizex, newsizey=sizey;
+
+ /// {
+ if(is_jpeg && config_jpegsubpixels) {
+ newsizex = (int)(targetwidth*config_jpegsubpixels+0.5);
+ newsizey = (int)(targetheight*config_jpegsubpixels+0.5);
+ } else if(!is_jpeg && config_ppmsubpixels) {
+ newsizex = (int)(targetwidth*config_ppmsubpixels+0.5);
+ newsizey = (int)(targetheight*config_ppmsubpixels+0.5);
+ }
+ /// }
+
+ /* TODO: cache images */
+
+ msg("<verbose> Drawing %dx%d %s%simage at size %dx%d (%dx%d), %s%d colors",
+ sizex, sizey,
+ has_alpha?(has_alpha==2?"semi-transparent ":"transparent "):"",
+ is_jpeg?"jpeg-":"",
+ newsizex, newsizey,
+ targetwidth, targetheight,
+ /*newsizex, newsizey,*/
+ num_colors>256?">":"", num_colors>256?256:num_colors);
+
+ if(newsizex>sizex || newsizey>sizey) {
+ newpic = swf_ImageScale(mem, sizex, sizey, newsizex, newsizey);
+ *newwidth = sizex = newsizex;
+ *newheight = sizey = newsizey;
+ mem = newpic;
+ }
+
+ if(has_alpha) {
+ if(!is_jpeg || num_colors<=256 || sizex<8 || sizey<8) {
+ i->tag = swf_InsertTag(i->tag,ST_DEFINEBITSLOSSLESS2);
+ swf_SetU16(i->tag, bitid);
+ swf_SetLosslessImage(i->tag,mem,sizex,sizey);
+ } else {
+ /*TODO: check what is smaller */
+ i->tag = swf_InsertTag(i->tag,ST_DEFINEBITSJPEG3);
+ swf_SetU16(i->tag, bitid);
+ swf_SetJPEGBits3(i->tag,sizex,sizey,mem,config_jpegquality);
+ //swf_SetLosslessImage(i->tag,mem,sizex,sizey);
+ }
+ } else {
+ if(!is_jpeg || num_colors<=256 || sizex<8 || sizey<8) {
+ i->tag = swf_InsertTag(i->tag,ST_DEFINEBITSLOSSLESS);
+ swf_SetU16(i->tag, bitid);
+ swf_SetLosslessImage(i->tag,mem,sizex,sizey);
+ } else {
+ /*TODO: check what is smaller */
+ i->tag = swf_InsertTag(i->tag,ST_DEFINEBITSJPEG2);
+ swf_SetU16(i->tag, bitid);
+ swf_SetJPEGBits2(i->tag,sizex,sizey,mem,config_jpegquality);
+ //swf_SetLosslessImage(i->tag,mem,sizex,sizey);
+ }