annotate src/imgproc.c @ 5596:3b1d4fa716a4

Ignore lazy docstring info, #'built-in-symbol-file; nothing built-in uses it. 2011-11-13 Aidan Kehoe <kehoea@parhasard.net> * doc.c (Fbuilt_in_symbol_file): Don't attempt to take file information from lazy docstring information in compiled functions; those functions are not built-in, and as such it's appropriate to give nil. Fix some indentation in passing.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 13 Nov 2011 17:13:52 +0000
parents 2aa9cd456ae7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Image processing functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1998 Jareth Hein
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
5405
2aa9cd456ae7 Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5169
diff changeset
4 This file is part of XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
5405
2aa9cd456ae7 Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5169
diff changeset
6 XEmacs is free software: you can redistribute it and/or modify it
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
5405
2aa9cd456ae7 Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5169
diff changeset
8 Free Software Foundation, either version 3 of the License, or (at your
2aa9cd456ae7 Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5169
diff changeset
9 option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
5405
2aa9cd456ae7 Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5169
diff changeset
17 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 /* Synched up with: Not in FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 /* Original author: Jareth Hein */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* Parts of this file are based on code from Sam Leffler's tiff library,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 with the original copyright displayed here:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 Copyright (c) 1988-1997 Sam Leffler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 Copyright (c) 1991-1997 Silicon Graphics, Inc.
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
28 Copyright (C) 2010 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 Permission to use, copy, modify, distribute, and sell this software and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 its documentation for any purpose is hereby granted without fee, provided
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 that (i) the above copyright notices and this permission notice appear in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 all copies of the software and related documentation, and (ii) the names of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 Sam Leffler and Silicon Graphics may not be used in any advertising or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 publicity relating to the software without the specific, prior written
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 permission of Sam Leffler and Silicon Graphics. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 /* Quantizing code based off of the paper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 Color Image Quantization for Frame Buffer Display, Paul Heckbert,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 Siggraph '82 proceedings, pp. 297-307 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #include "imgproc.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 static void
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
47 get_histogram(quant_table *qt, Binbyte *pic,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 int width, int height, Colorbox* box)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
50 register Binbyte *inptr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 register int red, green, blue;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 428
diff changeset
52 register int j, i;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 box->rmin = box->gmin = box->bmin = 999;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 box->rmax = box->gmax = box->bmax = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 box->total = width * height;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 inptr = pic;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 for (i = 0; i < height; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 for (j = width; j-- > 0;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 red = *inptr++ >> COLOR_SHIFT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 green = *inptr++ >> COLOR_SHIFT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 blue = *inptr++ >> COLOR_SHIFT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 if (red < box->rmin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 box->rmin = red;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 if (red > box->rmax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 box->rmax = red;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 if (green < box->gmin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 box->gmin = green;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 if (green > box->gmax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 box->gmax = green;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 if (blue < box->bmin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 box->bmin = blue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 if (blue > box->bmax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 box->bmax = blue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 qt->histogram[red][green][blue]++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 static Colorbox *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 largest_box(quant_table *qt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 register Colorbox *p, *b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 register int size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 b = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 size = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 for (p = qt->usedboxes; p != NULL; p = p->next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 if ((p->rmax > p->rmin || p->gmax > p->gmin ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 p->bmax > p->bmin) && p->total > size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 size = (b = p)->total;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 return (b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 shrinkbox(quant_table *qt, Colorbox* box)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 register int *histp, ir, ig, ib;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 if (box->rmax > box->rmin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 for (ir = box->rmin; ir <= box->rmax; ++ir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 for (ig = box->gmin; ig <= box->gmax; ++ig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 histp = &(qt->histogram[ir][ig][box->bmin]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 for (ib = box->bmin; ib <= box->bmax; ++ib)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 if (*histp++ != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 box->rmin = ir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 goto have_rmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 have_rmin:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 if (box->rmax > box->rmin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 for (ir = box->rmax; ir >= box->rmin; --ir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 for (ig = box->gmin; ig <= box->gmax; ++ig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 histp = &(qt->histogram[ir][ig][box->bmin]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 ib = box->bmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 for (; ib <= box->bmax; ++ib)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 if (*histp++ != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 box->rmax = ir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 goto have_rmax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 have_rmax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 if (box->gmax > box->gmin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 for (ig = box->gmin; ig <= box->gmax; ++ig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 for (ir = box->rmin; ir <= box->rmax; ++ir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 histp = &(qt->histogram[ir][ig][box->bmin]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 for (ib = box->bmin; ib <= box->bmax; ++ib)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 if (*histp++ != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 box->gmin = ig;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 goto have_gmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 have_gmin:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 if (box->gmax > box->gmin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 for (ig = box->gmax; ig >= box->gmin; --ig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 for (ir = box->rmin; ir <= box->rmax; ++ir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 histp = &(qt->histogram[ir][ig][box->bmin]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 ib = box->bmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 for (; ib <= box->bmax; ++ib)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 if (*histp++ != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 box->gmax = ig;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 goto have_gmax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 have_gmax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 if (box->bmax > box->bmin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 for (ib = box->bmin; ib <= box->bmax; ++ib)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 for (ir = box->rmin; ir <= box->rmax; ++ir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 histp = &(qt->histogram[ir][box->gmin][ib]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 for (ig = box->gmin; ig <= box->gmax; ++ig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 if (*histp != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 box->bmin = ib;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 goto have_bmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 histp += B_LEN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 have_bmin:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 if (box->bmax > box->bmin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 for (ib = box->bmax; ib >= box->bmin; --ib)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 for (ir = box->rmin; ir <= box->rmax; ++ir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 histp = &(qt->histogram[ir][box->gmin][ib]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 ig = box->gmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 for (; ig <= box->gmax; ++ig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 if (*histp != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 box->bmax = ib;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 goto have_bmax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 histp += B_LEN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 have_bmax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 splitbox(quant_table *qt, Colorbox* ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 int hist2[B_LEN];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 int first = 0, last = 0;
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
204 register Colorbox *new_;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 register int *iptr, *histp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 register int i, j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 register int ir,ig,ib;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 register int sum, sum1, sum2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 enum { RED, GREEN, BLUE } axis;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 * See which axis is the largest, do a histogram along that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 * axis. Split at median point. Contract both new boxes to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 * fit points and return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 i = ptr->rmax - ptr->rmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 if (i >= ptr->gmax - ptr->gmin && i >= ptr->bmax - ptr->bmin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 axis = RED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 else if (ptr->gmax - ptr->gmin >= ptr->bmax - ptr->bmin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 axis = GREEN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 axis = BLUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 /* get histogram along longest axis */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 switch (axis)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 case RED:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 histp = &hist2[ptr->rmin];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 for (ir = ptr->rmin; ir <= ptr->rmax; ++ir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 *histp = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 for (ig = ptr->gmin; ig <= ptr->gmax; ++ig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 iptr = &(qt->histogram[ir][ig][ptr->bmin]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 for (ib = ptr->bmin; ib <= ptr->bmax; ++ib)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 *histp += *iptr++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 histp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 first = ptr->rmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 last = ptr->rmax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 case GREEN:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 histp = &hist2[ptr->gmin];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 for (ig = ptr->gmin; ig <= ptr->gmax; ++ig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 *histp = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 for (ir = ptr->rmin; ir <= ptr->rmax; ++ir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 iptr = &(qt->histogram[ir][ig][ptr->bmin]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 for (ib = ptr->bmin; ib <= ptr->bmax; ++ib)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 *histp += *iptr++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 histp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 first = ptr->gmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 last = ptr->gmax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 case BLUE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 histp = &hist2[ptr->bmin];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 for (ib = ptr->bmin; ib <= ptr->bmax; ++ib)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 *histp = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 for (ir = ptr->rmin; ir <= ptr->rmax; ++ir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 iptr = &(qt->histogram[ir][ptr->gmin][ib]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 for (ig = ptr->gmin; ig <= ptr->gmax; ++ig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 *histp += *iptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 iptr += B_LEN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 histp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 first = ptr->bmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 last = ptr->bmax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 /* find median point */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 sum2 = ptr->total / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 histp = &hist2[first];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 sum = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 for (i = first; i <= last && (sum += *histp++) < sum2; ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 if (i == first)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 /* Create new box, re-allocate points */
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
288 new_ = qt->freeboxes;
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
289 qt->freeboxes = new_->next;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 if (qt->freeboxes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 qt->freeboxes->prev = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 if (qt->usedboxes)
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
293 qt->usedboxes->prev = new_;
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
294 new_->next = qt->usedboxes;
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
295 qt->usedboxes = new_;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 histp = &hist2[first];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 for (sum1 = 0, j = first; j < i; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 sum1 += *histp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 for (sum2 = 0, j = i; j <= last; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 sum2 += *histp++;
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
302 new_->total = sum1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 ptr->total = sum2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
305 new_->rmin = ptr->rmin;
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
306 new_->rmax = ptr->rmax;
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
307 new_->gmin = ptr->gmin;
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
308 new_->gmax = ptr->gmax;
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
309 new_->bmin = ptr->bmin;
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
310 new_->bmax = ptr->bmax;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 switch (axis)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 case RED:
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
314 new_->rmax = i-1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 ptr->rmin = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 case GREEN:
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
318 new_->gmax = i-1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 ptr->gmin = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 case BLUE:
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
322 new_->bmax = i-1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 ptr->bmin = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 }
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2367
diff changeset
326 shrinkbox (qt, new_);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 shrinkbox (qt, ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 static C_cell *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 create_colorcell(quant_table *qt, int num_colors, int red, int green, int blue)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 register int ir, ig, ib, i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 register C_cell *ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 int mindist, next_n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 register int tmp, dist, n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 ir = red >> (COLOR_DEPTH-C_DEPTH);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 ig = green >> (COLOR_DEPTH-C_DEPTH);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 ib = blue >> (COLOR_DEPTH-C_DEPTH);
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
342 ptr = xnew (C_cell);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 *(qt->ColorCells + ir*C_LEN*C_LEN + ig*C_LEN + ib) = ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 ptr->num_ents = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 * Step 1: find all colors inside this cell, while we're at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 * it, find distance of centermost point to furthest corner
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 mindist = 99999999;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 for (i = 0; i < num_colors; ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 if (qt->rm[i]>>(COLOR_DEPTH-C_DEPTH) != ir ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 qt->gm[i]>>(COLOR_DEPTH-C_DEPTH) != ig ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 qt->bm[i]>>(COLOR_DEPTH-C_DEPTH) != ib)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 ptr->entries[ptr->num_ents][0] = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 ptr->entries[ptr->num_ents][1] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 ++ptr->num_ents;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 tmp = qt->rm[i] - red;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 if (tmp < (MAX_COLOR/C_LEN/2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 tmp = MAX_COLOR/C_LEN-1 - tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 dist = tmp*tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 tmp = qt->gm[i] - green;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 if (tmp < (MAX_COLOR/C_LEN/2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 tmp = MAX_COLOR/C_LEN-1 - tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 dist += tmp*tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 tmp = qt->bm[i] - blue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 if (tmp < (MAX_COLOR/C_LEN/2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 tmp = MAX_COLOR/C_LEN-1 - tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 dist += tmp*tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 if (dist < mindist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 mindist = dist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 * Step 3: find all points within that distance to cell.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 for (i = 0; i < num_colors; ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 if (qt->rm[i] >> (COLOR_DEPTH-C_DEPTH) == ir &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 qt->gm[i] >> (COLOR_DEPTH-C_DEPTH) == ig &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 qt->bm[i] >> (COLOR_DEPTH-C_DEPTH) == ib)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 dist = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 if ((tmp = red - qt->rm[i]) > 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (tmp = qt->rm[i] - (red + MAX_COLOR/C_LEN-1)) > 0 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 dist += tmp*tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 if ((tmp = green - qt->gm[i]) > 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (tmp = qt->gm[i] - (green + MAX_COLOR/C_LEN-1)) > 0 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 dist += tmp*tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 if ((tmp = blue - qt->bm[i]) > 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (tmp = qt->bm[i] - (blue + MAX_COLOR/C_LEN-1)) > 0 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 dist += tmp*tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 if (dist < mindist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 ptr->entries[ptr->num_ents][0] = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 ptr->entries[ptr->num_ents][1] = dist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 ++ptr->num_ents;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 * Sort color cells by distance, use cheap exchange sort
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 for (n = ptr->num_ents - 1; n > 0; n = next_n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 next_n = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 for (i = 0; i < n; ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 if (ptr->entries[i][1] > ptr->entries[i+1][1])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 tmp = ptr->entries[i][0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 ptr->entries[i][0] = ptr->entries[i+1][0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 ptr->entries[i+1][0] = tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 tmp = ptr->entries[i][1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 ptr->entries[i][1] = ptr->entries[i+1][1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 ptr->entries[i+1][1] = tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 next_n = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 return (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 map_colortable(quant_table *qt, int num_colors)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 register int *histp = &(qt->histogram[0][0][0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 register C_cell *cell;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 register int j, tmp, d2, dist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 int ir, ig, ib, i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 for (ir = 0; ir < B_LEN; ++ir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 for (ig = 0; ig < B_LEN; ++ig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 for (ib = 0; ib < B_LEN; ++ib, histp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 if (*histp == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 *histp = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 cell = *(qt->ColorCells +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (((ir>>(B_DEPTH-C_DEPTH)) << C_DEPTH*2) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 ((ig>>(B_DEPTH-C_DEPTH)) << C_DEPTH) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 (ib>>(B_DEPTH-C_DEPTH))));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 if (cell == NULL )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 cell = create_colorcell (qt, num_colors,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 ir << COLOR_SHIFT,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 ig << COLOR_SHIFT,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 ib << COLOR_SHIFT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 if (cell == NULL) /* memory exhausted! punt! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 dist = 9999999;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 for (i = 0; i < cell->num_ents &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 dist > cell->entries[i][1]; ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 j = cell->entries[i][0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 d2 = qt->rm[j] - (ir << COLOR_SHIFT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 d2 *= d2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 tmp = qt->gm[j] - (ig << COLOR_SHIFT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 d2 += tmp*tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 tmp = qt->bm[j] - (ib << COLOR_SHIFT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 d2 += tmp*tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 if (d2 < dist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 dist = d2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 *histp = j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 quant_table *
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
474 build_EImage_quantable(Binbyte *eimage, int width, int height, int num_colors)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 quant_table *qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 Colorbox *box_list, *ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 int i,res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 qt = (quant_table*)xmalloc_and_zero (sizeof(quant_table));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 if (qt == NULL) return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 assert (num_colors < 257 && num_colors > 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 * STEP 1: create empty boxes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 qt->usedboxes = NULL;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
488 box_list = qt->freeboxes = xnew_array (Colorbox, num_colors);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 qt->freeboxes[0].next = &(qt->freeboxes[1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 qt->freeboxes[0].prev = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 for (i = 1; i < num_colors-1; ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 qt->freeboxes[i].next = &(qt->freeboxes[i+1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 qt->freeboxes[i].prev = &(qt->freeboxes[i-1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 qt->freeboxes[num_colors-1].next = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 qt->freeboxes[num_colors-1].prev = &(qt->freeboxes[num_colors-2]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 * STEP 2: get histogram, initialize first box
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 ptr = qt->freeboxes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 qt->freeboxes = ptr->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 if (qt->freeboxes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 qt->freeboxes->prev = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 ptr->next = qt->usedboxes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 qt->usedboxes = ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 if (ptr->next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 ptr->next->prev = ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 get_histogram (qt, eimage, width, height, ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 * STEP 3: continually subdivide boxes until no more free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 * boxes remain or until all colors assigned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 while (qt->freeboxes != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 ptr = largest_box(qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 if (ptr != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 splitbox (qt, ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 qt->freeboxes = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 * STEP 4: assign colors to all boxes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 for (i = 0, ptr = qt->usedboxes; ptr != NULL; ++i, ptr = ptr->next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 qt->rm[i] = ((ptr->rmin + ptr->rmax) << COLOR_SHIFT) / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 qt->gm[i] = ((ptr->gmin + ptr->gmax) << COLOR_SHIFT) / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 qt->bm[i] = ((ptr->bmin + ptr->bmax) << COLOR_SHIFT) / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 qt->um[i] = ptr->total;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 qt->num_active_colors = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 /* We're done with the boxes now */
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
538 xfree (box_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 qt->freeboxes = qt->usedboxes = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 * STEP 5: scan histogram and map all values to closest color
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 /* 5a: create cell list as described in Heckbert */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 qt->ColorCells = (C_cell **)xmalloc_and_zero (C_LEN*C_LEN*C_LEN*sizeof (C_cell*));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 /* 5b: create mapping from truncated pixel space to color
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 table entries */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 res = map_colortable (qt, num_colors);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 /* 5c: done with ColorCells */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 for (i = 0; i < C_LEN*C_LEN*C_LEN; i++)
1726
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 647
diff changeset
552 if (qt->ColorCells[i])
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
553 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
554 xfree (qt->ColorCells[i]);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
555 qt->ColorCells[i] = 0;
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
556 }
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
557 xfree (qt->ColorCells);
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
558 qt->ColorCells = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 if (res)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 {
1726
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 647
diff changeset
562 /* we failed in memory allocation, so clean up and leave */
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
563 xfree (qt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 return qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 }