5 int width
, height
, extra
;
8 Bitmap(int e
=0) : extra(e
), data(0) { };
9 ~Bitmap() { delete[] data
; };
11 void size(int w
,int h
) {
15 data
= new Pixel
[w
*h
+extra
];
20 memset(data
,0,sizeof(Pixel
)*(width
*height
+extra
));
24 template<class Pixel
, class Combiner
, int superSampleShift
>
25 struct PolygonEngine
: public Bitmap
<Pixel
> {
26 PolygonEngine() : Bitmap
<Pixel
>(1) { }
28 #define super (1<<superSampleShift)
29 void apply(Pixel
*dest
) {
31 int count
= this->width
*this->height
;
32 Pixel
*src
= this->data
;
36 *dest
= Combiner::combine(sum
,*dest
);
41 void add(Pixel color
,int x
,int y
) {
43 if (y
>= this->height
) return;
45 if (x
> this->width
) x
= this->width
;
46 this->data
[x
+y
*this->width
] += color
;
49 /* Color is char[layers] */
51 // zwoosh, yknow, it goes... zwoosh an all these bars and lines and
53 Pixel colorTable
[2][super
+1];
54 void pen(Pixel color
) {
55 for(int i
=0;i
<super
+1;i
++) {
56 colorTable
[0][i
] = color
*i
;
57 colorTable
[1][i
] = -(color
*i
);
61 void line(int x1
,int y1
,int x2
,int y2
) {
65 temp
= x2
; x2
= x1
; x1
= temp
;
66 temp
= y2
; y2
= y1
; y1
= temp
;
67 colors
= colorTable
[1];
71 colors
= colorTable
[0];
74 int slope
= (x1
-x2
<< 16)/(y1
-y2
);
75 int x
= x1
<<16, y
= y1
;
77 add(colors
[super
-((x
>>16)&(super
-1))],
78 x
>>(16+superSampleShift
),y
>>superSampleShift
);
79 add(colors
[(x
>>16)&(super
-1)],
80 1+(x
>>(16+superSampleShift
)),y
>>superSampleShift
);
86 void icon(double icon
[][4],Pixel color
,double x
,double y
,
87 double scaleX
, double scaleY
) {
93 for(int i
=0;icon
[i
][1] != icon
[i
][3];i
++)
94 line(int(icon
[i
][0]*scaleX
+x
),int(icon
[i
][1]*scaleY
+y
),
95 int(icon
[i
][2]*scaleX
+x
),int(icon
[i
][3]*scaleY
+y
));