-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgraph_cairo.c
38 lines (33 loc) · 1012 Bytes
/
graph_cairo.c
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
#include <cairo/cairo.h>
#include "graph.h"
void
graph_backend_create(graph_t *graph)
{
graph->image = cairo_create(
cairo_image_surface_create(CAIRO_FORMAT_RGB24,
graph->width, graph->height));
cairo_set_line_width(graph->image, 0.1);
}
void
graph_backend_set_pixel(const graph_t graph,
const size_t horizontal, const size_t vertical,
const size_t colormap_entry)
{
cairo_rectangle(graph.image, horizontal, vertical, 1, 1);
cairo_set_source_rgb(graph.image,
graph.colormap[colormap_entry][0] / 255.0,
graph.colormap[colormap_entry][1] / 255.0,
graph.colormap[colormap_entry][2] / 255.0);
cairo_fill(graph.image);
}
void
graph_backend_write(const graph_t graph, const char *outputfile)
{
cairo_surface_write_to_png(cairo_get_target(graph.image), outputfile);
}
void
graph_backend_destroy(const graph_t graph)
{
cairo_surface_destroy(cairo_get_target(graph.image));
cairo_destroy(graph.image);
}