24#ifdef QUANT_2PASS_SUPPORTED
85#define C0_SCALE R_SCALE
88#define C0_SCALE B_SCALE
91#define C1_SCALE G_SCALE
94#define C2_SCALE R_SCALE
97#define C2_SCALE B_SCALE
127#define MAXNUMCOLORS (MAXJSAMPLE+1)
132#define HIST_C0_BITS 5
133#define HIST_C1_BITS 6
134#define HIST_C2_BITS 5
137#define HIST_C0_ELEMS (1<<HIST_C0_BITS)
138#define HIST_C1_ELEMS (1<<HIST_C1_BITS)
139#define HIST_C2_ELEMS (1<<HIST_C2_BITS)
142#define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
143#define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
144#define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
180#if BITS_IN_JSAMPLE == 8
235 for (row = 0; row <
num_rows; row++) {
236 ptr = input_buf[row];
237 for (col =
width; col > 0; col--) {
282 for (
i = 0, boxp = boxlist;
i < numboxes;
i++, boxp++) {
302 for (
i = 0, boxp = boxlist;
i < numboxes;
i++, boxp++) {
303 if (boxp->
volume > maxv) {
321 int c0min,c0max,c1min,c1max,c2min,c2max;
322 INT32 dist0,dist1,dist2;
325 c0min = boxp->c0min; c0max = boxp->c0max;
326 c1min = boxp->c1min; c1max = boxp->c1max;
327 c2min = boxp->c2min; c2max = boxp->c2max;
330 for (c0 = c0min; c0 <= c0max; c0++)
331 for (c1 = c1min; c1 <= c1max; c1++) {
332 histp = & histogram[c0][c1][c2min];
333 for (
c2 = c2min;
c2 <= c2max;
c2++)
335 boxp->c0min = c0min = c0;
341 for (c0 = c0max; c0 >= c0min; c0--)
342 for (c1 = c1min; c1 <= c1max; c1++) {
343 histp = & histogram[c0][c1][c2min];
344 for (
c2 = c2min;
c2 <= c2max;
c2++)
346 boxp->c0max = c0max = c0;
352 for (c1 = c1min; c1 <= c1max; c1++)
353 for (c0 = c0min; c0 <= c0max; c0++) {
354 histp = & histogram[c0][c1][c2min];
355 for (
c2 = c2min;
c2 <= c2max;
c2++)
357 boxp->c1min = c1min = c1;
363 for (c1 = c1max; c1 >= c1min; c1--)
364 for (c0 = c0min; c0 <= c0max; c0++) {
365 histp = & histogram[c0][c1][c2min];
366 for (
c2 = c2min;
c2 <= c2max;
c2++)
368 boxp->c1max = c1max = c1;
374 for (
c2 = c2min;
c2 <= c2max;
c2++)
375 for (c0 = c0min; c0 <= c0max; c0++) {
376 histp = & histogram[c0][c1min][
c2];
379 boxp->c2min = c2min =
c2;
385 for (
c2 = c2max;
c2 >= c2min;
c2--)
386 for (c0 = c0min; c0 <= c0max; c0++) {
387 histp = & histogram[c0][c1min][
c2];
390 boxp->c2max = c2max =
c2;
407 boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
411 for (c0 = c0min; c0 <= c0max; c0++)
412 for (c1 = c1min; c1 <= c1max; c1++) {
413 histp = & histogram[c0][c1][c2min];
414 for (
c2 = c2min;
c2 <= c2max;
c2++, histp++)
419 boxp->colorcount = ccount;
432 while (numboxes < desired_colors) {
436 if (numboxes*2 <= desired_colors) {
443 b2 = &boxlist[numboxes];
459 if (c0 > cmax) { cmax = c0;
n = 0; }
460 if (
c2 > cmax) {
n = 2; }
463 if (
c2 > cmax) { cmax =
c2;
n = 2; }
464 if (c0 > cmax) {
n = 0; }
508 int c0min,c0max,c1min,c1max,c2min,c2max;
515 c0min = boxp->c0min; c0max = boxp->c0max;
516 c1min = boxp->c1min; c1max = boxp->c1max;
517 c2min = boxp->c2min; c2max = boxp->c2max;
519 for (c0 = c0min; c0 <= c0max; c0++)
520 for (c1 = c1min; c1 <= c1max; c1++) {
521 histp = & histogram[c0][c1][c2min];
522 for (
c2 = c2min;
c2 <= c2max;
c2++) {
523 if ((
count = *histp++) != 0) {
532 cinfo->colormap[0][icolor] = (
JSAMPLE) ((c0total + (total>>1)) / total);
533 cinfo->colormap[1][icolor] = (
JSAMPLE) ((c1total + (total>>1)) / total);
534 cinfo->colormap[2][icolor] = (
JSAMPLE) ((c2total + (total>>1)) / total);
547 boxlist = (
boxptr) (*cinfo->mem->alloc_small)
551 boxlist[0].
c0min = 0;
553 boxlist[0].
c1min = 0;
555 boxlist[0].
c2min = 0;
560 numboxes =
median_cut(cinfo, boxlist, numboxes, desired_colors);
562 for (
i = 0;
i < numboxes;
i++)
564 cinfo->actual_number_of_colors = numboxes;
565 TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
624#define BOX_C0_LOG (HIST_C0_BITS-3)
625#define BOX_C1_LOG (HIST_C1_BITS-3)
626#define BOX_C2_LOG (HIST_C2_BITS-3)
628#define BOX_C0_ELEMS (1<<BOX_C0_LOG)
629#define BOX_C1_ELEMS (1<<BOX_C1_LOG)
630#define BOX_C2_ELEMS (1<<BOX_C2_LOG)
632#define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
633#define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
634#define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
657 int numcolors = cinfo->actual_number_of_colors;
658 int maxc0, maxc1, maxc2;
659 int centerc0, centerc1, centerc2;
661 INT32 minmaxdist, min_dist, max_dist, tdist;
671 centerc0 = (minc0 + maxc0) >> 1;
673 centerc1 = (minc1 + maxc1) >> 1;
675 centerc2 = (minc2 + maxc2) >> 1;
685 minmaxdist = 0x7FFFFFFFL;
687 for (
i = 0;
i < numcolors;
i++) {
692 min_dist = tdist*tdist;
694 max_dist = tdist*tdist;
695 }
else if (
x > maxc0) {
697 min_dist = tdist*tdist;
699 max_dist = tdist*tdist;
705 max_dist = tdist*tdist;
708 max_dist = tdist*tdist;
715 min_dist += tdist*tdist;
717 max_dist += tdist*tdist;
718 }
else if (
x > maxc1) {
720 min_dist += tdist*tdist;
722 max_dist += tdist*tdist;
727 max_dist += tdist*tdist;
730 max_dist += tdist*tdist;
737 min_dist += tdist*tdist;
739 max_dist += tdist*tdist;
740 }
else if (
x > maxc2) {
742 min_dist += tdist*tdist;
744 max_dist += tdist*tdist;
749 max_dist += tdist*tdist;
752 max_dist += tdist*tdist;
756 mindist[
i] = min_dist;
757 if (max_dist < minmaxdist)
758 minmaxdist = max_dist;
766 for (
i = 0;
i < numcolors;
i++) {
767 if (mindist[
i] <= minmaxdist)
792 INT32 inc0, inc1, inc2;
799 *bptr++ = 0x7FFFFFFFL;
807#define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
808#define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
809#define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
811 for (
i = 0;
i < numcolors;
i++) {
862 int minc0, minc1, minc2;
901 cachep = & histogram[c0+ic0][c1+ic1][
c2];
928 for (row = 0; row <
num_rows; row++) {
929 inptr = input_buf[row];
931 for (col =
width; col > 0; col--) {
936 cachep = & histogram[c0][c1][
c2];
942 *outptr++ = (
JSAMPLE) (*cachep - 1);
967 JSAMPLE *range_limit = cinfo->sample_range_limit;
969 JSAMPROW colormap0 = cinfo->colormap[0];
970 JSAMPROW colormap1 = cinfo->colormap[1];
971 JSAMPROW colormap2 = cinfo->colormap[2];
974 for (row = 0; row <
num_rows; row++) {
975 inptr = input_buf[row];
993 cur0 = cur1 = cur2 = 0;
995 belowerr0 = belowerr1 = belowerr2 = 0;
996 bpreverr0 = bpreverr1 = bpreverr2 = 0;
998 for (col =
width; col > 0; col--) {
1007 cur0 =
RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
1008 cur1 =
RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
1009 cur2 =
RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
1013 cur0 = error_limit[cur0];
1014 cur1 = error_limit[cur1];
1015 cur2 = error_limit[cur2];
1033 {
int pixcode = *cachep - 1;
1049 errorptr[0] = (
FSERROR) (bpreverr0 + cur0);
1051 bpreverr0 = belowerr0 + cur0;
1052 belowerr0 = bnexterr;
1057 errorptr[1] = (
FSERROR) (bpreverr1 + cur1);
1059 bpreverr1 = belowerr1 + cur1;
1060 belowerr1 = bnexterr;
1065 errorptr[2] = (
FSERROR) (bpreverr2 + cur2);
1067 bpreverr2 = belowerr2 + cur2;
1068 belowerr2 = bnexterr;
1083 errorptr[0] = (
FSERROR) bpreverr0;
1084 errorptr[1] = (
FSERROR) bpreverr1;
1085 errorptr[2] = (
FSERROR) bpreverr2;
1115 table = (
int *) (*cinfo->mem->alloc_small)
1120#define STEPSIZE ((MAXJSAMPLE+1)/16)
1192 i = cinfo->actual_number_of_colors;
1194 ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
1199 size_t arraysize = (size_t) ((cinfo->output_width + 2) *
1216 for (i = 0; i < HIST_C0_ELEMS; i++) {
1217 jzero_far((void FAR *) histogram[i],
1218 HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
1259 if (cinfo->out_color_components != 3)
1276 if (cinfo->enable_2pass_quant) {
1278 int desired = cinfo->desired_number_of_colors;
1281 ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
1283 if (desired > MAXNUMCOLORS)
1284 ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
1285 cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
1286 ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
1287 cquantize->desired = desired;
1302 cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
1303 ((j_common_ptr) cinfo, JPOOL_IMAGE,
1304 (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
1306 init_error_limit(cinfo);
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
static void c2(register WDL_FFT_COMPLEX *a)
Definition fft.c:270
static int width
Definition pugl.h:1593
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition jdct.h:106
#define ERREXIT(cinfo, code)
Definition jerror.h:205
#define TRACEMS1(cinfo, lvl, code, p1)
Definition jerror.h:255
#define ERREXIT1(cinfo, code, p1)
Definition jerror.h:208
#define SIZEOF(object)
Definition jinclude.h:83
unsigned int JDIMENSION
Definition jmorecfg.h:171
long INT32
Definition jmorecfg.h:161
#define MAXJSAMPLE
Definition jmorecfg.h:73
char JSAMPLE
Definition jmorecfg.h:64
short INT16
Definition jmorecfg.h:155
unsigned int UINT16
Definition jmorecfg.h:149
#define LOCAL(type)
Definition jmorecfg.h:186
#define METHODDEF(type)
Definition jmorecfg.h:184
#define GETJSAMPLE(value)
Definition jmorecfg.h:68
#define SHIFT_TEMPS
Definition jpegint.h:289
int JSAMPARRAY int int num_rows
Definition jpegint.h:375
#define RIGHT_SHIFT(x, shft)
Definition jpegint.h:290
struct jpeg_decompress_struct * j_decompress_ptr
Definition jpeglib.h:263
struct jpeg_common_struct * j_common_ptr
Definition jpeglib.h:261
@ JDITHER_NONE
Definition jpeglib.h:233
@ JDITHER_FS
Definition jpeglib.h:235
JSAMPROW * JSAMPARRAY
Definition jpeglib.h:67
JSAMPLE FAR * JSAMPROW
Definition jpeglib.h:66
#define JPOOL_IMAGE
Definition jpeglib.h:749
FSERROR FAR * FSERRPTR
Definition jquant1.c:135
int LOCFSERROR
Definition jquant1.c:129
INT16 FSERROR
Definition jquant1.c:128
#define HIST_C0_ELEMS
Definition jquant2.c:137
find_biggest_volume(boxptr boxlist, int numboxes)
Definition jquant2.c:293
new_color_map_2_quant(j_decompress_ptr cinfo)
Definition jquant2.c:1230
#define BOX_C1_ELEMS
Definition jquant2.c:629
box * boxptr
Definition jquant2.c:269
#define BOX_C1_LOG
Definition jquant2.c:625
prescan_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY, int num_rows)
Definition jquant2.c:224
start_pass_2_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
Definition jquant2.c:1167
#define C2_SCALE
Definition jquant2.c:97
update_box(j_decompress_ptr cinfo, boxptr boxp)
Definition jquant2.c:313
compute_color(j_decompress_ptr cinfo, boxptr boxp, int icolor)
Definition jquant2.c:499
#define BOX_C0_LOG
Definition jquant2.c:624
#define BOX_C0_SHIFT
Definition jquant2.c:632
init_error_limit(j_decompress_ptr cinfo)
Definition jquant2.c:1108
find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2, JSAMPLE colorlist[])
Definition jquant2.c:646
#define BOX_C0_ELEMS
Definition jquant2.c:628
#define BOX_C2_ELEMS
Definition jquant2.c:630
#define MAXNUMCOLORS
Definition jquant2.c:127
histcell FAR * histptr
Definition jquant2.c:149
#define C1_SCALE
Definition jquant2.c:91
#define BOX_C2_LOG
Definition jquant2.c:626
pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
Definition jquant2.c:949
#define C0_SCALE
Definition jquant2.c:85
FSERROR FAR * FSERRPTR
Definition jquant2.c:188
#define HIST_C2_ELEMS
Definition jquant2.c:139
my_cquantizer2 * my_cquantize_ptr2
Definition jquant2.c:211
finish_pass1(j_decompress_ptr cinfo)
Definition jquant2.c:1143
#define BOX_C2_SHIFT
Definition jquant2.c:634
#define C1_SHIFT
Definition jquant2.c:143
jinit_2pass_quantizer(j_decompress_ptr cinfo)
Definition jquant2.c:1244
#define C2_SHIFT
Definition jquant2.c:144
#define C0_SHIFT
Definition jquant2.c:142
pass2_no_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
Definition jquant2.c:915
#define HIST_C1_ELEMS
Definition jquant2.c:138
hist1d FAR * hist2d
Definition jquant2.c:152
finish_pass2(j_decompress_ptr)
Definition jquant2.c:1156
find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2, int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
Definition jquant2.c:775
hist2d * hist3d
Definition jquant2.c:153
histcell hist1d[HIST_C2_ELEMS]
Definition jquant2.c:151
#define BOX_C1_SHIFT
Definition jquant2.c:633
fill_inverse_cmap(j_decompress_ptr cinfo, int c0, int c1, int c2)
Definition jquant2.c:855
UINT16 histcell
Definition jquant2.c:147
select_colors(j_decompress_ptr cinfo, int desired_colors)
Definition jquant2.c:539
median_cut(j_decompress_ptr cinfo, boxptr boxlist, int numboxes, int desired_colors)
Definition jquant2.c:424
find_biggest_color_pop(boxptr boxlist, int numboxes)
Definition jquant2.c:273
jzero_far(void FAR *target, size_t bytestozero)
Definition jutils.c:165
float in
Definition lilv_test.c:1460
float out
Definition lilv_test.c:1461
int c2max
Definition jquant2.c:262
int c1max
Definition jquant2.c:261
int c2min
Definition jquant2.c:262
int c1min
Definition jquant2.c:261
int c0max
Definition jquant2.c:260
INT32 volume
Definition jquant2.c:264
int c0min
Definition jquant2.c:260
long colorcount
Definition jquant2.c:266
int * error_limiter
Definition jquant2.c:208
boolean needs_zeroed
Definition jquant2.c:203
JSAMPARRAY sv_colormap
Definition jquant2.c:197
int desired
Definition jquant2.c:198
struct jpeg_color_quantizer pub
Definition jquant2.c:194
hist3d histogram
Definition jquant2.c:201
boolean on_odd_row
Definition jquant2.c:207
FSERRPTR fserrors
Definition jquant2.c:206
int n
Definition crypt.c:458
#define GLOBAL(g)
Definition crypt.c:87
if(GLOBAL(newzip))
Definition crypt.c:475
G inptr
Definition fileio.c:766
#define TRUE
Definition unzpriv.h:1295
#define FALSE
Definition unzpriv.h:1298
_WDL_CSTRING_PREFIX void INT_PTR count
Definition wdlcstring.h:263
#define FAR
Definition zconf.h:270