1ascmap(1) AfterStep X11 window manager ascmap(1)
2
3
4
6 ascmap - defines main structures and function for image quantization
7 libAfterImage/ascmap.h
8
10 - Defines main structures and function for image quantization.
11
12
14 Image quantization is needed primarily in order to be able to export
15 images into file, with colormap format, such as GIF and XPM.
16 libAfterImage attempts to allocate colorcells to the most used colors,
17 and then approximate remaining colors with the closest colorcell.
18
19 Since quality of quantization is in reverse proportion to the number
20 of colors in original image, libAfterImage allows to set arbitrary
21 level of downsampling of the color spectrum in the range of 8 bit per
22 channel to 1 bit per channel. Downsampling is performed by simple
23 dropping of less significant bits off of color values.
24
25 In order to be able to determine closeness of colors, 3-channel RGB
26 values are converted into flat 24bit (or less if downsampling is used)
27 index. That is done by intermixing bits from different channels, like
28 so : R8G8B8R7G7B7...R1G1B1. That flat index is used to arrange colors
29 in ascending order, and later on to be able to find closest mapped
30 color. Simple hashing technique is used to speed up the
31 sorting/searching, as it allows to limit linked lists traversals.
32
34 Structures :
35 ASColormapEntry
36 ASColormap
37
38 Functions :
39 colormap_asimage(), destroy_colormap()
40
41 Other libAfterImage modules :
42 ascmap.h asfont.h asimage.h asvisual.h blender.h export.h
43 import.h transform.h ximage.h
44
46 Sasha Vasko <sasha at aftercode dot net>
47
49 - ASColormapEntry represents single colorcell in the colormap.
50
51
53 Source :
54 typedef struct ASColormapEntry
55 {
56 CARD8 red, green, blue;
57 }ASColormapEntry;
58
60 - ASColormap represents entire colormap generated for the image.
61
62
64 Source :
65 typedef struct ASColormap
66 {
67 ASColormapEntry *entries ; /* array of colorcells */
68 unsigned int count ; /* number of used colorcells */
69 ASSortedColorHash *hash ; /* internal data */
70 Bool has_opaque ; /* If True then Image has opaque pixels */
71 }ASColormap;
72
75 int *colormap_asimage( ASImage *im, ASColormap *cmap,
76 unsigned int max_colors, unsigned int dither,
77 int opaque_threshold );
78
80 im - pointer to valid ASImage structure.
81
82 cmap - preallocated structure to store colormap in.
83
84 max_colors
85 - maximum size of the colormap.
86
87 dither - number of bits to strip off the color data ( 0...7 )
88
89 opaque_threshold
90 - alpha channel threshold at which pixel should be treated as
91 opaque
92
93
95 pointer to the array of indexes representing pixel's colorcells. This
96 array has size of WIDTHxHEIGHT where WIDTH and HEIGHT are size of the
97 source image.
98
100 This function is all that is needed to quantize the ASImage. In order
101 to obtain colorcell of the pixel at (x,y) from result, the following
102 code could be used :
103 cmap->entries[res[y*width+x]]
104 where res is returned pointer.
105 Recommended value for dither parameter is 4 while quantizing photos to
106 256 colors, and it could be less , if original has limited number of
107 colors.
108
111 void destroy_colormap( ASColormap *cmap, Bool reusable );
112
114 cmap - pointer to valid ASColormap structure.
115
116 reusable
117 - if True, then the memory pointed to by cmap will not be deal‐
118 located, as if it was allocated on stack
119
120
122 Destroys ASColormap object created using colormap_asimage.
123
124
125
1263rd Berkeley Distribution AfterStep v.2.2.6 ascmap(1)