]> mj.ucw.cz Git - libucw.git/blob - lib/custom.c
Merging IS branch: New customization code and its use for images.
[libucw.git] / lib / custom.c
1 /*
2  *      Sherlock: Custom Parts of Configuration
3  *
4  *      (c) 2001--2002 Martin Mares <mj@ucw.cz>
5  */
6
7 #include "lib/lib.h"
8 #include "lib/index.h"
9
10 #include <stdlib.h>
11
12 #ifdef CONFIG_IMAGES
13
14 void
15 custom_create_attrs(struct odes *odes, struct card_attr *ca)
16 {
17   byte *x;
18   uns ox, oy, tw, th, ncolors;
19   uns ifmt, isize, icol;
20   byte ocspace[10];
21   byte *ctype;
22
23   x = obj_find_aval(odes, 'G');
24   ctype = obj_find_aval(odes, 'T');
25   if (!x || !ctype || sscanf(x, "%d%d%s%d%d%d", &ox, &oy, ocspace, &ncolors, &tw, &th) != 6)
26     {
27       ca->image_flags = 0;
28       return;
29     }
30
31   if (!strcasecmp(ctype, "image/jpeg"))
32     ifmt = 1;
33   else if (!strcasecmp(ctype, "image/png"))
34     ifmt = 2;
35   else if (!strcasecmp(ctype, "image/gif"))
36     ifmt = 3;
37   else
38     {
39       log(L_ERROR, "Unknown image content-type: %s", ctype);
40       ifmt = 0;
41     }
42
43   if (ox <= 100 && oy <= 100)
44     isize = 0;
45   else if (ox <= 320 && oy <= 200)
46     isize = 1;
47   else if (ox <= 640 && oy <= 480)
48     isize = 2;
49   else
50     isize = 3;
51
52   if (!strcasecmp(ocspace, "GRAY"))
53     icol = 0;
54   else if (ncolors <= 16)
55     icol = 1;
56   else if (ncolors <= 256)
57     icol = 2;
58   else
59     icol = 3;
60
61   ca->image_flags = ifmt | (isize << 2) | (icol << 4);
62 }
63
64 byte *
65 custom_it_parse(u32 *dest, byte *value, uns intval)
66 {
67   if (value)
68     return "IMGTYPE: number expected";
69   if (intval > 3)
70     return "IMGTYPE out of range";
71   *dest = intval;
72   return NULL;
73 }
74
75 byte *
76 custom_is_parse(u32 *dest, byte *value, uns intval)
77 {
78   if (value)
79     return "IMGSIZE: number expected";
80   if (intval > 3)
81     return "IMGSIZE out of range";
82   *dest = intval;
83   return NULL;
84 }
85
86 byte *
87 custom_ic_parse(u32 *dest, byte *value, uns intval)
88 {
89   if (value)
90     return "IMGCOLORS: number expected";
91   if (intval > 3)
92     return "IMGCOLORS out of range";
93   *dest = intval;
94   return NULL;
95 }
96
97 #endif
98
99 #if 0           /* Example */
100
101 /* FIXME: The example is wrong */
102
103 void
104 custom_get_lm(struct card_attr *ca, byte *attr)
105 {
106   if (attr)
107     ca->lm = atol(attr);
108   else
109     ca->lm = 0;
110 }
111
112 byte *
113 custom_parse_lm(u32 *dest, byte *value, uns intval)
114 {
115   if (value)
116     return "LM is an integer, not a string";
117   *dest = intval;
118   return NULL;
119 }
120
121 #endif