+#define IMAGE_TYPE_JPEG 0
+#define IMAGE_TYPE_LOSSLESS 1
+
+static void drawimage(gfxdevice_t*dev, gfxcolor_t* data, int sizex,int sizey,
+ double x1,double y1,
+ double x2,double y2,
+ double x3,double y3,
+ double x4,double y4, int type)
+{
+ gfxcolor_t*newpic=0;
+
+ double l1 = sqrt((x4-x1)*(x4-x1) + (y4-y1)*(y4-y1));
+ double l2 = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
+
+ gfxline_t p1,p2,p3,p4,p5;
+ p1.type=gfx_moveTo;p1.x=x1; p1.y=y1;p1.next=&p2;
+ p2.type=gfx_lineTo;p2.x=x2; p2.y=y2;p2.next=&p3;
+ p3.type=gfx_lineTo;p3.x=x3; p3.y=y3;p3.next=&p4;
+ p4.type=gfx_lineTo;p4.x=x4; p4.y=y4;p4.next=&p5;
+ p5.type=gfx_lineTo;p5.x=x1; p5.y=y1;p5.next=0;
+
+ {p1.x = (int)(p1.x*20)/20.0;
+ p1.y = (int)(p1.y*20)/20.0;
+ p2.x = (int)(p2.x*20)/20.0;
+ p2.y = (int)(p2.y*20)/20.0;
+ p3.x = (int)(p3.x*20)/20.0;
+ p3.y = (int)(p3.y*20)/20.0;
+ p4.x = (int)(p4.x*20)/20.0;
+ p4.y = (int)(p4.y*20)/20.0;
+ p5.x = (int)(p5.x*20)/20.0;
+ p5.y = (int)(p5.y*20)/20.0;
+ }
+
+ float m00,m10,tx;
+ float m01,m11,ty;
+
+ gfxmatrix_t m;
+ m.m00 = (p4.x-p1.x)/sizex; m.m10 = (p2.x-p1.x)/sizey;
+ m.m01 = (p4.y-p1.y)/sizex; m.m11 = (p2.y-p1.y)/sizey;
+ m.tx = p1.x - 0.5;
+ m.ty = p1.y - 0.5;
+
+ gfximage_t img;
+ img.data = (gfxcolor_t*)data;
+ img.width = sizex;
+ img.height = sizey;
+
+ if(type == IMAGE_TYPE_JPEG)
+ /* TODO: pass image_dpi to device instead */
+ dev->setparameter(dev, "next_bitmap_is_jpeg", "1");
+
+ dev->fillbitmap(dev, &p1, &img, &m, 0);
+}
+
+void drawimagejpeg(gfxdevice_t*dev, gfxcolor_t*mem, int sizex,int sizey,
+ double x1,double y1, double x2,double y2, double x3,double y3, double x4,double y4)
+{
+ drawimage(dev,mem,sizex,sizey,x1,y1,x2,y2,x3,y3,x4,y4, IMAGE_TYPE_JPEG);
+}
+
+void drawimagelossless(gfxdevice_t*dev, gfxcolor_t*mem, int sizex,int sizey,
+ double x1,double y1, double x2,double y2, double x3,double y3, double x4,double y4)
+{
+ drawimage(dev,mem,sizex,sizey,x1,y1,x2,y2,x3,y3,x4,y4, IMAGE_TYPE_LOSSLESS);
+}
+
+