blob: bdad696a403c6a5fda0db9db602dd9e9e4898654 [file] [log] [blame]
Kristian Høgsbergffd710e2008-12-02 15:15:01 -05001/*
2 * Copyright © 2008 Kristian Høgsberg
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050023#include <stdint.h>
24#include <stdlib.h>
25#include <string.h>
26#include <stdio.h>
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050027#include <math.h>
28#include <cairo.h>
29#include "cairo-util.h"
30
Kristian Høgsberg27d38662011-10-20 13:11:12 -040031#include <jpeglib.h>
Kristian Høgsbergd6548762012-01-25 15:43:48 -050032#include <png.h>
Kristian Høgsberg27d38662011-10-20 13:11:12 -040033
Kristian Høgsberg87330262008-11-17 22:23:55 -050034#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
35
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050036void
Benjamin Franzke47eb8f42011-10-07 09:08:56 +020037surface_flush_device(cairo_surface_t *surface)
38{
39 cairo_device_t *device;
40
41 device = cairo_surface_get_device(surface);
42 if (device)
43 cairo_device_flush(device);
44}
45
46void
Kristian Høgsberg10bdd292008-11-08 23:27:27 -050047blur_surface(cairo_surface_t *surface, int margin)
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050048{
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050049 int32_t width, height, stride, x, y, z, w;
50 uint8_t *src, *dst;
51 uint32_t *s, *d, a, p;
Kristian Høgsberg87330262008-11-17 22:23:55 -050052 int i, j, k, size, half;
Kristian Høgsberg49e868c2010-06-15 16:18:58 -040053 uint32_t kernel[49];
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050054 double f;
55
Kristian Høgsberg87330262008-11-17 22:23:55 -050056 size = ARRAY_LENGTH(kernel);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050057 width = cairo_image_surface_get_width(surface);
58 height = cairo_image_surface_get_height(surface);
59 stride = cairo_image_surface_get_stride(surface);
60 src = cairo_image_surface_get_data(surface);
61
Kristian Høgsberg5fc96ff2009-09-12 15:58:48 -040062 dst = malloc(height * stride);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050063
64 half = size / 2;
Kristian Høgsberg0cd8f6e2011-01-21 22:19:40 -050065 a = 0;
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050066 for (i = 0; i < size; i++) {
67 f = (i - half);
Kristian Høgsberg49e868c2010-06-15 16:18:58 -040068 kernel[i] = exp(- f * f / ARRAY_LENGTH(kernel)) * 10000;
Kristian Høgsberg0cd8f6e2011-01-21 22:19:40 -050069 a += kernel[i];
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050070 }
71
72 for (i = 0; i < height; i++) {
73 s = (uint32_t *) (src + i * stride);
74 d = (uint32_t *) (dst + i * stride);
75 for (j = 0; j < width; j++) {
Kristian Høgsberg87330262008-11-17 22:23:55 -050076 if (margin < j && j < width - margin) {
77 d[j] = s[j];
Kristian Høgsberg10bdd292008-11-08 23:27:27 -050078 continue;
Kristian Høgsberg87330262008-11-17 22:23:55 -050079 }
80
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050081 x = 0;
82 y = 0;
83 z = 0;
84 w = 0;
85 for (k = 0; k < size; k++) {
86 if (j - half + k < 0 || j - half + k >= width)
87 continue;
88 p = s[j - half + k];
89
90 x += (p >> 24) * kernel[k];
91 y += ((p >> 16) & 0xff) * kernel[k];
92 z += ((p >> 8) & 0xff) * kernel[k];
93 w += (p & 0xff) * kernel[k];
94 }
95 d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
96 }
97 }
98
99 for (i = 0; i < height; i++) {
100 s = (uint32_t *) (dst + i * stride);
101 d = (uint32_t *) (src + i * stride);
102 for (j = 0; j < width; j++) {
Kristian Høgsberg87330262008-11-17 22:23:55 -0500103 if (margin <= i && i < height - margin) {
104 d[j] = s[j];
Kristian Høgsberg10bdd292008-11-08 23:27:27 -0500105 continue;
Kristian Høgsberg87330262008-11-17 22:23:55 -0500106 }
107
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -0500108 x = 0;
109 y = 0;
110 z = 0;
111 w = 0;
112 for (k = 0; k < size; k++) {
113 if (i - half + k < 0 || i - half + k >= height)
114 continue;
115 s = (uint32_t *) (dst + (i - half + k) * stride);
116 p = s[j];
117
118 x += (p >> 24) * kernel[k];
119 y += ((p >> 16) & 0xff) * kernel[k];
120 z += ((p >> 8) & 0xff) * kernel[k];
121 w += (p & 0xff) * kernel[k];
122 }
123 d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
124 }
125 }
126
Kristian Høgsberg5fc96ff2009-09-12 15:58:48 -0400127 free(dst);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400128 cairo_surface_mark_dirty(surface);
129}
130
131void
132tile_mask(cairo_t *cr, cairo_surface_t *surface,
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400133 int x, int y, int width, int height, int margin, int top_margin)
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400134{
135 cairo_pattern_t *pattern;
136 cairo_matrix_t matrix;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400137 int i, fx, fy, vmargin;
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400138
139 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
140 pattern = cairo_pattern_create_for_surface (surface);
141
142 for (i = 0; i < 4; i++) {
143 fx = i & 1;
144 fy = i >> 1;
145
146 cairo_matrix_init_translate(&matrix,
147 -x + fx * (128 - width),
148 -y + fy * (128 - height));
149 cairo_pattern_set_matrix(pattern, &matrix);
150
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400151 if (fy)
152 vmargin = margin;
153 else
154 vmargin = top_margin;
155
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400156 cairo_reset_clip(cr);
157 cairo_rectangle(cr,
158 x + fx * (width - margin),
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400159 y + fy * (height - vmargin),
160 margin, vmargin);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400161 cairo_clip (cr);
162 cairo_mask(cr, pattern);
163 }
164
165 /* Top strecth */
166 cairo_matrix_init_translate(&matrix, 64, 0);
167 cairo_matrix_scale(&matrix, 64.0 / (width - 2 * margin), 1);
168 cairo_matrix_translate(&matrix, -x - width / 2, -y);
169 cairo_pattern_set_matrix(pattern, &matrix);
170 cairo_rectangle(cr, x + margin, y, width - 2 * margin, margin);
171
172 cairo_reset_clip(cr);
173 cairo_rectangle(cr,
174 x + margin,
175 y,
176 width - 2 * margin, margin);
177 cairo_clip (cr);
178 cairo_mask(cr, pattern);
179
180 /* Bottom strecth */
181 cairo_matrix_translate(&matrix, 0, -height + 128);
182 cairo_pattern_set_matrix(pattern, &matrix);
183
184 cairo_reset_clip(cr);
185 cairo_rectangle(cr, x + margin, y + height - margin,
186 width - 2 * margin, margin);
187 cairo_clip (cr);
188 cairo_mask(cr, pattern);
189
190 /* Left strecth */
191 cairo_matrix_init_translate(&matrix, 0, 64);
192 cairo_matrix_scale(&matrix, 1, 64.0 / (height - 2 * margin));
193 cairo_matrix_translate(&matrix, -x, -y - height / 2);
194 cairo_pattern_set_matrix(pattern, &matrix);
195 cairo_reset_clip(cr);
196 cairo_rectangle(cr, x, y + margin, margin, height - 2 * margin);
197 cairo_clip (cr);
198 cairo_mask(cr, pattern);
199
200 /* Right strecth */
201 cairo_matrix_translate(&matrix, -width + 128, 0);
202 cairo_pattern_set_matrix(pattern, &matrix);
203 cairo_rectangle(cr, x + width - margin, y + margin,
204 margin, height - 2 * margin);
205 cairo_reset_clip(cr);
206 cairo_clip (cr);
207 cairo_mask(cr, pattern);
208
209 cairo_pattern_destroy(pattern);
210 cairo_reset_clip(cr);
211}
212
213void
214tile_source(cairo_t *cr, cairo_surface_t *surface,
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400215 int x, int y, int width, int height, int margin, int top_margin)
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400216{
217 cairo_pattern_t *pattern;
218 cairo_matrix_t matrix;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400219 int i, fx, fy, vmargin;
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400220
221 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
222 pattern = cairo_pattern_create_for_surface (surface);
223 cairo_set_source(cr, pattern);
224 cairo_pattern_destroy(pattern);
225
226 for (i = 0; i < 4; i++) {
227 fx = i & 1;
228 fy = i >> 1;
229
230 cairo_matrix_init_translate(&matrix,
231 -x + fx * (128 - width),
232 -y + fy * (128 - height));
233 cairo_pattern_set_matrix(pattern, &matrix);
234
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400235 if (fy)
236 vmargin = margin;
237 else
238 vmargin = top_margin;
239
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400240 cairo_rectangle(cr,
241 x + fx * (width - margin),
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400242 y + fy * (height - vmargin),
243 margin, vmargin);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400244 cairo_fill(cr);
245 }
246
247 /* Top strecth */
248 cairo_matrix_init_translate(&matrix, 64, 0);
249 cairo_matrix_scale(&matrix, 64.0 / (width - 2 * margin), 1);
250 cairo_matrix_translate(&matrix, -x - width / 2, -y);
251 cairo_pattern_set_matrix(pattern, &matrix);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400252 cairo_rectangle(cr, x + margin, y, width - 2 * margin, top_margin);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400253 cairo_fill(cr);
254
255 /* Bottom strecth */
256 cairo_matrix_translate(&matrix, 0, -height + 128);
257 cairo_pattern_set_matrix(pattern, &matrix);
258 cairo_rectangle(cr, x + margin, y + height - margin,
259 width - 2 * margin, margin);
260 cairo_fill(cr);
261
262 /* Left strecth */
263 cairo_matrix_init_translate(&matrix, 0, 64);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400264 cairo_matrix_scale(&matrix, 1, 64.0 / (height - margin - top_margin));
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400265 cairo_matrix_translate(&matrix, -x, -y - height / 2);
266 cairo_pattern_set_matrix(pattern, &matrix);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400267 cairo_rectangle(cr, x, y + top_margin,
268 margin, height - margin - top_margin);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400269 cairo_fill(cr);
270
271 /* Right strecth */
272 cairo_matrix_translate(&matrix, -width + 128, 0);
273 cairo_pattern_set_matrix(pattern, &matrix);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400274 cairo_rectangle(cr, x + width - margin, y + top_margin,
275 margin, height - margin - top_margin);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400276 cairo_fill(cr);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -0500277}
Kristian Høgsberg1e164b92011-09-13 14:47:46 -0400278
279void
280rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius)
281{
282 cairo_move_to(cr, x0, y0 + radius);
283 cairo_arc(cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2);
284 cairo_line_to(cr, x1 - radius, y0);
285 cairo_arc(cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI);
286 cairo_line_to(cr, x1, y1 - radius);
287 cairo_arc(cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2);
288 cairo_line_to(cr, x0 + radius, y1);
289 cairo_arc(cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI);
290 cairo_close_path(cr);
291}
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400292
Kristian Høgsberg02453dd2011-11-22 14:40:00 -0500293static void
294swizzle_row(JSAMPLE *row, JDIMENSION width)
295{
296 JSAMPLE *s;
297 uint32_t *d;
298
299 s = row + (width - 1) * 3;
300 d = (uint32_t *) (row + (width - 1) * 4);
301 while (s >= row) {
302 *d = 0xff000000 | (s[0] << 16) | (s[1] << 8) | (s[2] << 0);
303 s -= 3;
304 d--;
305 }
306}
307
Kristian Høgsbergffe3bba2012-01-25 14:54:26 -0500308static void
309error_exit(j_common_ptr cinfo)
310{
311 longjmp(cinfo->client_data, 1);
312}
313
Kristian Høgsbergd6548762012-01-25 15:43:48 -0500314static cairo_surface_t *
315load_jpeg(FILE *fp)
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400316{
317 struct jpeg_decompress_struct cinfo;
318 struct jpeg_error_mgr jerr;
Kristian Høgsberg02453dd2011-11-22 14:40:00 -0500319 int stride, i, first;
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400320 JSAMPLE *data, *rows[4];
Kristian Høgsbergffe3bba2012-01-25 14:54:26 -0500321 jmp_buf env;
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400322
323 cinfo.err = jpeg_std_error(&jerr);
Kristian Høgsbergffe3bba2012-01-25 14:54:26 -0500324 jerr.error_exit = error_exit;
325 cinfo.client_data = env;
326 if (setjmp(env))
327 return NULL;
328
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400329 jpeg_create_decompress(&cinfo);
330
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400331 jpeg_stdio_src(&cinfo, fp);
332
333 jpeg_read_header(&cinfo, TRUE);
334
Kristian Høgsberg02453dd2011-11-22 14:40:00 -0500335 cinfo.out_color_space = JCS_RGB;
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400336 jpeg_start_decompress(&cinfo);
337
338 stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24,
339 cinfo.output_width);
340 data = malloc(stride * cinfo.output_height);
341 if (data == NULL) {
342 fprintf(stderr, "couldn't allocate image data\n");
343 return NULL;
344 }
345
346 while (cinfo.output_scanline < cinfo.output_height) {
Kristian Høgsberg02453dd2011-11-22 14:40:00 -0500347 first = cinfo.output_scanline;
Kristian Høgsbergbf8bd5a2011-10-20 14:44:48 -0400348 for (i = 0; i < ARRAY_LENGTH(rows); i++)
Kristian Høgsberg02453dd2011-11-22 14:40:00 -0500349 rows[i] = data + (first + i) * stride;
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400350
351 jpeg_read_scanlines(&cinfo, rows, ARRAY_LENGTH(rows));
Kristian Høgsberg02453dd2011-11-22 14:40:00 -0500352 for (i = 0; first + i < cinfo.output_scanline; i++)
353 swizzle_row(rows[i], cinfo.output_width);
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400354 }
355
356 jpeg_finish_decompress(&cinfo);
357
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400358 jpeg_destroy_decompress(&cinfo);
359
360 return cairo_image_surface_create_for_data (data,
361 CAIRO_FORMAT_RGB24,
362 cinfo.output_width,
363 cinfo.output_height,
364 stride);
365}
Kristian Høgsbergd6548762012-01-25 15:43:48 -0500366
367static inline int
368multiply_alpha(int alpha, int color)
369{
370 int temp = (alpha * color) + 0x80;
371
372 return ((temp + (temp >> 8)) >> 8);
373}
374
375static void
376premultiply_data(png_structp png,
377 png_row_infop row_info,
378 png_bytep data)
379{
380 unsigned int i;
381 png_bytep p;
382
383 for (i = 0, p = data; i < row_info->rowbytes; i += 4, p += 4) {
384 png_byte alpha = p[3];
385 uint32_t w;
386
387 if (alpha == 0) {
388 w = 0;
389 } else {
390 png_byte red = p[0];
391 png_byte green = p[1];
392 png_byte blue = p[2];
393
394 if (alpha != 0xff) {
395 red = multiply_alpha(alpha, red);
396 green = multiply_alpha(alpha, green);
397 blue = multiply_alpha(alpha, blue);
398 }
399 w = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
400 }
401
402 * (uint32_t *) p = w;
403 }
404}
405
406static void
407read_func(png_structp png, png_bytep data, png_size_t size)
408{
409 FILE *fp = png_get_io_ptr(png);
410
411 if (fread(data, 1, size, fp) < 0)
412 png_error(png, NULL);
413}
414
415static void
416png_error_callback(png_structp png, png_const_charp error_msg)
417{
418 longjmp (png_jmpbuf (png), 1);
419}
420
421static cairo_surface_t *
422load_png(FILE *fp)
423{
424 png_struct *png;
425 png_info *info;
426 png_byte *data = NULL;
427 png_byte **row_pointers = NULL;
428 png_uint_32 width, height;
429 int depth, color_type, interlace, stride;
430 unsigned int i;
431
432 png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
433 png_error_callback, NULL);
434 if (!png)
435 return NULL;
436
437 info = png_create_info_struct(png);
438 if (!info) {
439 png_destroy_read_struct(&png, &info, NULL);
440 return NULL;
441 }
442
443 if (setjmp(png_jmpbuf(png))) {
444 if (data)
445 free(data);
446 if (row_pointers)
447 free(row_pointers);
448 png_destroy_read_struct(&png, &info, NULL);
449 return NULL;
450 }
451
452 png_set_read_fn(png, fp, read_func);
453 png_read_info(png, info);
454 png_get_IHDR(png, info,
455 &width, &height, &depth,
456 &color_type, &interlace, NULL, NULL);
457
458 if (color_type == PNG_COLOR_TYPE_PALETTE)
459 png_set_palette_to_rgb(png);
460
461 if (color_type == PNG_COLOR_TYPE_GRAY)
462 png_set_expand_gray_1_2_4_to_8(png);
463
464 if (png_get_valid(png, info, PNG_INFO_tRNS))
465 png_set_tRNS_to_alpha(png);
466
467 if (depth == 16)
468 png_set_strip_16(png);
469
470 if (depth < 8)
471 png_set_packing(png);
472
473 if (color_type == PNG_COLOR_TYPE_GRAY ||
474 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
475 png_set_gray_to_rgb(png);
476
477 if (interlace != PNG_INTERLACE_NONE)
478 png_set_interlace_handling(png);
479
480 png_set_filler(png, 0xff, PNG_FILLER_AFTER);
481 png_set_read_user_transform_fn(png, premultiply_data);
482 png_read_update_info(png, info);
483 png_get_IHDR(png, info,
484 &width, &height, &depth,
485 &color_type, &interlace, NULL, NULL);
486
487
488 stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, width);
489 data = malloc(stride * height);
490 if (!data) {
491 png_destroy_read_struct(&png, &info, NULL);
492 return NULL;
493 }
494
495 row_pointers = malloc(height * sizeof row_pointers[0]);
496 if (row_pointers == NULL) {
497 free(data);
498 png_destroy_read_struct(&png, &info, NULL);
499 return NULL;
500 }
501
502 for (i = 0; i < height; i++)
503 row_pointers[i] = &data[i * stride];
504
505 png_read_image(png, row_pointers);
506 png_read_end(png, info);
507
508 free(row_pointers);
509 png_destroy_read_struct(&png, &info, NULL);
510
511 return cairo_image_surface_create_for_data (data,
512 CAIRO_FORMAT_RGB24,
513 width, height, stride);
514}
515
516cairo_surface_t *
517load_image(const char *filename)
518{
519 cairo_surface_t *surface;
520 static const unsigned char png_header[] = { 0x89, 'P', 'N', 'G' };
521 static const unsigned char jpeg_header[] = { 0xff, 0xd8, 0xff, 0xe0 };
522 unsigned char header[4];
523 FILE *fp;
524
525 fp = fopen(filename, "rb");
526 if (fp == NULL)
527 return NULL;
528
529 fread(header, sizeof header, 1, fp);
530 rewind(fp);
531 if (memcmp(header, png_header, sizeof header) == 0)
532 surface = load_png(fp);
533 else if (memcmp(header, jpeg_header, sizeof header) == 0)
534 surface = load_jpeg(fp);
535 else {
536 fprintf(stderr, "unrecognized file header for %s: "
537 "0x%02x 0x%02x 0x%02x 0x%02x\n",
538 filename, header[0], header[1], header[2], header[3]);
539 surface = NULL;
540 }
541
542 fclose(fp);
543
544 return surface;
545}