Opensource Compliance Issue.
[platform/core/graphics/cairo.git] / doc / tutorial / src / include / cairo-tutorial-png.h
1 /* cairo-tutorial-png.h - a tutorial framework for cairo to write a PNG image
2  *
3  * Copyright © 2005, Carl Worth
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17  */
18
19 #include <cairo.h>
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <assert.h>
24 #include <string.h>
25
26 #ifndef WIDTH
27 #define WIDTH 400
28 #endif
29
30 #ifndef HEIGHT
31 #define HEIGHT 400
32 #endif
33
34 static void
35 draw (cairo_t *cr, int width, int height);
36
37 int
38 main (int argc, char **argv)
39 {
40     cairo_surface_t *surface;
41     cairo_t *cr;
42     char *filename, *dash;
43
44     surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
45                                           WIDTH, HEIGHT);
46
47     cr = cairo_create (surface);
48
49     draw (cr, WIDTH, HEIGHT);
50
51     filename = strdup (argv[0]);
52     assert (filename != NULL);
53
54     dash = strrchr (filename, '-');
55
56     if (strcmp (dash, "-png") == 0) {
57         *dash = '.';
58     } else {
59         char *new_filename;
60         new_filename = malloc (strlen (filename) + 5);
61         sprintf (new_filename, "%s.png", filename);
62         free (filename);
63         filename = new_filename;
64     }
65
66     cairo_surface_write_to_png (surface, filename);
67
68     free (filename);
69
70     cairo_surface_destroy (surface);
71     cairo_destroy (cr);
72
73     return 0;
74 }