13 #define JPEG_INTERNALS 17 #ifdef QUANT_1PASS_SUPPORTED 71 #define ODITHER_SIZE 16 73 #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) 74 #define ODITHER_MASK (ODITHER_SIZE-1) 84 { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
85 { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
86 { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
87 { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
88 { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
89 { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
90 { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
91 { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
92 { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
93 { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
94 { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
95 { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
96 { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
97 { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
98 { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
99 { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
127 #if BITS_IN_JSAMPLE == 8 140 #define MAX_Q_COMPS 4 191 int nc = cinfo->out_color_components;
192 int max_colors = cinfo->desired_number_of_colors;
193 int total_colors, iroot,
i, j;
196 static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
204 for (i = 1; i < nc; i++)
206 }
while (temp <= (
long) max_colors);
211 ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (
int) temp);
215 for (i = 0; i < nc; i++) {
217 total_colors *= iroot;
227 for (i = 0; i < nc; i++) {
228 j = (cinfo->out_color_space ==
JCS_RGB ? RGB_order[
i] :
i);
230 temp = total_colors / Ncolors[j];
231 temp *= Ncolors[j]+1;
232 if (temp > (
long) max_colors)
235 total_colors = (
int) temp;
278 int i,j,k, nci, blksize, blkdist,
ptr,
val;
284 if (cinfo->out_color_components == 3)
285 TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
286 total_colors, cquantize->Ncolors[0],
287 cquantize->Ncolors[1], cquantize->Ncolors[2]);
289 TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
295 colormap = (*cinfo->mem->alloc_sarray)
301 blkdist = total_colors;
303 for (
i = 0;
i < cinfo->out_color_components;
i++) {
305 nci = cquantize->Ncolors[
i];
306 blksize = blkdist / nci;
307 for (j = 0; j < nci; j++) {
311 for (
ptr = j * blksize;
ptr < total_colors;
ptr += blkdist) {
313 for (k = 0; k < blksize; k++)
323 cquantize->sv_colormap = colormap;
324 cquantize->sv_actual = total_colors;
337 int i,j,k, nci, blksize,
val, pad;
346 cquantize->is_padded =
TRUE;
349 cquantize->is_padded =
FALSE;
352 cquantize->colorindex = (*cinfo->mem->alloc_sarray)
358 blksize = cquantize->sv_actual;
360 for (
i = 0;
i < cinfo->out_color_components;
i++) {
362 nci = cquantize->Ncolors[
i];
363 blksize = blksize / nci;
371 indexptr = cquantize->colorindex[
i];
383 indexptr[-j] = indexptr[0];
418 odither[j][k] = (
int) (
num<0 ? -((-
num)/den) :
num/den);
438 for (
i = 0;
i < cinfo->out_color_components;
i++) {
439 nci = cquantize->Ncolors[
i];
441 for (j = 0; j <
i; j++) {
442 if (nci == cquantize->Ncolors[j]) {
443 odither = cquantize->odither[j];
449 cquantize->odither[
i] = odither;
464 JSAMPARRAY colorindex = cquantize->colorindex;
465 register int pixcode, ci;
470 register int nc = cinfo->out_color_components;
473 ptrin = input_buf[
row];
475 for (col =
width; col > 0; col--) {
477 for (ci = 0; ci < nc; ci++) {
492 register int pixcode;
494 JSAMPROW colorindex0 = cquantize->colorindex[0];
495 JSAMPROW colorindex1 = cquantize->colorindex[1];
496 JSAMPROW colorindex2 = cquantize->colorindex[2];
502 ptrin = input_buf[
row];
504 for (col =
width; col > 0; col--) {
524 int row_index, col_index;
525 int nc = cinfo->out_color_components;
535 row_index = cquantize->row_index;
536 for (ci = 0; ci < nc; ci++) {
537 input_ptr = input_buf[
row] + ci;
539 colorindex_ci = cquantize->colorindex[ci];
540 dither = cquantize->odither[ci][row_index];
543 for (col =
width; col > 0; col--) {
551 *output_ptr += colorindex_ci[
GETJSAMPLE(*input_ptr)+dither[col_index]];
559 cquantize->row_index = row_index;
570 register int pixcode;
573 JSAMPROW colorindex0 = cquantize->colorindex[0];
574 JSAMPROW colorindex1 = cquantize->colorindex[1];
575 JSAMPROW colorindex2 = cquantize->colorindex[2];
579 int row_index, col_index;
585 row_index = cquantize->row_index;
586 input_ptr = input_buf[
row];
588 dither0 = cquantize->odither[0][row_index];
589 dither1 = cquantize->odither[1][row_index];
590 dither2 = cquantize->odither[2][row_index];
593 for (col =
width; col > 0; col--) {
595 dither0[col_index]]);
597 dither1[col_index]]);
599 dither2[col_index]]);
600 *output_ptr++ = (
JSAMPLE) pixcode;
604 cquantize->row_index = row_index;
626 int nc = cinfo->out_color_components;
633 JSAMPLE *range_limit = cinfo->sample_range_limit;
640 for (ci = 0; ci < nc; ci++) {
641 input_ptr = input_buf[
row] + ci;
643 if (cquantize->on_odd_row) {
645 input_ptr += (
width-1) * nc;
646 output_ptr +=
width-1;
649 errorptr = cquantize->fserrors[ci] + (
width+1);
654 errorptr = cquantize->fserrors[ci];
656 colorindex_ci = cquantize->colorindex[ci];
657 colormap_ci = cquantize->sv_colormap[ci];
661 belowerr = bpreverr = 0;
663 for (col =
width; col > 0; col--) {
681 *output_ptr += (
JSAMPLE) pixcode;
693 errorptr[0] = (
FSERROR) (bpreverr + cur);
695 bpreverr = belowerr + cur;
710 errorptr[0] = (
FSERROR) bpreverr;
712 cquantize->on_odd_row = (cquantize->on_odd_row ?
FALSE :
TRUE);
728 arraysize = (
size_t) ((cinfo->output_width + 2) *
SIZEOF(
FSERROR));
729 for (
i = 0;
i < cinfo->out_color_components;
i++) {
748 cinfo->colormap = cquantize->sv_colormap;
749 cinfo->actual_number_of_colors = cquantize->sv_actual;
752 switch (cinfo->dither_mode) {
754 if (cinfo->out_color_components == 3)
760 if (cinfo->out_color_components == 3)
764 cquantize->row_index = 0;
769 if (! cquantize->is_padded)
772 if (cquantize->odither[0] ==
NULL)
777 cquantize->on_odd_row =
FALSE;
779 if (cquantize->fserrors[0] ==
NULL)
782 arraysize = (size_t) ((cinfo->output_width + 2) *
SIZEOF(
FSERROR));
783 for (
i = 0;
i < cinfo->out_color_components;
i++)
787 ERREXIT(cinfo, JERR_NOT_COMPILED);
812 ERREXIT(cinfo, JERR_MODE_CHANGE);
832 cquantize->fserrors[0] =
NULL;
833 cquantize->odither[0] =
NULL;
839 if (cinfo->desired_number_of_colors > (
MAXJSAMPLE+1))
for(n=1;n< outline->n_points;n++)
start_pass_1_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
finish_pass_1_quant(j_decompress_ptr cinfo)
struct jpeg_common_struct * j_common_ptr
#define GETJSAMPLE(value)
GLint GLint GLsizei width
#define ERREXIT(cinfo, code)
quantize3_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
GLenum GLenum GLvoid * row
#define TRACEMS1(cinfo, lvl, code, p1)
create_odither_tables(j_decompress_ptr cinfo)
color_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
largest_input_value(j_decompress_ptr cinfo, int ci, int j, int maxj)
int JSAMPARRAY int int num_rows
quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE]
alloc_fs_workspace(j_decompress_ptr cinfo)
jzero_far(void FAR *target, size_t bytestozero)
color_quantize3(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
jinit_1pass_quantizer(j_decompress_ptr cinfo)
#define ERREXIT1(cinfo, code, p1)
if(!abbox) return FT_THROW(Invalid_Argument)
create_colorindex(j_decompress_ptr cinfo)
#define RIGHT_SHIFT(x, shft)
create_colormap(j_decompress_ptr cinfo)
my_cquantizer * my_cquantize_ptr
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
new_color_map_1_quant(j_decompress_ptr cinfo)
#define TRACEMS4(cinfo, lvl, code, p1, p2, p3, p4)
int(* ODITHER_MATRIX_PTR)[ODITHER_SIZE]
quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
select_ncolors(j_decompress_ptr cinfo, int Ncolors[])
output_value(j_decompress_ptr cinfo, int ci, int j, int maxj)
make_odither_array(j_decompress_ptr cinfo, int ncolors)