]> mj.ucw.cz Git - libucw.git/blob - images/images.h
First try of libjpeg... much faster than graphicsmagick
[libucw.git] / images / images.h
1 #ifndef _IMAGES_IMAGES_H
2 #define _IMAGES_IMAGES_H
3
4 #include <alloca.h>
5 #include <stdio.h>
6
7 enum image_flag {
8   IMAGE_GRAYSCALE = 0x1,        /* RGB otherwise */
9 };
10
11 struct image {
12   uns flags;                    /* enum thumbnail_flags */
13   uns width;                    /* number of columns */
14   uns height;                   /* number of rows */
15   byte *pixels;                 /* 3 bytes per pixel for RGB, 1 byte for grayscale */
16 };
17
18 #define IMAGE_VEC_K     6
19 #define IMAGE_REG_K     9
20 #define IMAGE_REG_MAX   4
21
22 typedef u16 image_feature_t;    /* 8 or 16 bits precision */
23
24 /* K-dimensional feature vector */
25 struct image_vector {
26   image_feature_t f[IMAGE_VEC_K];
27 };
28
29 /* K-dimensional interval */
30 struct image_bbox {
31   struct image_vector vec[2];
32 };
33
34 /* Fetures for image regions */
35 struct image_region {
36   image_feature_t f[IMAGE_REG_K];
37 };
38
39 /* Image signature */
40 struct image_signature {
41   struct image_vector vec;      /* Combination of all regions... simplier signature */
42   image_feature_t len;          /* Number of regions */
43   struct image_region reg[IMAGE_REG_MAX];/* Feature vector for every region */
44 };
45
46 /* Similarity search tree... will be changed */
47 struct image_tree {
48   uns count;                    /* Number of images in the tree */
49   uns depth;                    /* Tree depth */
50   struct image_bbox bbox;       /* Bounding box containing all the */
51   struct image_node *nodes;     /* Internal nodes */
52   struct image_leaf *leaves;    /* Leaves */
53 };
54
55 /* Internal node in the search tree */
56 #define IMAGE_NODE_LEAF         0x80000000              /* Node contains pointer to leaves array */
57 #define IMAGE_NODE_DIM          0xff                    /* Split dimension */
58 struct image_node {
59   u32 val;
60 };
61
62 /* Leaves in the search tree */
63 #define IMAGE_LEAF_LAST         0x80000000              /* Last entry in the list */
64 #define IMAGE_LEAF_BITS(i)      (31 / IMAGE_VEC_K)      /* Number of bits for relative position in i-th dimension */
65 struct image_leaf {
66   u32 flags;            /* Relative position in bbox and last node flag */ 
67   oid_t oid;
68 };
69
70 #define stk_print_image_vector(v) ({ struct image_vector *_v = v; \
71     byte *_s = (byte *) alloca(IMAGE_VEC_K * 6), *_p = _s + sprintf(_s, "%d", _v->f[0]); \
72     for (uns _i = 1; _i < IMAGE_VEC_K; _i++) _p += sprintf(_p, " %d", _v->f[_i]); _s; })
73
74 extern struct image_tree image_tree;
75
76 void image_tree_init(void);
77 void image_tree_done(void);
78
79 void compute_image_signature_prepare(void);
80 void compute_image_signature_finish(void);
81 int compute_image_signature(struct image *image, struct image_signature *sig);
82
83 #endif
84