3 #include "sherlock/sherlock.h"
4 #include "lib/mempool.h"
6 #include "lib/fastbuf.h"
7 #include "lib/chartype.h"
8 #include "sherlock/object.h"
10 #include "lib/unicode.h"
11 #include "sherlock/lizard-fb.h"
12 #include "sherlock/tagged-text.h"
13 #include "charset/charconv.h"
14 #include "charset/unicat.h"
15 #include "charset/fb-charconv.h"
16 #include "indexer/indexer.h"
17 #include "indexer/lexicon.h"
18 #include "indexer/params.h"
19 #include "utils/dumpconfig.h"
20 #include "lang/lang.h"
21 #include "lib/base224.h"
24 #include "images/images.h"
30 /* This should happen in gatherer or scanner */
32 generate_signatures(uns limit)
34 struct fastbuf *cards = index_bopen("cards", O_RDONLY);
35 struct fastbuf *card_attrs = index_bopen("card-attrs", O_RDONLY);
36 struct fastbuf *signatures = index_bopen("image-sig", O_CREAT | O_WRONLY | O_TRUNC);
38 struct image_signature sig;
39 struct mempool *pool = mp_new(1 << 16);
40 struct buck2obj_buf *bob = buck2obj_alloc();
43 DBG("Generating signatures");
45 for (; bread(card_attrs, &ca, sizeof(ca)); oid++)
46 if ((uns)((ca.type_flags >> 4) - 8) < 4)
48 bsetpos(cards, (sh_off_t)ca.card << CARD_POS_SHIFT);
49 uns buck_len = bgetl(cards)-(LIZARD_COMPRESS_HEADER-1);
50 uns buck_type = bgetc(cards) + BUCKET_TYPE_PLAIN;
52 struct odes *obj = obj_read_bucket(bob, pool, buck_type, buck_len, cards, NULL);
55 die("Failed to read card");
56 if (attr = obj_find_attr(obj, 'N'))
58 DBG("Reading oid=%d url=%s", oid, obj_find_aval(obj_find_attr(obj, 'U' + OBJ_ATTR_SON)->son, 'U'));
62 for (; attr; attr = attr->same)
64 uns len = strlen(attr->val);
65 bb_grow(&buf, buf_len + len);
66 memcpy(buf.ptr + buf_len, attr->val, len);
70 uns thumb_len = base224_decode(thumb, buf.ptr, buf_len);
72 int err = compute_image_signature(thumb, thumb_len, &sig);
75 bputl(signatures, oid);
76 bwrite(signatures, &sig, sizeof(sig));
81 DBG("Cannot create signature, error=%d", err);
94 static char *shortopts = CF_SHORT_OPTS "";
95 static struct option longopts[] =
101 static char *help = "\
102 Usage: image-indexer [<options>]\n\
104 Options:\n" CF_USAGE;
120 main(int argc UNUSED, char **argv)
125 while ((opt = cf_getopt(argc, argv, shortopts, longopts, NULL)) >= 0)
129 usage("Invalid option");
132 usage("Invalid usage");
134 generate_signatures(~0U);