summaryrefslogtreecommitdiff
path: root/util.h
blob: c6b5c412e30b5445c608bc60dc6822e1fb72fa77 (plain)
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
#ifndef _UTIL_H_
#define _UTIL_H_

#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

#include <string.h>

typedef struct _point {
	gint16 x, y;
} point_t;
#define POINT(_x, _y) ((point_t){.x=(_x), .y=(_y)})

/* a vector is the same as a point */
typedef point_t vector_t;
#define VECTOR(_x, _y) POINT(_x, _y)

static inline vector_t vector(point_t p1, point_t p2) {
	return VECTOR(p2.x - p1.x, p2.y - p1.y); 
}

typedef struct _color {
	guint8 r, g, b, a;
} color_t;
#define COLOR(_r, _g, _b, _a) ((color_t){.r=(_r), .g=(_g), .b=(_b), .a=(_a)})
#define COL_MAX G_MAXUINT8

typedef struct _color32 {
	gint32 r, g, b;
} color32_t;

#define COLOR32(_r, _g, _b) ((color32_t){.r=(_r), .g=(_g), .b=(_b)})
#define COL32_MAX G_MAXINT32

color32_t color32_add(color32_t, color32_t);
color32_t color32_mult(color32_t, gint);
color32_t to_color32(color_t);

typedef struct _colord {
	gdouble r, g, b, a;
} colord_t;
colord_t colord_add(colord_t, colord_t);
colord_t colord_mult(colord_t, gdouble);
colord_t to_colord(color_t);
#define COLORD(_r, _g, _b, _a) ((colord_t){.r=(_r), .g=(_g), .b=(_b), .a=(_a)})
#define COLORD_MAX G_MAXDOUBLE

void put_pixel(GdkPixbuf *pixbuf, point_t point, color_t color);

color_t get_pixel(GdkPixbuf *pixbuf, point_t point);

void color_to_yiq(color_t color, guint8 *y, guint8 *i, guint8 *q);

color_t tint(color_t src, color_t tint_color);

void ring_shift(void *_pntr, gint num, size_t size);

#endif /* _UTIL_H_ */