1 | #include "mupdf/fitz.h" |
2 | #include "fitz-imp.h" |
3 | |
4 | #include <string.h> |
5 | |
6 | static const unsigned char pkm[256*8] = |
7 | { |
8 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
9 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, |
10 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, |
11 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, |
12 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, |
13 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, |
14 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, |
15 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, |
16 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, |
17 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, |
18 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, |
19 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, |
20 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, |
21 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, |
22 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, |
23 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, |
24 | 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, |
25 | 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, |
26 | 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, |
27 | 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, |
28 | 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, |
29 | 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, |
30 | 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, |
31 | 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, |
32 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, |
33 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, |
34 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, |
35 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, |
36 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, |
37 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, |
38 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, |
39 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
40 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, |
41 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, |
42 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, |
43 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, |
44 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, |
45 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, |
46 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, |
47 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, |
48 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, |
49 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, |
50 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, |
51 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, |
52 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, |
53 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, |
54 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, |
55 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, |
56 | 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, |
57 | 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, |
58 | 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, |
59 | 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, |
60 | 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, |
61 | 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, |
62 | 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, |
63 | 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, |
64 | 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, |
65 | 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, |
66 | 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, |
67 | 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, |
68 | 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, |
69 | 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, |
70 | 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, |
71 | 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
72 | 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
73 | 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, |
74 | 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, |
75 | 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, |
76 | 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, |
77 | 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, |
78 | 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, |
79 | 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, |
80 | 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, |
81 | 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, |
82 | 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, |
83 | 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, |
84 | 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, |
85 | 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, |
86 | 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, |
87 | 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, |
88 | 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, |
89 | 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, |
90 | 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, |
91 | 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, |
92 | 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, |
93 | 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, |
94 | 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, |
95 | 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, |
96 | 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, |
97 | 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, |
98 | 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, |
99 | 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, |
100 | 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, |
101 | 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, |
102 | 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, |
103 | 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
104 | 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, |
105 | 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, |
106 | 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, |
107 | 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, |
108 | 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, |
109 | 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, |
110 | 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, |
111 | 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, |
112 | 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, |
113 | 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, |
114 | 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, |
115 | 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, |
116 | 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, |
117 | 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, |
118 | 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, |
119 | 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, |
120 | 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, |
121 | 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, |
122 | 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, |
123 | 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, |
124 | 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, |
125 | 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, |
126 | 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, |
127 | 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, |
128 | 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, |
129 | 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, |
130 | 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, |
131 | 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, |
132 | 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, |
133 | 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, |
134 | 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, |
135 | 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
136 | 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
137 | 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, |
138 | 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, |
139 | 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, |
140 | 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, |
141 | 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, |
142 | 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, |
143 | 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, |
144 | 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, |
145 | 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, |
146 | 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, |
147 | 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, |
148 | 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, |
149 | 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, |
150 | 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, |
151 | 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, |
152 | 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, |
153 | 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, |
154 | 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, |
155 | 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, |
156 | 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, |
157 | 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, |
158 | 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, |
159 | 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, |
160 | 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, |
161 | 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, |
162 | 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, |
163 | 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, |
164 | 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, |
165 | 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, |
166 | 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, |
167 | 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
168 | 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, |
169 | 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, |
170 | 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, |
171 | 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, |
172 | 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, |
173 | 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, |
174 | 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, |
175 | 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, |
176 | 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, |
177 | 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, |
178 | 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, |
179 | 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, |
180 | 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, |
181 | 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, |
182 | 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, |
183 | 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, |
184 | 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, |
185 | 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, |
186 | 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, |
187 | 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, |
188 | 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, |
189 | 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, |
190 | 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, |
191 | 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, |
192 | 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, |
193 | 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, |
194 | 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, |
195 | 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, |
196 | 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, |
197 | 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, |
198 | 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, |
199 | 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
200 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
201 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, |
202 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, |
203 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, |
204 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, |
205 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, |
206 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, |
207 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, |
208 | 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, |
209 | 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, |
210 | 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, |
211 | 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, |
212 | 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, |
213 | 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, |
214 | 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, |
215 | 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, |
216 | 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, |
217 | 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, |
218 | 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, |
219 | 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, |
220 | 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, |
221 | 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, |
222 | 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, |
223 | 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, |
224 | 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, |
225 | 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, |
226 | 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, |
227 | 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, |
228 | 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, |
229 | 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, |
230 | 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, |
231 | 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
232 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, |
233 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, |
234 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, |
235 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, |
236 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, |
237 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, |
238 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, |
239 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, |
240 | 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, |
241 | 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, |
242 | 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, |
243 | 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, |
244 | 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, |
245 | 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, |
246 | 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, |
247 | 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, |
248 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, |
249 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, |
250 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, |
251 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, |
252 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, |
253 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, |
254 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, |
255 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, |
256 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, |
257 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, |
258 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, |
259 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, |
260 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, |
261 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, |
262 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, |
263 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF |
264 | }; |
265 | |
266 | /* |
267 | Create a new bitmap. |
268 | |
269 | w, h: Width and Height for the bitmap |
270 | |
271 | n: Number of color components (assumed to be a divisor of 8) |
272 | |
273 | xres, yres: X and Y resolutions (in pixels per inch). |
274 | |
275 | Returns pointer to created bitmap structure. The bitmap |
276 | data is uninitialised. |
277 | */ |
278 | fz_bitmap * |
279 | fz_new_bitmap(fz_context *ctx, int w, int h, int n, int xres, int yres) |
280 | { |
281 | fz_bitmap *bit; |
282 | |
283 | /* Stride is 32 bit aligned. We may want to make this 64 bit if we use SSE2 etc. */ |
284 | int stride = ((n * w + 31) & ~31) >> 3; |
285 | if (h > SIZE_MAX / stride) |
286 | fz_throw(ctx, FZ_ERROR_MEMORY, "bitmap too large" ); |
287 | |
288 | bit = fz_malloc_struct(ctx, fz_bitmap); |
289 | fz_try(ctx) |
290 | { |
291 | bit->refs = 1; |
292 | bit->w = w; |
293 | bit->h = h; |
294 | bit->n = n; |
295 | bit->xres = xres; |
296 | bit->yres = yres; |
297 | bit->stride = stride; |
298 | bit->samples = fz_malloc(ctx, h * bit->stride); |
299 | } |
300 | fz_catch(ctx) |
301 | { |
302 | fz_free(ctx, bit); |
303 | fz_rethrow(ctx); |
304 | } |
305 | |
306 | return bit; |
307 | } |
308 | |
309 | fz_bitmap * |
310 | fz_keep_bitmap(fz_context *ctx, fz_bitmap *bit) |
311 | { |
312 | return fz_keep_imp(ctx, bit, &bit->refs); |
313 | } |
314 | |
315 | void |
316 | fz_drop_bitmap(fz_context *ctx, fz_bitmap *bit) |
317 | { |
318 | if (fz_drop_imp(ctx, bit, &bit->refs)) |
319 | { |
320 | fz_free(ctx, bit->samples); |
321 | fz_free(ctx, bit); |
322 | } |
323 | } |
324 | |
325 | void |
326 | fz_clear_bitmap(fz_context *ctx, fz_bitmap *bit) |
327 | { |
328 | memset(bit->samples, 0, bit->stride * bit->h); |
329 | } |
330 | |
331 | static void |
332 | (fz_context *ctx, fz_band_writer *writer, fz_colorspace *cs) |
333 | { |
334 | fz_output *out = writer->out; |
335 | int w = writer->w; |
336 | int h = writer->h; |
337 | |
338 | if (writer->s != 0) |
339 | fz_throw(ctx, FZ_ERROR_GENERIC, "pbms cannot contain spot colors" ); |
340 | |
341 | fz_write_printf(ctx, out, "P4\n%d %d\n" , w, h); |
342 | } |
343 | |
344 | static void |
345 | (fz_context *ctx, fz_band_writer *writer, fz_colorspace *cs) |
346 | { |
347 | fz_output *out = writer->out; |
348 | int w = writer->w; |
349 | int h = writer->h; |
350 | |
351 | if (writer->s != 0) |
352 | fz_throw(ctx, FZ_ERROR_GENERIC, "pkms cannot contain spot colors" ); |
353 | |
354 | fz_write_printf(ctx, out, "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE CMYK\nENDHDR\n" , w, h); |
355 | } |
356 | |
357 | void |
358 | fz_write_bitmap_as_pbm(fz_context *ctx, fz_output *out, fz_bitmap *bitmap) |
359 | { |
360 | fz_band_writer *writer; |
361 | |
362 | if (bitmap->n != 1) |
363 | fz_throw(ctx, FZ_ERROR_GENERIC, "bitmap must be monochrome to save as PBM" ); |
364 | |
365 | writer = fz_new_pbm_band_writer(ctx, out); |
366 | fz_try(ctx) |
367 | { |
368 | fz_write_header(ctx, writer, bitmap->w, bitmap->h, 1, 0, 0, 0, 0, NULL, NULL); |
369 | fz_write_band(ctx, writer, bitmap->stride, bitmap->h, bitmap->samples); |
370 | } |
371 | fz_always(ctx) |
372 | fz_drop_band_writer(ctx, writer); |
373 | fz_catch(ctx) |
374 | fz_rethrow(ctx); |
375 | } |
376 | |
377 | void |
378 | fz_write_bitmap_as_pkm(fz_context *ctx, fz_output *out, fz_bitmap *bitmap) |
379 | { |
380 | fz_band_writer *writer; |
381 | |
382 | if (bitmap->n != 4) |
383 | fz_throw(ctx, FZ_ERROR_GENERIC, "bitmap must be CMYK to save as PKM" ); |
384 | |
385 | writer = fz_new_pkm_band_writer(ctx, out); |
386 | fz_try(ctx) |
387 | { |
388 | fz_write_header(ctx, writer, bitmap->w, bitmap->h, 4, 0, 0, 0, 0, NULL, NULL); |
389 | fz_write_band(ctx, writer, bitmap->stride, bitmap->h, bitmap->samples); |
390 | } |
391 | fz_always(ctx) |
392 | fz_drop_band_writer(ctx, writer); |
393 | fz_catch(ctx) |
394 | fz_rethrow(ctx); |
395 | } |
396 | |
397 | static void |
398 | pbm_write_band(fz_context *ctx, fz_band_writer *writer, int stride, int band_start, int band_height, const unsigned char *p) |
399 | { |
400 | fz_output *out = writer->out; |
401 | int w = writer->w; |
402 | int h = writer->h; |
403 | int n = writer->n; |
404 | int bytestride; |
405 | int end = band_start + band_height; |
406 | |
407 | if (n != 1) |
408 | fz_throw(ctx, FZ_ERROR_GENERIC, "too many color components in bitmap" ); |
409 | |
410 | if (end > h) |
411 | end = h; |
412 | end -= band_start; |
413 | |
414 | bytestride = (w + 7) >> 3; |
415 | while (end--) |
416 | { |
417 | fz_write_data(ctx, out, p, bytestride); |
418 | p += stride; |
419 | } |
420 | } |
421 | |
422 | static void |
423 | pkm_write_band(fz_context *ctx, fz_band_writer *writer, int stride, int band_start, int band_height, const unsigned char *p) |
424 | { |
425 | fz_output *out = writer->out; |
426 | int w = writer->w; |
427 | int h = writer->h; |
428 | int n = writer->n; |
429 | int bytestride; |
430 | int end = band_start + band_height; |
431 | |
432 | if (n != 4) |
433 | fz_throw(ctx, FZ_ERROR_GENERIC, "wrong number of color components in bitmap" ); |
434 | |
435 | if (end > h) |
436 | end = h; |
437 | end -= band_start; |
438 | |
439 | bytestride = stride - (w>>1); |
440 | while (end--) |
441 | { |
442 | int ww = w-1; |
443 | while (ww > 0) |
444 | { |
445 | fz_write_data(ctx, out, &pkm[8 * *p++], 8); |
446 | ww -= 2; |
447 | } |
448 | if (ww == 0) |
449 | fz_write_data(ctx, out, &pkm[8 * *p], 4); |
450 | p += bytestride; |
451 | } |
452 | } |
453 | |
454 | fz_band_writer *fz_new_pbm_band_writer(fz_context *ctx, fz_output *out) |
455 | { |
456 | fz_band_writer *writer = fz_new_band_writer(ctx, fz_band_writer, out); |
457 | |
458 | writer->header = pbm_write_header; |
459 | writer->band = pbm_write_band; |
460 | |
461 | return writer; |
462 | } |
463 | |
464 | fz_band_writer *fz_new_pkm_band_writer(fz_context *ctx, fz_output *out) |
465 | { |
466 | fz_band_writer *writer = fz_new_band_writer(ctx, fz_band_writer, out); |
467 | |
468 | writer->header = pkm_write_header; |
469 | writer->band = pkm_write_band; |
470 | |
471 | return writer; |
472 | } |
473 | |
474 | void |
475 | fz_save_bitmap_as_pbm(fz_context *ctx, fz_bitmap *bitmap, const char *filename) |
476 | { |
477 | fz_output *out = fz_new_output_with_path(ctx, filename, 0); |
478 | fz_try(ctx) |
479 | { |
480 | fz_write_bitmap_as_pbm(ctx, out, bitmap); |
481 | fz_close_output(ctx, out); |
482 | } |
483 | fz_always(ctx) |
484 | fz_drop_output(ctx, out); |
485 | fz_catch(ctx) |
486 | fz_rethrow(ctx); |
487 | } |
488 | |
489 | void |
490 | fz_save_bitmap_as_pkm(fz_context *ctx, fz_bitmap *bitmap, const char *filename) |
491 | { |
492 | fz_output *out = fz_new_output_with_path(ctx, filename, 0); |
493 | fz_try(ctx) |
494 | { |
495 | fz_write_bitmap_as_pkm(ctx, out, bitmap); |
496 | fz_close_output(ctx, out); |
497 | } |
498 | fz_always(ctx) |
499 | fz_drop_output(ctx, out); |
500 | fz_catch(ctx) |
501 | fz_rethrow(ctx); |
502 | } |
503 | |
504 | void |
505 | fz_save_pixmap_as_pbm(fz_context *ctx, fz_pixmap *pixmap, const char *filename) |
506 | { |
507 | fz_bitmap *bitmap = fz_new_bitmap_from_pixmap(ctx, pixmap, NULL); |
508 | fz_try(ctx) |
509 | fz_save_bitmap_as_pbm(ctx, bitmap, filename); |
510 | fz_always(ctx) |
511 | fz_drop_bitmap(ctx, bitmap); |
512 | fz_catch(ctx) |
513 | fz_rethrow(ctx); |
514 | } |
515 | |
516 | void |
517 | fz_save_pixmap_as_pkm(fz_context *ctx, fz_pixmap *pixmap, const char *filename) |
518 | { |
519 | fz_bitmap *bitmap = fz_new_bitmap_from_pixmap(ctx, pixmap, NULL); |
520 | fz_try(ctx) |
521 | fz_save_bitmap_as_pkm(ctx, bitmap, filename); |
522 | fz_always(ctx) |
523 | fz_drop_bitmap(ctx, bitmap); |
524 | fz_catch(ctx) |
525 | fz_rethrow(ctx); |
526 | } |
527 | |
528 | /* |
529 | Retrieve details of a given bitmap. |
530 | |
531 | bitmap: The bitmap to query. |
532 | |
533 | w: Pointer to storage to retrieve width (or NULL). |
534 | |
535 | h: Pointer to storage to retrieve height (or NULL). |
536 | |
537 | n: Pointer to storage to retrieve number of color components (or NULL). |
538 | |
539 | stride: Pointer to storage to retrieve bitmap stride (or NULL). |
540 | */ |
541 | void fz_bitmap_details(fz_bitmap *bit, int *w, int *h, int *n, int *stride) |
542 | { |
543 | if (!bit) |
544 | { |
545 | if (w) |
546 | *w = 0; |
547 | if (h) |
548 | *h = 0; |
549 | if (n) |
550 | *n = 0; |
551 | if (stride) |
552 | *stride = 0; |
553 | return; |
554 | } |
555 | if (w) |
556 | *w = bit->w; |
557 | if (h) |
558 | *h = bit->h; |
559 | if (n) |
560 | *n = bit->n; |
561 | if (stride) |
562 | *stride = bit->stride; |
563 | } |
564 | |