Debian Codegraph @

lib/imagelib.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 #include <stdio.h>
2 #include <string.h>
•3 #include <stdlib.h>
4 #include "imagelib.h"
5 #include "table.h"
6
7 static image_list *image_root = 0;
8
9 int
10 register_imagelib (image_list *images)
11 {
12 int i, j, k;
13 for (i=0; images[i].name; i++)
14 {
15 if (images[i].next)
16 continue;
17 images[i].next = image_root;
18 image_root = images+i;
19 for (j=0; j<3; j++)
20 if (images[i].subimage[j])
21 for (k=0; images[i].subimage[j][k].width; k++)
22 {
23 if (images[i].subimage[j][k+1].width)
24 images[i].subimage[j][k].next = images[i].subimage[j] + k + 1;
25 images[i].subimage[j][k].list = images+i;
26 images[i].subimage[j][k].type = j;
27 }
28 }
29 }
30
31 static int type_search[3][3] = {
32 { TABLE_MONO, TABLE_GRAY, TABLE_COLOR },
33 { TABLE_GRAY, TABLE_MONO, TABLE_COLOR },
34 { TABLE_COLOR, TABLE_GRAY, TABLE_MONO }};
35
36 #define abs(a) ((a) < 0 ? -(a) : (a))
37
38 image *
39 get_image (char *name,
40 int preferred_width,
41 int preferred_height,
42 int flags)
43 {
44 image_list *list;
45 image *img, *best;
46 int type, best_w, best_h;
47
48 for (list=image_root; list; list=list->next)
49 if (strcmp(name, list->name) == 0)
50 break;
51 if (!list)
52 {
53 printf("No image named `%s' available\n", name);
54 return 0;
55 }
56 if (list->synth_func)
57 return list->synth_func (list, table_type, preferred_width, preferred_height);
58
59 best = 0;
60 best_w = 0;
61 best_h = 0;
62 for (type = 0; type<3; type++)
63 {
64 for (img = list->subimage[type_search[table_type][type]]; img; img=img->next)
65 {
66 if (flags & GI_NOT_BIGGER)
67 {
68 if (img->width > best_w && img->width <= preferred_width
69 && img->height > best_h && img->height <= preferred_height)
70 {
71 best = img;
72 best_w = img->width;
73 best_h = img->height;
74 }
75 }
76 else
77 {
78 int diff = abs(preferred_width - img->width) + abs(preferred_height - img->height);
79 if (diff < best_w || !best)
80 {
81 best = img;
82 best_w = diff;
83 }
84 }
85 }
86 if (best && !(flags & GI_ANY_TYPE))
87 break;
88 }
89
90 return best;
91 }
92
93 void put_subimage (image *src, int col, int row,
94 image *dest, int dx, int dy, int flags)
95 {
96 int x, y, w, h;
97 if (src->list->across == 1 && src->list->down == 1)
98 col = row = 0;
99 w = src->width / src->list->across;
100 h = src->height / src->list->down;
101 x = w * col;
102 y = h * row;
103 put_image (src, x, y, w, h, dest, dx-x, dy-y, flags);
104 }
105
106 image *
107 alloc_synth_image (image_list *list, int width, int height, int type)
108 {
109 image *rv;
110 rv = (image *)malloc (sizeof(image));
111 rv->width = width;
112 rv->height = height;
113 rv->file_data = 0;
114 rv->next = list->subimage[type];
115 list->subimage[type] = rv;
116 rv->type = type;
117 rv->pixels = 0;
118 rv->list = list;
119 return rv;
120 }