]> mj.ucw.cz Git - libucw.git/blob - images/images.c
Simple image search... under construction
[libucw.git] / images / images.c
1 #define LOCAL_DEBUG
2
3 #include "sherlock/sherlock.h"
4 #include "lib/fastbuf.h"
5 #include "images/images.h"
6 #include "sherlock/index.h"
7
8 #include <stdio.h>
9 #include <fcntl.h>
10
11 struct image_tree image_tree;
12
13 void
14 image_tree_init(void)
15 {
16   DBG("Initializing image search structures");
17   struct fastbuf *fb = bopen("index/image-tree", O_RDONLY, 1 << 16); /* FIXME: filename hack */
18   image_tree.count = bgetl(fb);
19   image_tree.depth = bgetl(fb);
20   ASSERT(image_tree.count < 0x80000000 && image_tree.depth > 0 && image_tree.depth < 30);
21   image_tree.nodes = xmalloc((1 << image_tree.depth) * sizeof(struct image_node));
22   image_tree.leaves = xmalloc(image_tree.count * sizeof(struct image_leaf));
23   bread(fb, &image_tree.bbox, sizeof(struct image_bbox));
24   bread(fb, image_tree.nodes + 1, ((1 << image_tree.depth) - 1) * sizeof(struct image_node));
25   bread(fb, image_tree.leaves, image_tree.count * sizeof(struct image_leaf));
26   DBG("Search tree with depth %d and %d leaves loaded", image_tree.depth, image_tree.count);
27   bclose(fb);
28 }
29
30 void
31 image_tree_done(void)
32 {
33   DBG("Freeing image search structures");
34   xfree(image_tree.nodes);
35   xfree(image_tree.leaves);
36 }
37