File: f-image-surface.c

package info (click to toggle)
f-spot 0.8.2-5
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 26,376 kB
  • sloc: cs: 138,718; sh: 16,964; makefile: 2,321; xml: 783; ansic: 721
file content (63 lines) | stat: -rw-r--r-- 1,325 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <gdk/gdk.h>
#include <cairo.h>

const cairo_user_data_key_t pixel_key;
const cairo_user_data_key_t format_key;

cairo_surface_t *
f_image_surface_create (cairo_format_t format, int width, int height)
{
	int size;
	cairo_surface_t *surface;
	unsigned char *pixels;

	switch (format) {
	case CAIRO_FORMAT_ARGB32:
	case CAIRO_FORMAT_RGB24:
		size = 4;
		break;
	case CAIRO_FORMAT_A8:
		size = 8;
		break;
	case CAIRO_FORMAT_A1:
		size = 1;
		break;
	}

	pixels = g_malloc (width * height * size);
	surface = cairo_image_surface_create_for_data (pixels,
						       format,
						       width,
						       height,
						       width * size);

	cairo_surface_set_user_data (surface, &pixel_key, pixels, g_free);
	cairo_surface_set_user_data (surface, &format_key, GINT_TO_POINTER (format), NULL);

	return surface;
}

void  *
f_image_surface_get_data (cairo_surface_t *surface)
{
	return cairo_surface_get_user_data (surface, &pixel_key);
}

cairo_format_t
f_image_surface_get_format (cairo_surface_t *surface)
{
	return GPOINTER_TO_INT (cairo_surface_get_user_data (surface, &format_key));
}

int
f_image_surface_get_width (cairo_surface_t *surface)
{
	return cairo_image_surface_get_width (surface);
}

int
f_image_surface_get_height (cairo_surface_t *surface)
{
	return cairo_image_surface_get_height (surface);	
}