From: Martin Mares Date: Sat, 8 Jun 2002 13:27:56 +0000 (+0000) Subject: Merging IS branch: New customization code and its use for images. X-Git-Tag: holmes-import~1400 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=0451d70e26e29d5c54e9fc5401b0744c6e6fd9c9;p=libucw.git Merging IS branch: New customization code and its use for images. --- diff --git a/lib/Makefile b/lib/Makefile index 273e3fda..c6ef7e94 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -8,9 +8,9 @@ SHLIB_OBJS=alloc.o alloc_str.o ctmatch.o db.o fastbuf.o fb-file.o fb-mem.o lists prime.o random.o realloc.o regex.o timer.o url.o wildmatch.o \ wordsplit.o str_ctype.o str_upper.o bucket.o conf.o object.o sorter.o \ finger.o proctitle.o ipaccess.o profile.o bitsig.o randomkey.o \ - hashfunc.o custom.o base224.o fb-temp.o + hashfunc.o base224.o fb-temp.o -obj/lib/libsh.a: $(addprefix obj/lib/,$(SHLIB_OBJS)) +obj/lib/libsh.a: $(addprefix obj/lib/,$(SHLIB_OBJS)) $(CUSTOM_MODULES) obj/lib/hashfunc.o: CFLAGS += -funroll-loops diff --git a/lib/config.h b/lib/config.h index c6e7c750..85d6a464 100644 --- a/lib/config.h +++ b/lib/config.h @@ -13,7 +13,7 @@ /* Version */ -#define SHER_VER "2.2a" SHER_SUFFIX +#define SHER_VER "2.2a" SHERLOCK_VERSION_SUFFIX /* Paths */ @@ -41,10 +41,6 @@ typedef unsigned int sh_time_t; /* Timestamp */ typedef u32 oid_t; /* Object ID */ -/* Custom stuff */ - -#include "lib/custom.h" - /* Data types and functions for accessing file positions */ #ifdef SHERLOCK_CONFIG_LARGE_DB diff --git a/lib/custom.c b/lib/custom.c index cba8412a..a1aec75f 100644 --- a/lib/custom.c +++ b/lib/custom.c @@ -9,8 +9,97 @@ #include +#ifdef CONFIG_IMAGES + +void +custom_create_attrs(struct odes *odes, struct card_attr *ca) +{ + byte *x; + uns ox, oy, tw, th, ncolors; + uns ifmt, isize, icol; + byte ocspace[10]; + byte *ctype; + + x = obj_find_aval(odes, 'G'); + ctype = obj_find_aval(odes, 'T'); + if (!x || !ctype || sscanf(x, "%d%d%s%d%d%d", &ox, &oy, ocspace, &ncolors, &tw, &th) != 6) + { + ca->image_flags = 0; + return; + } + + if (!strcasecmp(ctype, "image/jpeg")) + ifmt = 1; + else if (!strcasecmp(ctype, "image/png")) + ifmt = 2; + else if (!strcasecmp(ctype, "image/gif")) + ifmt = 3; + else + { + log(L_ERROR, "Unknown image content-type: %s", ctype); + ifmt = 0; + } + + if (ox <= 100 && oy <= 100) + isize = 0; + else if (ox <= 320 && oy <= 200) + isize = 1; + else if (ox <= 640 && oy <= 480) + isize = 2; + else + isize = 3; + + if (!strcasecmp(ocspace, "GRAY")) + icol = 0; + else if (ncolors <= 16) + icol = 1; + else if (ncolors <= 256) + icol = 2; + else + icol = 3; + + ca->image_flags = ifmt | (isize << 2) | (icol << 4); +} + +byte * +custom_it_parse(u32 *dest, byte *value, uns intval) +{ + if (value) + return "IMGTYPE: number expected"; + if (intval > 3) + return "IMGTYPE out of range"; + *dest = intval; + return NULL; +} + +byte * +custom_is_parse(u32 *dest, byte *value, uns intval) +{ + if (value) + return "IMGSIZE: number expected"; + if (intval > 3) + return "IMGSIZE out of range"; + *dest = intval; + return NULL; +} + +byte * +custom_ic_parse(u32 *dest, byte *value, uns intval) +{ + if (value) + return "IMGCOLORS: number expected"; + if (intval > 3) + return "IMGCOLORS out of range"; + *dest = intval; + return NULL; +} + +#endif + #if 0 /* Example */ +/* FIXME: The example is wrong */ + void custom_get_lm(struct card_attr *ca, byte *attr) { diff --git a/lib/custom.h b/lib/custom.h index d97e8dff..226d76d8 100644 --- a/lib/custom.h +++ b/lib/custom.h @@ -4,10 +4,6 @@ * (c) 2001--2002 Martin Mares */ -/* Name of this customization (version suffix) */ - -#define SHER_SUFFIX "" - /* Word types */ enum word_type { @@ -84,34 +80,79 @@ enum string_type { /* * Definitions of custom attributes: * - * INT_ATTR(type, id, oattr, keyword, get_func, parse_func) + * First of all, you need to define your own card_attr fields which will + * contain your attributes: CUSTOM_CARD_ATTRS lists them. + * Please order the attributes by decreasing size to get optimum padding. + * + * Then define custom_create_attrs() which will get the object description + * and set your card_attr fields accordingly. + * + * Finally, you have to define CUSTOM_ATTRS with matching rules: + * + * INT_ATTR(id, keyword, get_func, parse_func) -- unsigned integer attribute * - * type data type used to hold the value * id C identifier of the attribute - * oattr object attribute we get the value from * keywd search server keyword for the attribute - * void get_func(struct card_attr *ca, byte *attr) - * parse object attribute (may be NULL) + * type get_func(struct card_attr *ca, byte *attr) + * get attribute value from the card_attr * byte *parse_func(u32 *dest, byte *value, uns intval) * parse value in query (returns error message or NULL) * for KEYWD = "string", it gets value="string", intval=0 * for KEYWD = num, it gets value=NULL, intval=num. * + * SMALL_SET_ATTR(id, keyword, get_func, parse_func) + * -- integers 0..31 with set matching + * * A good place for definitions of the functions is lib/custom.c. + */ + +struct card_attr; +struct odes; + +#ifdef CONFIG_IMAGES + +/* + * We store several image properties to card_attr->image_flags and + * match them as custom attributes. The image_flags byte contains: * - * Please order the attributes by decreasing size to get optimum padding. + * bits 0--1 image format (0: not an image, 1: JPEG, 2: PNG, 3: GIF) + * bits 2--3 image size (0: <=100x100, 1: <=320x200, 2: <=640x480, 3: other) + * bits 4--5 image colors (0: grayscale, 1: <=16, 2: <=256, 3: >256) */ -#if 0 /* Example */ +#define CUSTOM_CARD_ATTRS \ + byte image_flags; -#define CUSTOM_ATTRS INT_ATTR(u32, lm, 'L', LM, custom_get_lm, custom_parse_lm) +#define CUSTOM_ATTRS \ + SMALL_SET_ATTR(ifmt, IMGTYPE, custom_it_get, custom_it_parse) \ + SMALL_SET_ATTR(isize, IMGSIZE, custom_is_get, custom_is_parse) \ + SMALL_SET_ATTR(icolors, IMGCOLORS, custom_ic_get, custom_ic_parse) -struct card_attr; -void custom_get_lm(struct card_attr *ca, byte *attr); -byte *custom_parse_lm(u32 *dest, byte *value, uns intval); +void custom_create_attrs(struct odes *odes, struct card_attr *ca); + +/* These must be macros instead of inline functions, struct card_attr is not fully defined yet */ +#define custom_it_get(ca) ((ca)->image_flags & 3) +#define custom_is_get(ca) (((ca)->image_flags >> 2) & 3) +#define custom_ic_get(ca) (((ca)->image_flags >> 4) & 3) + +byte *custom_it_parse(u32 *dest, byte *value, uns intval); +byte *custom_is_parse(u32 *dest, byte *value, uns intval); +byte *custom_ic_parse(u32 *dest, byte *value, uns intval); + +#else + +#if 0 + +/* FIXME: Add a simple example */ #else +/* No custom attributes defined */ + +#define CUSTOM_CARD_ATTRS #define CUSTOM_ATTRS +static inline void custom_create_attrs(struct odes *odes UNUSED, struct card_attr *ca UNUSED) { } + +#endif #endif diff --git a/lib/index.h b/lib/index.h index 75b3b7dc..6579fc4d 100644 --- a/lib/index.h +++ b/lib/index.h @@ -8,6 +8,7 @@ #define _SHERLOCK_INDEX_H #include "lib/fastbuf.h" +#include SHERLOCK_CUSTOM #include "charset/unistream.h" /* Words */ @@ -28,9 +29,7 @@ struct index_params { struct card_attr { u32 card; /* Reference to card description (either oid or filepos) */ u32 site_id; -#define INT_ATTR(t,i,o,k,g,p) t i; - CUSTOM_ATTRS /* Include all custom attributes */ -#undef INT_ATTR + CUSTOM_CARD_ATTRS /* Include all custom attributes */ byte weight; byte flags; byte age; /* Document age in pseudo-logarithmic units wrt. reference time */