Repository navigation
Expand file tree
/
Copy pathutils.c
More file actions
92 lines (76 loc) · 1.73 KB
/
Copy pathutils.c
File metadata and controls
92 lines (76 loc) · 1.73 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Copyright 2011-2015 Thierry FOURNIER
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License.
*
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cairo.h>
#include <cairo-ps.h>
#include <cairo-pdf.h>
#include <cairo-svg.h>
#include "pla.h"
static inline
int hex_to_int(char c)
{
if (c >= '0' && c <='9')
return c - '0';
else if (c >= 'A' && c <= 'F')
return c + 10 - 'A';
else if (c >= 'a' && c <= 'f')
return c + 10 - 'a';
return 0;
}
void convert_rgba_hex(const char *hex, unsigned char alpha, struct color *out)
{
if (hex == NULL)
return;
if (hex[0] == '#')
hex++;
if (strlen(hex) != 6) {
out->r = 0;
out->g = 0;
out->b = 0;
out->a = 0;
return;
}
out->r = ( hex_to_int(hex[0]) * 16.0f ) + hex_to_int(hex[1]);
out->g = ( hex_to_int(hex[2]) * 16.0f ) + hex_to_int(hex[3]);
out->b = ( hex_to_int(hex[4]) * 16.0f ) + hex_to_int(hex[5]);
out->a = alpha;
out->r /= 255.0f;
out->g /= 255.0f;
out->b /= 255.0f;
out->a /= 255.0f;
}
void cairo_set_source_col(cairo_t *c, const struct color *col)
{
cairo_set_source_rgba(c, col->r, col->g, col->b, col->a);
}
void col_dark(struct color *in, struct color *out, double dark) {
out->r = in->r * dark;
out->g = in->g * dark;
out->b = in->b * dark;
out->a = in->a;
}
double max(double *in, int nb)
{
double ret = 0;
int i;
for (i=0; i<nb; i++)
if (in[i] > ret)
ret = in[i];
return ret;
}
cairo_status_t cairo_wr(void *closure, const unsigned char *data, unsigned int length)
{
FILE *out = closure;
fwrite(data, 1, length, out);
return CAIRO_STATUS_SUCCESS;
}