1 /* -*- C -*-
2 * This program is written by Henning Makholm, and is in the
3 * public domain.
4 */
5
6 #include <png.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 static void
error(png_structp png_ptr,png_const_charp errormsg)11 error(png_structp png_ptr, png_const_charp errormsg)
12 {
13 fprintf(stderr,"PNG error: %s\n",errormsg);
14 exit(1);
15 }
16
17
18 int
main(void)19 main(void)
20 {
21 png_structp libpng = NULL ;
22 png_infop libpng2 = NULL ;
23 unsigned char row[TEST_IMAGE_WIDTH*4] ;
24 unsigned x,y ;
25 int r,g,b,a ;
26
27 libpng = png_create_write_struct(PNG_LIBPNG_VER_STRING,
28 png_voidp_NULL,
29 error,
30 png_error_ptr_NULL);
31 if( !libpng )
32 error(libpng,"Couldn't initialize libpng library");
33
34 libpng2 = png_create_info_struct(libpng);
35 if( !libpng2 )
36 error(libpng,"Couldn't create PNG info structure");
37
38 png_init_io(libpng,stdout);
39
40 png_set_IHDR(libpng,libpng2,TEST_IMAGE_WIDTH,TEST_IMAGE_HEIGHT,
41 8, PNG_COLOR_TYPE_RGB_ALPHA,
42 PNG_INTERLACE_NONE,
43 PNG_COMPRESSION_TYPE_DEFAULT,
44 PNG_FILTER_TYPE_DEFAULT);
45
46 png_write_info(libpng,libpng2);
47
48 for( y=0; y<TEST_IMAGE_HEIGHT; y++ ) {
49 for( x=0; x<TEST_IMAGE_WIDTH; x++ ) {
50 makepixel(x,y,&r,&g,&b,&a);
51 row[x*4+0] = r ;
52 row[x*4+1] = g ;
53 row[x*4+2] = b ;
54 row[x*4+3] = a ;
55 }
56 png_write_row(libpng,row);
57 }
58 png_write_end(libpng,libpng2);
59 return 0 ;
60 }
61