Mercurial > fife-parpg
comparison utils/frmconv/out_png.c @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 #ifdef _WIN32 | |
2 #define ssize_t int | |
3 #include <io.h> | |
4 #include <sys/types.h> | |
5 #include <Winsock2.h> | |
6 #else | |
7 #include <netinet/in.h> | |
8 #include <unistd.h> | |
9 #endif | |
10 | |
11 #include <stdio.h> | |
12 | |
13 #include <png.h> | |
14 | |
15 #include "frm.h" | |
16 #include "out_png.h" | |
17 | |
18 | |
19 | |
20 void png_my_error(png_structp a, png_const_charp b) { | |
21 printf("png_my_error: %s\n", b); | |
22 } | |
23 void png_my_warning(png_structp a, png_const_charp b) { | |
24 printf("png_my_warn: %s\n", b); | |
25 } | |
26 | |
27 void writePNGFile(frm_frame *frame, frm_color *pal, FILE *file) { | |
28 if (!file) { | |
29 printf("ERR: write open failed\n"); | |
30 return; | |
31 } | |
32 | |
33 png_structp png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, NULL, png_my_error, png_my_warning); | |
34 if (!png_ptr) | |
35 return; | |
36 | |
37 png_infop info_ptr = png_create_info_struct(png_ptr); | |
38 if (!info_ptr) { | |
39 png_destroy_write_struct(&png_ptr, (png_infopp)NULL); | |
40 return; | |
41 } | |
42 | |
43 if (setjmp(png_jmpbuf(png_ptr))) { | |
44 png_destroy_write_struct(&png_ptr, &info_ptr); | |
45 printf("Error: return setjmp\n"); | |
46 return; | |
47 } | |
48 | |
49 png_init_io(png_ptr, file); | |
50 png_set_IHDR(png_ptr, info_ptr, frame->width, frame->height, 8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | |
51 | |
52 png_set_PLTE(png_ptr, info_ptr, (png_color*)pal, 256); | |
53 png_set_rows(png_ptr, info_ptr, frame->rowptr); | |
54 png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); | |
55 } |