-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkdtree.h
More file actions
40 lines (30 loc) · 1.02 KB
/
kdtree.h
File metadata and controls
40 lines (30 loc) · 1.02 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
#ifndef __KDTREE_H__
#define __KDTREE_H__
#include "image.h"
#ifdef __cplusplus
extern "C" {
#endif
/* k-d tree node for 3D color space (RGB) */
typedef struct kdnode {
rgb_t color; /* RGB color value */
uint8 index; /* palette index */
struct kdnode *left; /* left child (lesser values) */
struct kdnode *right; /* right child (greater values) */
} kdnode_t;
/* k-d tree structure */
typedef struct {
kdnode_t *root;
uint32 size; /* number of colors in tree */
} kdtree_t;
/* Create a k-d tree from a color palette */
kdtree_t *kdtree_create(rgb_t *palette, uint32 num_colors);
/* Destroy a k-d tree and free memory */
void kdtree_destroy(kdtree_t *tree);
/* Find the nearest color in the tree to the given RGB color */
uint8 kdtree_nearest(kdtree_t *tree, uint8 r, uint8 g, uint8 b);
/* Find nearest color and return distance squared */
uint8 kdtree_nearest_dist(kdtree_t *tree, uint8 r, uint8 g, uint8 b, uint32 *dist_sq);
#ifdef __cplusplus
}
#endif
#endif /* __KDTREE_H__ */