1
/*
2
 * Copyright © 2005 Red Hat, Inc.
3
 * Copyright © 2021 Manuel Stoeckl
4
 *
5
 * Permission to use, copy, modify, distribute, and sell this software
6
 * and its documentation for any purpose is hereby granted without
7
 * fee, provided that the above copyright notice appear in all copies
8
 * and that both that copyright notice and this permission notice
9
 * appear in supporting documentation, and that the name of
10
 * Red Hat, Inc. not be used in advertising or publicity pertaining to
11
 * distribution of the software without specific, written prior
12
 * permission. Red Hat, Inc. makes no representations about the
13
 * suitability of this software for any purpose.  It is provided "as
14
 * is" without express or implied warranty.
15
 *
16
 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18
 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
19
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
22
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
 *
24
 * Author: Carl Worth <cworth@cworth.org>
25
 * Author: Manuel Stoeckl <code@mstoeckl.com>
26
 */
27

            
28
#include "cairo-test.h"
29

            
30
#include <stdlib.h>
31

            
32
#define WIDTH 2
33
#define HEIGHT 2
34

            
35
static cairo_test_status_t
36
3
draw (cairo_t *cr, int width, int height)
37
{
38
3
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
39
    char *filename;
40
    cairo_surface_t *surface;
41

            
42
3
    xasprintf (&filename, "%s/reference/%s",
43
3
	       ctx->srcdir, "create-from-png-16bit.base.png");
44

            
45
3
    surface = cairo_image_surface_create_from_png (filename);
46
3
    if (cairo_surface_status (surface)) {
47
	cairo_test_status_t result;
48

            
49
	result = cairo_test_status_from_status (ctx,
50
						cairo_surface_status (surface));
51
	if (result == CAIRO_TEST_FAILURE) {
52
	    cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
53
			    filename,
54
			    cairo_status_to_string (cairo_surface_status (surface)));
55
	}
56

            
57
	free (filename);
58
	return result;
59
    }
60

            
61
    /* Pretend we modify the surface data (which detaches the PNG mime data) */
62
3
    cairo_surface_flush (surface);
63
3
    cairo_surface_mark_dirty (surface);
64

            
65
3
    cairo_set_source_surface (cr, surface, 0, 0);
66
3
    cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
67
3
    cairo_paint (cr);
68

            
69
3
    cairo_surface_destroy (surface);
70

            
71
3
    free (filename);
72
3
    return CAIRO_TEST_SUCCESS;
73
}
74

            
75
1
CAIRO_TEST (create_from_png_16bit,
76
	    "Tests the creation of an image surface from a 16 bit PNG file",
77
	    "png", /* keywords */
78
	    NULL, /* requirements */
79
	    WIDTH, HEIGHT,
80
	    NULL, draw)