#include <stdlib.h>
+#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)
{
* (c) 2001--2002 Martin Mares <mj@ucw.cz>
*/
-/* Name of this customization (version suffix) */
-
-#define SHER_SUFFIX ""
-
/* Word types */
enum word_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