18#ifdef QUANT_1PASS_SUPPORTED
72#define ODITHER_SIZE 16
74#define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE)
75#define ODITHER_MASK (ODITHER_SIZE-1)
77typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
78typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
80static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
85 { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
86 { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
87 { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
88 { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
89 { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
90 { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
91 { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
92 { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
93 { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
94 { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
95 { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
96 { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
97 { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
98 { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
99 { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
100 { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
128#if BITS_IN_JSAMPLE == 8
129typedef INT16 FSERROR;
130typedef int LOCFSERROR;
132typedef INT32 FSERROR;
133typedef INT32 LOCFSERROR;
136typedef FSERROR
FAR *FSERRPTR;
157 int Ncolors[MAX_Q_COMPS];
161 ODITHER_MATRIX_PTR odither[MAX_Q_COMPS];
164 FSERRPTR fserrors[MAX_Q_COMPS];
168typedef my_cquantizer * my_cquantize_ptr;
194 int total_colors, iroot,
i,
j;
197 static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
205 for (
i = 1;
i < nc;
i++)
207 }
while (
temp <= (
long) max_colors);
216 for (
i = 0;
i < nc;
i++) {
218 total_colors *= iroot;
228 for (
i = 0;
i < nc;
i++) {
231 temp = total_colors / Ncolors[
j];
232 temp *= Ncolors[
j]+1;
233 if (
temp > (
long) max_colors)
276 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
282 total_colors = select_ncolors(cinfo, cquantize->Ncolors);
286 TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
287 total_colors, cquantize->Ncolors[0],
288 cquantize->Ncolors[1], cquantize->Ncolors[2]);
290 TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
301 blkdist = total_colors;
305 nci = cquantize->Ncolors[
i];
307 for (
j = 0;
j < nci;
j++) {
323 cquantize->sv_colormap = colormap;
324 cquantize->sv_actual = total_colors;
335 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
346 cquantize->is_padded =
TRUE;
349 cquantize->is_padded =
FALSE;
352 cquantize->colorindex = (*cinfo->mem->alloc_sarray)
358 blksize = cquantize->sv_actual;
362 nci = cquantize->Ncolors[
i];
371 indexptr = cquantize->colorindex[
i];
373 k = largest_input_value(cinfo,
i, 0, nci-1);
376 k = largest_input_value(cinfo,
i, ++
val, nci-1);
383 indexptr[-
j] = indexptr[0];
395LOCAL(ODITHER_MATRIX_PTR)
398 ODITHER_MATRIX_PTR odither;
402 odither = (ODITHER_MATRIX_PTR) (*cinfo->mem->alloc_small)
409 den = 2 * ODITHER_CELLS * ((
INT32) (ncolors - 1));
410 for (
j = 0;
j < ODITHER_SIZE;
j++) {
411 for (
k = 0;
k < ODITHER_SIZE;
k++) {
412 num = ((
INT32) (ODITHER_CELLS-1 - 2*((
int)base_dither_matrix[
j][
k])))
433 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
434 ODITHER_MATRIX_PTR odither;
438 nci = cquantize->Ncolors[
i];
440 for (
j = 0;
j <
i;
j++) {
441 if (nci == cquantize->Ncolors[
j]) {
442 odither = cquantize->odither[
j];
447 odither = make_odither_array(cinfo, nci);
448 cquantize->odither[
i] = odither;
462 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
463 JSAMPARRAY colorindex = cquantize->colorindex;
464 register int pixcode, ci;
472 ptrin = input_buf[
row];
474 for (col =
width; col > 0; col--) {
476 for (ci = 0; ci < nc; ci++) {
490 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
491 register int pixcode;
493 JSAMPROW colorindex0 = cquantize->colorindex[0];
494 JSAMPROW colorindex1 = cquantize->colorindex[1];
495 JSAMPROW colorindex2 = cquantize->colorindex[2];
501 ptrin = input_buf[
row];
503 for (col =
width; col > 0; col--) {
518 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
523 int row_index, col_index;
533 row_index = cquantize->row_index;
534 for (ci = 0; ci < nc; ci++) {
535 input_ptr = input_buf[
row] + ci;
537 colorindex_ci = cquantize->colorindex[ci];
538 dither = cquantize->odither[ci][row_index];
541 for (col =
width; col > 0; col--) {
549 *output_ptr += colorindex_ci[
GETJSAMPLE(*input_ptr)+dither[col_index]];
552 col_index = (col_index + 1) & ODITHER_MASK;
556 row_index = (row_index + 1) & ODITHER_MASK;
557 cquantize->row_index = row_index;
567 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
568 register int pixcode;
571 JSAMPROW colorindex0 = cquantize->colorindex[0];
572 JSAMPROW colorindex1 = cquantize->colorindex[1];
573 JSAMPROW colorindex2 = cquantize->colorindex[2];
577 int row_index, col_index;
583 row_index = cquantize->row_index;
584 input_ptr = input_buf[
row];
586 dither0 = cquantize->odither[0][row_index];
587 dither1 = cquantize->odither[1][row_index];
588 dither2 = cquantize->odither[2][row_index];
591 for (col =
width; col > 0; col--) {
593 dither0[col_index]]);
595 dither1[col_index]]);
597 dither2[col_index]]);
598 *output_ptr++ = (
JSAMPLE) pixcode;
599 col_index = (col_index + 1) & ODITHER_MASK;
601 row_index = (row_index + 1) & ODITHER_MASK;
602 cquantize->row_index = row_index;
612 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
613 register LOCFSERROR
cur;
618 register FSERRPTR errorptr;
637 for (ci = 0; ci < nc; ci++) {
638 input_ptr = input_buf[
row] + ci;
640 if (cquantize->on_odd_row) {
642 input_ptr += (
width-1) * nc;
643 output_ptr +=
width-1;
646 errorptr = cquantize->fserrors[ci] + (
width+1);
651 errorptr = cquantize->fserrors[ci];
653 colorindex_ci = cquantize->colorindex[ci];
654 colormap_ci = cquantize->sv_colormap[ci];
658 belowerr = bpreverr = 0;
660 for (col =
width; col > 0; col--) {
678 *output_ptr += (
JSAMPLE) pixcode;
690 errorptr[0] = (FSERROR) (bpreverr +
cur);
692 bpreverr = belowerr +
cur;
707 errorptr[0] = (FSERROR) bpreverr;
709 cquantize->on_odd_row = (cquantize->on_odd_row ?
FALSE :
TRUE);
721 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
727 cquantize->fserrors[
i] = (FSERRPTR) (*cinfo->mem->alloc_large)
740 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
745 cinfo->
colormap = cquantize->sv_colormap;
752 cquantize->pub.color_quantize = color_quantize3;
754 cquantize->pub.color_quantize = color_quantize;
758 cquantize->pub.color_quantize = quantize3_ord_dither;
760 cquantize->pub.color_quantize = quantize_ord_dither;
761 cquantize->row_index = 0;
766 if (! cquantize->is_padded)
767 create_colorindex(cinfo);
769 if (cquantize->odither[0] ==
NULL)
770 create_odither_tables(cinfo);
773 cquantize->pub.color_quantize = quantize_fs_dither;
774 cquantize->on_odd_row =
FALSE;
776 if (cquantize->fserrors[0] ==
NULL)
777 alloc_fs_workspace(cinfo);
781 FMEMZERO((
void FAR *) cquantize->fserrors[
i], arraysize);
784 ERREXIT(cinfo, JERR_NOT_COMPILED);
808 ERREXIT(cinfo, JERR_MODE_CHANGE);
819 my_cquantize_ptr cquantize;
821 cquantize = (my_cquantize_ptr) (*cinfo->mem->alloc_small)
824 cquantize->pub.start_pass = start_pass_1_quant;
825 cquantize->pub.finish_pass = finish_pass_1_quant;
826 cquantize->pub.new_color_map = new_color_map_1_quant;
827 cquantize->fserrors[0] =
NULL;
828 cquantize->odither[0] =
NULL;
832 ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
838 create_colormap(cinfo);
839 create_colorindex(cinfo);
848 alloc_fs_workspace(cinfo);
static void output_value(const WCHAR *value_name, DWORD type, BYTE *data, DWORD data_size)
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
for(i=0;i< ARRAY_SIZE(offsets);i++)
GLint GLint GLsizei width
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
#define TRACEMS1(cinfo, lvl, code, p1)
#define TRACEMS4(cinfo, lvl, code, p1, p2, p3, p4)
#define ERREXIT1(cinfo, code, p1)
#define GETJSAMPLE(value)
#define FMEMZERO(target, size)
#define RIGHT_SHIFT(x, shft)
struct jpeg_common_struct * j_common_ptr
J_COLOR_SPACE out_color_space
JSAMPLE * sample_range_limit
int actual_number_of_colors
int desired_number_of_colors
J_DITHER_MODE dither_mode
struct jpeg_color_quantizer * cquantize