|
@@ -33,44 +33,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
33
|
33
|
#include <ipxe/pixbuf.h>
|
34
|
34
|
#include <ipxe/pnm.h>
|
35
|
35
|
#include <ipxe/test.h>
|
|
36
|
+#include "pixbuf_test.h"
|
36
|
37
|
|
37
|
38
|
/** Define inline pixel data */
|
38
|
39
|
#define DATA(...) { __VA_ARGS__ }
|
39
|
40
|
|
40
|
|
-/** A PNM test */
|
41
|
|
-struct pnm_test {
|
42
|
|
- /** Source image */
|
43
|
|
- struct image *image;
|
44
|
|
- /** Pixel data */
|
45
|
|
- const uint32_t *data;
|
46
|
|
- /** Length of pixel data */
|
47
|
|
- size_t len;
|
48
|
|
- /** Width */
|
49
|
|
- unsigned int width;
|
50
|
|
- /** Height */
|
51
|
|
- unsigned int height;
|
52
|
|
-};
|
53
|
|
-
|
54
|
|
-/** Define a PNM test */
|
55
|
|
-#define PNM( NAME, FILE, WIDTH, HEIGHT, DATA ) \
|
56
|
|
- static const char NAME ## _file[] = FILE; \
|
57
|
|
- static const uint32_t NAME ## _data[] = DATA; \
|
58
|
|
- static struct image NAME ## _image = { \
|
59
|
|
- .refcnt = REF_INIT ( ref_no_free ), \
|
60
|
|
- .name = #NAME, \
|
61
|
|
- .data = ( userptr_t ) ( NAME ## _file ), \
|
62
|
|
- .len = sizeof ( NAME ## _file ), \
|
63
|
|
- }; \
|
64
|
|
- static struct pnm_test NAME = { \
|
65
|
|
- .image = & NAME ## _image, \
|
66
|
|
- .data = NAME ## _data, \
|
67
|
|
- .len = sizeof ( NAME ## _data ), \
|
68
|
|
- .width = WIDTH, \
|
69
|
|
- .height = HEIGHT, \
|
70
|
|
- };
|
71
|
|
-
|
72
|
41
|
/** PBM ASCII example (from Wikipedia) */
|
73
|
|
-PNM ( pbm_ascii,
|
|
42
|
+PIX ( pbm_ascii, &pnm_image_type,
|
74
|
43
|
"P1\n"
|
75
|
44
|
"# This is an example bitmap of the letter \"J\"\n"
|
76
|
45
|
"6 10\n"
|
|
@@ -97,7 +66,7 @@ PNM ( pbm_ascii,
|
97
|
66
|
0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff ) );
|
98
|
67
|
|
99
|
68
|
/** PGM ASCII example (from Wikipedia) */
|
100
|
|
-PNM ( pgm_ascii,
|
|
69
|
+PIX ( pgm_ascii, &pnm_image_type,
|
101
|
70
|
"P2\n"
|
102
|
71
|
"# Shows the word \"FEEP\" (example from Netpbm man page on PGM)\n"
|
103
|
72
|
"24 7\n"
|
|
@@ -140,7 +109,7 @@ PNM ( pgm_ascii,
|
140
|
109
|
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000 ) );
|
141
|
110
|
|
142
|
111
|
/** PPM ASCII example (from Wikipedia) */
|
143
|
|
-PNM ( ppm_ascii,
|
|
112
|
+PIX ( ppm_ascii, &pnm_image_type,
|
144
|
113
|
"P3\n"
|
145
|
114
|
"# The P3 means colors are in ASCII, then 3 columns and 2 rows,\n"
|
146
|
115
|
"# then 255 for max color, then RGB triplets\n"
|
|
@@ -152,7 +121,7 @@ PNM ( ppm_ascii,
|
152
|
121
|
DATA ( 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xffffff, 0x000000 ) );
|
153
|
122
|
|
154
|
123
|
/** PBM ASCII with no space between pixel values */
|
155
|
|
-PNM ( pbm_ascii_no_space,
|
|
124
|
+PIX ( pbm_ascii_no_space, &pnm_image_type,
|
156
|
125
|
"P1\n"
|
157
|
126
|
"3 3\n"
|
158
|
127
|
"001\n"
|
|
@@ -163,7 +132,7 @@ PNM ( pbm_ascii_no_space,
|
163
|
132
|
0x000000, 0x000000, 0x000000 ) );
|
164
|
133
|
|
165
|
134
|
/** PBM binary example (converted from Wikipedia) */
|
166
|
|
-PNM ( pbm_binary,
|
|
135
|
+PIX ( pbm_binary, &pnm_image_type,
|
167
|
136
|
DATA ( 0x50, 0x34, 0x0a, 0x23, 0x20, 0x43, 0x52, 0x45, 0x41, 0x54, 0x4f,
|
168
|
137
|
0x52, 0x3a, 0x20, 0x47, 0x49, 0x4d, 0x50, 0x20, 0x50, 0x4e, 0x4d,
|
169
|
138
|
0x20, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x20, 0x56, 0x65, 0x72,
|
|
@@ -183,7 +152,7 @@ PNM ( pbm_binary,
|
183
|
152
|
0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff ) );
|
184
|
153
|
|
185
|
154
|
/** PGM binary example (converted from Wikipedia) */
|
186
|
|
-PNM ( pgm_binary,
|
|
155
|
+PIX ( pgm_binary, &pnm_image_type,
|
187
|
156
|
DATA ( 0x50, 0x35, 0x0a, 0x32, 0x34, 0x20, 0x37, 0x0a, 0x31, 0x35, 0x0a,
|
188
|
157
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
189
|
158
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
@@ -232,68 +201,26 @@ PNM ( pgm_binary,
|
232
|
201
|
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000 ) );
|
233
|
202
|
|
234
|
203
|
/** PPM binary example (converted from Wikipedia) */
|
235
|
|
-PNM ( ppm_binary,
|
|
204
|
+PIX ( ppm_binary, &pnm_image_type,
|
236
|
205
|
DATA ( 0x50, 0x36, 0x0a, 0x33, 0x20, 0x32, 0x0a, 0x32, 0x35, 0x35, 0x0a,
|
237
|
206
|
0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
|
238
|
207
|
0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 ),
|
239
|
208
|
3, 2,
|
240
|
209
|
DATA ( 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xffffff, 0x000000 ) );
|
241
|
210
|
|
242
|
|
-/**
|
243
|
|
- * Report PNM test result
|
244
|
|
- *
|
245
|
|
- * @v test PNM test
|
246
|
|
- * @v file Test code file
|
247
|
|
- * @v line Test code line
|
248
|
|
- */
|
249
|
|
-static void pnm_okx ( struct pnm_test *test, const char *file,
|
250
|
|
- unsigned int line ) {
|
251
|
|
- struct pixel_buffer *pixbuf;
|
252
|
|
- int rc;
|
253
|
|
-
|
254
|
|
- /* Sanity check */
|
255
|
|
- assert ( ( test->width * test->height * sizeof ( test->data[0] ) )
|
256
|
|
- == test->len );
|
257
|
|
-
|
258
|
|
- /* Correct image data pointer */
|
259
|
|
- test->image->data = virt_to_user ( ( void * ) test->image->data );
|
260
|
|
-
|
261
|
|
- /* Check that image is detected as PNM */
|
262
|
|
- okx ( image_probe ( test->image ) == 0, file, line );
|
263
|
|
- okx ( test->image->type == &pnm_image_type, file, line );
|
264
|
|
-
|
265
|
|
- /* Check that a pixel buffer can be created from the image */
|
266
|
|
- okx ( ( rc = image_pixbuf ( test->image, &pixbuf ) ) == 0, file, line );
|
267
|
|
- if ( rc == 0 ) {
|
268
|
|
-
|
269
|
|
- /* Check pixel buffer dimensions */
|
270
|
|
- okx ( pixbuf->width == test->width, file, line );
|
271
|
|
- okx ( pixbuf->height == test->height, file, line );
|
272
|
|
-
|
273
|
|
- /* Check pixel buffer data */
|
274
|
|
- okx ( pixbuf->len == test->len, file, line );
|
275
|
|
- okx ( memcmp_user ( pixbuf->data, 0,
|
276
|
|
- virt_to_user ( test->data ), 0,
|
277
|
|
- test->len ) == 0, file, line );
|
278
|
|
-
|
279
|
|
- pixbuf_put ( pixbuf );
|
280
|
|
- }
|
281
|
|
-}
|
282
|
|
-#define pnm_ok( test ) pnm_okx ( test, __FILE__, __LINE__ )
|
283
|
|
-
|
284
|
211
|
/**
|
285
|
212
|
* Perform PNM self-test
|
286
|
213
|
*
|
287
|
214
|
*/
|
288
|
215
|
static void pnm_test_exec ( void ) {
|
289
|
216
|
|
290
|
|
- pnm_ok ( &pbm_ascii );
|
291
|
|
- pnm_ok ( &pgm_ascii );
|
292
|
|
- pnm_ok ( &ppm_ascii );
|
293
|
|
- pnm_ok ( &pbm_ascii_no_space );
|
294
|
|
- pnm_ok ( &pbm_binary );
|
295
|
|
- pnm_ok ( &pgm_binary );
|
296
|
|
- pnm_ok ( &ppm_binary );
|
|
217
|
+ pixbuf_ok ( &pbm_ascii );
|
|
218
|
+ pixbuf_ok ( &pgm_ascii );
|
|
219
|
+ pixbuf_ok ( &ppm_ascii );
|
|
220
|
+ pixbuf_ok ( &pbm_ascii_no_space );
|
|
221
|
+ pixbuf_ok ( &pbm_binary );
|
|
222
|
+ pixbuf_ok ( &pgm_binary );
|
|
223
|
+ pixbuf_ok ( &ppm_binary );
|
297
|
224
|
}
|
298
|
225
|
|
299
|
226
|
/** PNM self-test */
|