2 * Copyright © 2005 Red Hat, Inc.
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.
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.
23 * Author: Carl Worth <cworth@cworth.org>
31 main (int argc
, char *argv
[])
34 cairo_surface_t
*argb
, *rgb24
;
35 cairo_status_t status
;
36 const char *input
, *output
;
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");
47 argb
= cairo_image_surface_create_from_png (input
);
48 status
= cairo_surface_status (argb
);
50 fprintf (stderr
, "%s: Error: Failed to load %s: %s\n",
51 argv
[0], input
, cairo_status_to_string (status
));
55 rgb24
= cairo_image_surface_create (CAIRO_FORMAT_RGB24
,
56 cairo_image_surface_get_width (argb
),
57 cairo_image_surface_get_height (argb
));
59 cr
= cairo_create (rgb24
);
61 cairo_set_source_rgb (cr
, 1.0, 1.0, 1.0); /* white */
64 cairo_set_source_surface (cr
, argb
, 0, 0);
69 status
= cairo_surface_write_to_png (rgb24
, output
);
71 fprintf (stderr
, "%s: Error: Failed to write %s: %s\n",
72 argv
[0], output
, cairo_status_to_string (status
));