forked from vectorgraphics/asymptote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawimage.h
128 lines (102 loc) · 2.97 KB
/
drawimage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*****
* drawimage.h
* John Bowman
*
* Stores a image that has been added to a picture.
*****/
#ifndef DRAWIMAGE_H
#define DRAWIMAGE_H
#include "drawelement.h"
#include "array.h"
namespace camp {
class drawImage : public drawElement {
protected:
transform t;
bool antialias;
public:
drawImage(const transform& t, bool antialias, const string& key="")
: drawElement(key), t(t), antialias(antialias) {}
virtual ~drawImage() {}
void bounds(bbox& b, iopipestream&, boxvector&, bboxlist&) {
b += t*pair(0,0);
b += t*pair(1,1);
}
bool svg() {return true;}
bool svgpng() {return true;}
};
class drawPaletteImage : public drawImage {
vm::array image;
vm::array palette;
public:
drawPaletteImage(const vm::array& image, const vm::array& palette,
const transform& t, bool antialias, const string& key="")
: drawImage(t,antialias,key), image(image), palette(palette) {}
virtual ~drawPaletteImage() {}
bool draw(psfile *out) {
out->gsave();
out->concat(t);
out->image(image,palette,antialias);
out->grestore();
return true;
}
drawElement *transformed(const transform& T) {
return new drawPaletteImage(image,palette,T*t,antialias,KEY);
}
};
class drawNoPaletteImage : public drawImage {
vm::array image;
public:
drawNoPaletteImage(const vm::array& image, const transform& t,
bool antialias, const string& key="")
: drawImage(t,antialias,key), image(image) {}
virtual ~drawNoPaletteImage() {}
bool draw(psfile *out) {
out->gsave();
out->concat(t);
out->image(image,antialias);
out->grestore();
return true;
}
drawElement *transformed(const transform& T) {
return new drawNoPaletteImage(image,T*t,antialias,KEY);
}
};
class drawFunctionImage : public drawImage {
vm::stack *Stack;
vm::callable *f;
Int width, height;
public:
drawFunctionImage(vm::stack *Stack, vm::callable *f, Int width, Int height,
const transform& t, bool antialias, const string& key="")
: drawImage(t,antialias,key), Stack(Stack), f(f),
width(width), height(height) {}
virtual ~drawFunctionImage() {}
bool draw(psfile *out) {
out->gsave();
out->concat(t);
out->image(Stack,f,width,height,antialias);
out->grestore();
return true;
}
drawElement *transformed(const transform& T) {
return new drawFunctionImage(Stack,f,width,height,T*t,antialias,KEY);
}
};
class drawRawImage : public drawImage {
unsigned char *raw; // For internal use; not buffered, may be overwritten.
size_t width,height;
public:
drawRawImage(unsigned char *raw, size_t width, size_t height,
const transform& t, bool antialias, const string& key="")
: drawImage(t,antialias,key), raw(raw), width(width), height(height) {}
virtual ~drawRawImage() {}
bool draw(psfile *out) {
out->gsave();
out->concat(t);
out->rawimage(raw,width,height,antialias);
out->grestore();
return true;
}
};
}
#endif