+ /// {
+ 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);
+ }
+ /// }
+
+ *newwidth = newsizex;
+ *newheight = newsizey;
+
+
+ /* 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);
+ sizex = newsizex;
+ sizey = newsizey;
+ mem = newpic;
+ }
+
+ if(has_alpha) {
+ if(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(num_colors<=256 || sizex<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);
+ }
+ }
+
+ if(newpic)
+ free(newpic);
+
+ return bitid;
+}
+
+void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+ swfoutput*obj = i->obj;
+
+ if(i->shapeid>=0)
+ endshape(obj,0);
+ if(i->textid>=0)
+ endtext(obj);
+
+ gfxbbox_t bbox = gfxline_getbbox(line);
+
+ int targetx = (int)(sqrt(matrix->m00*matrix->m00 + matrix->m01*matrix->m01)*img->width);
+ int targety = (int)(sqrt(matrix->m10*matrix->m10 + matrix->m11*matrix->m11)*img->height);
+
+ int newwidth=0,newheight=0;
+ int bitid = add_image(i, img, targetx, targety, &newwidth, &newheight);
+ double fx = (double)img->width / (double)newwidth;
+ double fy = (double)img->height / (double)newheight;
+
+ MATRIX m;
+ float m00,m10,tx;
+ float m01,m11,ty;
+ m.sx = (int)(65536*20*matrix->m00*fx);
+ m.r0 = (int)(65536*20*matrix->m01*fx);
+ m.r1 = (int)(65536*20*matrix->m10*fy);
+ m.sy = (int)(65536*20*matrix->m11*fy);
+ m.tx = (int)(matrix->tx*20);
+ m.ty = (int)(matrix->ty*20);