]>
git.saurik.com Git - wxWidgets.git/blob - src/gdk_imlib/colors.c
2 #include "../gdk_imlib/gdk_imlib.h"
3 #include "../gdk_imlib/gdk_imlib_private.h"
6 g_PaletteAlloc(int num
, int *cols
)
14 id
->palette
= malloc(sizeof(GdkImlibColor
) * num
);
16 free(id
->palette_orig
);
17 id
->palette_orig
= malloc(sizeof(GdkImlibColor
) * num
);
18 for (i
= 0; i
< num
; i
++)
20 r
= cols
[(i
* 3) + 0];
21 g
= cols
[(i
* 3) + 1];
22 b
= cols
[(i
* 3) + 2];
23 xcl
.red
= (unsigned short)((r
<< 8) | (r
));
24 xcl
.green
= (unsigned short)((g
<< 8) | (g
));
25 xcl
.blue
= (unsigned short)((b
<< 8) | (b
));
26 xcl
.flags
= DoRed
| DoGreen
| DoBlue
;
27 XAllocColor(id
->x
.disp
, id
->x
.root_cmap
, &xcl
);
28 id
->palette
[i
].r
= xcl
.red
>> 8;
29 id
->palette
[i
].g
= xcl
.green
>> 8;
30 id
->palette
[i
].b
= xcl
.blue
>> 8;
31 id
->palette
[i
].pixel
= xcl
.pixel
;
32 id
->palette_orig
[i
].r
= r
;
33 id
->palette_orig
[i
].g
= g
;
34 id
->palette_orig
[i
].b
= b
;
35 id
->palette_orig
[i
].pixel
= xcl
.pixel
;
41 gdk_imlib_load_colors(char *file
)
53 fprintf(stderr
, "GImLib ERROR: Cannot find palette file %s\n", file
);
57 while (fgets(s
, 256, f
))
61 sscanf(s
, "%x %x %x", &r
, &g
, &b
);
82 g_PaletteAlloc((i
/ 3), pal
);
85 id
->fast_rgb
= malloc(sizeof(int) * 32 * 32 * 32);
87 for (r
= 0; r
< 32; r
++)
89 for (g
= 0; g
< 32; g
++)
91 for (b
= 0; b
< 32; b
++)
93 rr
= (r
<< 3) | (r
>> 2);
94 gg
= (g
<< 3) | (g
>> 2);
95 bb
= (b
<< 3) | (b
>> 2);
96 INDEX_RGB(r
, g
, b
) = gindex_best_color_match(&rr
, &gg
, &bb
);
104 gdk_imlib_free_colors()
107 unsigned long pixels
[256];
109 for (i
= 0; i
< id
->num_colors
; i
++)
110 pixels
[i
] = id
->palette
[i
].pixel
;
111 XFreeColors(id
->x
.disp
, id
->x
.root_cmap
, pixels
, id
->num_colors
, 0);