23 #define JPEG_INTERNALS
27 #ifdef QUANT_2PASS_SUPPORTED
81 #define C0_SCALE c_scales[rgb_red[cinfo->out_color_space]]
82 #define C1_SCALE c_scales[rgb_green[cinfo->out_color_space]]
83 #define C2_SCALE c_scales[rgb_blue[cinfo->out_color_space]]
109 #define MAXNUMCOLORS (MAXJSAMPLE + 1)
114 #define HIST_C0_BITS 5
115 #define HIST_C1_BITS 6
116 #define HIST_C2_BITS 5
119 #define HIST_C0_ELEMS (1 << HIST_C0_BITS)
120 #define HIST_C1_ELEMS (1 << HIST_C1_BITS)
121 #define HIST_C2_ELEMS (1 << HIST_C2_BITS)
124 #define C0_SHIFT (BITS_IN_JSAMPLE - HIST_C0_BITS)
125 #define C1_SHIFT (BITS_IN_JSAMPLE - HIST_C1_BITS)
126 #define C2_SHIFT (BITS_IN_JSAMPLE - HIST_C2_BITS)
159 #if BITS_IN_JSAMPLE == 8
216 for (col =
width; col > 0; col--) {
218 histp = &histogram[ptr[0] >>
C0_SHIFT]
258 register long maxc = 0;
261 for (
i = 0, boxp = boxlist;
i < numboxes;
i++, boxp++) {
278 register JLONG maxv = 0;
281 for (
i = 0, boxp = boxlist;
i < numboxes;
i++, boxp++) {
282 if (boxp->
volume > maxv) {
300 int c0min, c0max, c1min, c1max, c2min, c2max;
301 JLONG dist0, dist1, dist2;
304 c0min = boxp->c0min; c0max = boxp->c0max;
305 c1min = boxp->c1min; c1max = boxp->c1max;
306 c2min = boxp->c2min; c2max = boxp->c2max;
309 for (c0 = c0min; c0 <= c0max; c0++)
310 for (c1 = c1min; c1 <= c1max; c1++) {
311 histp = &histogram[c0][c1][c2min];
312 for (
c2 = c2min;
c2 <= c2max;
c2++)
314 boxp->c0min = c0min = c0;
320 for (c0 = c0max; c0 >= c0min; c0--)
321 for (c1 = c1min; c1 <= c1max; c1++) {
322 histp = &histogram[c0][c1][c2min];
323 for (
c2 = c2min;
c2 <= c2max;
c2++)
325 boxp->c0max = c0max = c0;
331 for (c1 = c1min; c1 <= c1max; c1++)
332 for (c0 = c0min; c0 <= c0max; c0++) {
333 histp = &histogram[c0][c1][c2min];
334 for (
c2 = c2min;
c2 <= c2max;
c2++)
336 boxp->c1min = c1min = c1;
342 for (c1 = c1max; c1 >= c1min; c1--)
343 for (c0 = c0min; c0 <= c0max; c0++) {
344 histp = &histogram[c0][c1][c2min];
345 for (
c2 = c2min;
c2 <= c2max;
c2++)
347 boxp->c1max = c1max = c1;
353 for (
c2 = c2min;
c2 <= c2max;
c2++)
354 for (c0 = c0min; c0 <= c0max; c0++) {
355 histp = &histogram[c0][c1min][
c2];
358 boxp->c2min = c2min =
c2;
364 for (
c2 = c2max;
c2 >= c2min;
c2--)
365 for (c0 = c0min; c0 <= c0max; c0++) {
366 histp = &histogram[c0][c1min][
c2];
369 boxp->c2max = c2max =
c2;
386 boxp->volume = dist0 * dist0 + dist1 * dist1 + dist2 * dist2;
390 for (c0 = c0min; c0 <= c0max; c0++)
391 for (c1 = c1min; c1 <= c1max; c1++) {
392 histp = &histogram[c0][c1][c2min];
393 for (
c2 = c2min;
c2 <= c2max;
c2++, histp++)
398 boxp->colorcount = ccount;
408 int c0, c1,
c2, cmax;
411 while (numboxes < desired_colors) {
415 if (numboxes * 2 <= desired_colors) {
422 b2 = &boxlist[numboxes];
436 if (rgb_red[cinfo->out_color_space] == 0) {
438 if (c0 > cmax) { cmax = c0;
n = 0; }
439 if (
c2 > cmax) {
n = 2; }
442 if (
c2 > cmax) { cmax =
c2;
n = 2; }
443 if (c0 > cmax) {
n = 0; }
487 int c0min, c0max, c1min, c1max, c2min, c2max;
494 c0min = boxp->c0min; c0max = boxp->c0max;
495 c1min = boxp->c1min; c1max = boxp->c1max;
496 c2min = boxp->c2min; c2max = boxp->c2max;
498 for (c0 = c0min; c0 <= c0max; c0++)
499 for (c1 = c1min; c1 <= c1max; c1++) {
500 histp = &histogram[c0][c1][c2min];
501 for (
c2 = c2min;
c2 <= c2max;
c2++) {
502 if ((
count = *histp++) != 0) {
511 cinfo->colormap[0][icolor] = (JSAMPLE)((c0total + (total >> 1)) / total);
512 cinfo->colormap[1][icolor] = (JSAMPLE)((c1total + (total >> 1)) / total);
513 cinfo->colormap[2][icolor] = (JSAMPLE)((c2total + (total >> 1)) / total);
526 boxlist = (
boxptr)(*cinfo->mem->alloc_small)
530 boxlist[0].
c0min = 0;
532 boxlist[0].
c1min = 0;
534 boxlist[0].
c2min = 0;
539 numboxes =
median_cut(cinfo, boxlist, numboxes, desired_colors);
541 for (
i = 0;
i < numboxes;
i++)
543 cinfo->actual_number_of_colors = numboxes;
544 TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
603 #define BOX_C0_LOG (HIST_C0_BITS - 3)
604 #define BOX_C1_LOG (HIST_C1_BITS - 3)
605 #define BOX_C2_LOG (HIST_C2_BITS - 3)
607 #define BOX_C0_ELEMS (1 << BOX_C0_LOG)
608 #define BOX_C1_ELEMS (1 << BOX_C1_LOG)
609 #define BOX_C2_ELEMS (1 << BOX_C2_LOG)
611 #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
612 #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
613 #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
636 int numcolors = cinfo->actual_number_of_colors;
637 int maxc0, maxc1, maxc2;
638 int centerc0, centerc1, centerc2;
640 JLONG minmaxdist, min_dist, max_dist, tdist;
650 centerc0 = (minc0 + maxc0) >> 1;
652 centerc1 = (minc1 + maxc1) >> 1;
654 centerc2 = (minc2 + maxc2) >> 1;
664 minmaxdist = 0x7FFFFFFFL;
666 for (
i = 0;
i < numcolors;
i++) {
668 x = cinfo->colormap[0][
i];
671 min_dist = tdist * tdist;
673 max_dist = tdist * tdist;
674 }
else if (
x > maxc0) {
676 min_dist = tdist * tdist;
678 max_dist = tdist * tdist;
684 max_dist = tdist * tdist;
687 max_dist = tdist * tdist;
691 x = cinfo->colormap[1][
i];
694 min_dist += tdist * tdist;
696 max_dist += tdist * tdist;
697 }
else if (
x > maxc1) {
699 min_dist += tdist * tdist;
701 max_dist += tdist * tdist;
706 max_dist += tdist * tdist;
709 max_dist += tdist * tdist;
713 x = cinfo->colormap[2][
i];
716 min_dist += tdist * tdist;
718 max_dist += tdist * tdist;
719 }
else if (
x > maxc2) {
721 min_dist += tdist * tdist;
723 max_dist += tdist * tdist;
728 max_dist += tdist * tdist;
731 max_dist += tdist * tdist;
735 mindist[
i] = min_dist;
736 if (max_dist < minmaxdist)
737 minmaxdist = max_dist;
745 for (
i = 0;
i < numcolors;
i++) {
746 if (mindist[
i] <= minmaxdist)
747 colorlist[ncolors++] = (JSAMPLE)
i;
755 int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
765 register JLONG *bptr;
768 register JLONG dist2;
771 JLONG inc0, inc1, inc2;
778 *bptr++ = 0x7FFFFFFFL;
786 #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
787 #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
788 #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
790 for (
i = 0;
i < numcolors;
i++) {
791 icolor = colorlist[
i];
793 inc0 = (minc0 - cinfo->colormap[0][icolor]) *
C0_SCALE;
795 inc1 = (minc1 - cinfo->colormap[1][icolor]) *
C1_SCALE;
796 dist0 += inc1 * inc1;
797 inc2 = (minc2 - cinfo->colormap[2][icolor]) *
C2_SCALE;
798 dist0 += inc2 * inc2;
816 *cptr = (JSAMPLE)icolor;
841 int minc0, minc1, minc2;
843 register JSAMPLE *cptr;
880 cachep = &histogram[c0 + ic0][c1 + ic1][
c2];
882 *cachep++ = (
histcell)((*cptr++) + 1);
902 register int c0, c1,
c2;
910 for (col =
width; col > 0; col--) {
915 cachep = &histogram[c0][c1][
c2];
921 *outptr++ = (JSAMPLE)(*cachep - 1);
946 JSAMPLE *range_limit = cinfo->sample_range_limit;
948 JSAMPROW colormap0 = cinfo->colormap[0];
949 JSAMPROW colormap1 = cinfo->colormap[1];
950 JSAMPROW colormap2 = cinfo->colormap[2];
958 inptr += (
width - 1) * 3;
972 cur0 = cur1 = cur2 = 0;
974 belowerr0 = belowerr1 = belowerr2 = 0;
975 bpreverr0 = bpreverr1 = bpreverr2 = 0;
977 for (col =
width; col > 0; col--) {
986 cur0 =
RIGHT_SHIFT(cur0 + errorptr[dir3 + 0] + 8, 4);
987 cur1 =
RIGHT_SHIFT(cur1 + errorptr[dir3 + 1] + 8, 4);
988 cur2 =
RIGHT_SHIFT(cur2 + errorptr[dir3 + 2] + 8, 4);
992 cur0 = error_limit[cur0];
993 cur1 = error_limit[cur1];
994 cur2 = error_limit[cur2];
1002 cur0 = range_limit[cur0];
1003 cur1 = range_limit[cur1];
1004 cur2 = range_limit[cur2];
1015 register int pixcode = *cachep - 1;
1016 *outptr = (JSAMPLE)pixcode;
1018 cur0 -= colormap0[pixcode];
1019 cur1 -= colormap1[pixcode];
1020 cur2 -= colormap2[pixcode];
1030 errorptr[0] = (
FSERROR)(bpreverr0 + cur0 * 3);
1031 bpreverr0 = belowerr0 + cur0 * 5;
1032 belowerr0 = bnexterr;
1035 errorptr[1] = (
FSERROR)(bpreverr1 + cur1 * 3);
1036 bpreverr1 = belowerr1 + cur1 * 5;
1037 belowerr1 = bnexterr;
1040 errorptr[2] = (
FSERROR)(bpreverr2 + cur2 * 3);
1041 bpreverr2 = belowerr2 + cur2 * 5;
1042 belowerr2 = bnexterr;
1057 errorptr[0] = (
FSERROR)bpreverr0;
1058 errorptr[1] = (
FSERROR)bpreverr1;
1059 errorptr[2] = (
FSERROR)bpreverr2;
1089 table = (
int *)(*cinfo->mem->alloc_small)
1091 table += MAXJSAMPLE;
1094 #define STEPSIZE ((MAXJSAMPLE + 1) / 16)
1105 for (;
in <= MAXJSAMPLE;
in++) {
1166 i = cinfo->actual_number_of_colors;
1168 ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
1174 (size_t)((cinfo->output_width + 2) * (3 *
sizeof(
FSERROR)));
1233 if (cinfo->out_color_components != 3)
1250 if (cinfo->enable_2pass_quant) {
1252 int desired = cinfo->desired_number_of_colors;
1255 ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
1259 cquantize->
sv_colormap = (*cinfo->mem->alloc_sarray)
1279 (
size_t)((cinfo->output_width + 2) * (3 *
sizeof(
FSERROR))));
small capitals from c petite p scientific i
[1]
for(n=0;n< outline->n_points;n++)
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
#define ERREXIT(cinfo, code)
#define TRACEMS1(cinfo, lvl, code, p1)
#define ERREXIT1(cinfo, code, p1)
int JSAMPARRAY int int num_rows
#define RIGHT_SHIFT(x, shft)
struct jpeg_common_struct * j_common_ptr
find_biggest_volume(boxptr boxlist, int numboxes)
new_color_map_2_quant(j_decompress_ptr cinfo)
start_pass_2_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
update_box(j_decompress_ptr cinfo, boxptr boxp)
my_cquantizer * my_cquantize_ptr
compute_color(j_decompress_ptr cinfo, boxptr boxp, int icolor)
init_error_limit(j_decompress_ptr cinfo)
find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2, JSAMPLE colorlist[])
finish_pass2(j_decompress_ptr cinfo)
pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
finish_pass1(j_decompress_ptr cinfo)
prescan_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
jinit_2pass_quantizer(j_decompress_ptr cinfo)
pass2_no_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2, int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
histcell hist1d[HIST_C2_ELEMS]
fill_inverse_cmap(j_decompress_ptr cinfo, int c0, int c1, int c2)
select_colors(j_decompress_ptr cinfo, int desired_colors)
median_cut(j_decompress_ptr cinfo, boxptr boxlist, int numboxes, int desired_colors)
find_biggest_color_pop(boxptr boxlist, int numboxes)
jzero_far(void *target, size_t bytestozero)
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
[3]
GLint GLint GLint GLint GLint x
[0]
GLenum GLenum GLsizei count
GLsizei const GLint * box
GLenum GLenum GLsizei void * row
GLenum GLenum GLsizei void * table
QTextStream out(stdout)
[7]
void(* start_pass)(j_decompress_ptr cinfo, boolean is_pre_scan)
void(* new_color_map)(j_decompress_ptr cinfo)
void(* color_quantize)(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
void(* finish_pass)(j_decompress_ptr cinfo)
FSERRPTR fserrors[MAX_Q_COMPS]
struct jpeg_color_quantizer pub