Upload Tizen2.0 source
[framework/graphics/cairo.git] / test / png-flatten.c
1 /*
2  * Copyright © 2005 Red Hat, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without
6  * fee, provided that the above copyright notice appear in all copies
7  * and that both that copyright notice and this permission notice
8  * appear in supporting documentation, and that the name of
9  * Red Hat, Inc. not be used in advertising or publicity pertaining to
10  * distribution of the software without specific, written prior
11  * permission. Red Hat, Inc. makes no representations about the
12  * suitability of this software for any purpose.  It is provided "as
13  * is" without express or implied warranty.
14  *
15  * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Author: Carl Worth <cworth@cworth.org>
24  */
25
26 #include <stdio.h>
27
28 #include <cairo.h>
29
30 int
31 main (int argc, char *argv[])
32 {
33     cairo_t *cr;
34     cairo_surface_t *argb, *rgb24;
35     cairo_status_t status;
36     const char *input, *output;
37
38     if (argc != 3) {
39         fprintf (stderr, "usage: %s input.png output.png", argv[0]);
40         fprintf (stderr, "Loads a PNG image (potentially with alpha) and writes out a flattened (no alpha)\nPNG image by first blending over white.\n");
41         return 1;
42     }
43
44     input = argv[1];
45     output = argv[2];
46
47     argb = cairo_image_surface_create_from_png (input);
48     status = cairo_surface_status (argb);
49     if (status) {
50         fprintf (stderr, "%s: Error: Failed to load %s: %s\n",
51                  argv[0], input, cairo_status_to_string (status));
52         return 1;
53     }
54
55     rgb24 = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
56                                         cairo_image_surface_get_width (argb),
57                                         cairo_image_surface_get_height (argb));
58
59     cr = cairo_create (rgb24);
60
61     cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
62     cairo_paint (cr);
63
64     cairo_set_source_surface (cr, argb, 0, 0);
65     cairo_paint (cr);
66
67     cairo_destroy (cr);
68
69     status = cairo_surface_write_to_png (rgb24, output);
70     if (status) {
71         fprintf (stderr, "%s: Error: Failed to write %s: %s\n",
72                  argv[0], output, cairo_status_to_string (status));
73         return 1;
74     }
75
76     return 0;
77 }