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);
296 colormap = (*cinfo->mem->alloc_sarray)
302 blkdist = total_colors;
306 nci = cquantize->Ncolors[
i];
308 for (
j = 0;
j < nci;
j++) {
324 cquantize->sv_colormap = colormap;
325 cquantize->sv_actual = total_colors;
336 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
347 cquantize->is_padded =
TRUE;
350 cquantize->is_padded =
FALSE;
353 cquantize->colorindex = (*cinfo->mem->alloc_sarray)
359 blksize = cquantize->sv_actual;
363 nci = cquantize->Ncolors[
i];
372 indexptr = cquantize->colorindex[
i];
374 k = largest_input_value(cinfo,
i, 0, nci-1);
377 k = largest_input_value(cinfo,
i, ++
val, nci-1);
384 indexptr[-
j] = indexptr[0];
396LOCAL(ODITHER_MATRIX_PTR)
399 ODITHER_MATRIX_PTR odither;
403 odither = (ODITHER_MATRIX_PTR)
411 den = 2 * ODITHER_CELLS * ((
INT32) (ncolors - 1));
412 for (
j = 0;
j < ODITHER_SIZE;
j++) {
413 for (
k = 0;
k < ODITHER_SIZE;
k++) {
414 num = ((
INT32) (ODITHER_CELLS-1 - 2*((
int)base_dither_matrix[
j][
k])))
435 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
436 ODITHER_MATRIX_PTR odither;
440 nci = cquantize->Ncolors[
i];
442 for (
j = 0;
j <
i;
j++) {
443 if (nci == cquantize->Ncolors[
j]) {
444 odither = cquantize->odither[
j];
449 odither = make_odither_array(cinfo, nci);
450 cquantize->odither[
i] = odither;
464 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
465 JSAMPARRAY colorindex = cquantize->colorindex;
466 register int pixcode, ci;
474 ptrin = input_buf[
row];
476 for (col =
width; col > 0; col--) {
478 for (ci = 0; ci < nc; ci++) {
492 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
493 register int pixcode;
495 JSAMPROW colorindex0 = cquantize->colorindex[0];
496 JSAMPROW colorindex1 = cquantize->colorindex[1];
497 JSAMPROW colorindex2 = cquantize->colorindex[2];
503 ptrin = input_buf[
row];
505 for (col =
width; col > 0; col--) {
520 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
525 int row_index, col_index;
536 row_index = cquantize->row_index;
537 for (ci = 0; ci < nc; ci++) {
538 input_ptr = input_buf[
row] + ci;
540 colorindex_ci = cquantize->colorindex[ci];
541 dither = cquantize->odither[ci][row_index];
544 for (col =
width; col > 0; col--) {
552 *output_ptr += colorindex_ci[
GETJSAMPLE(*input_ptr)+dither[col_index]];
555 col_index = (col_index + 1) & ODITHER_MASK;
559 row_index = (row_index + 1) & ODITHER_MASK;
560 cquantize->row_index = row_index;
570 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
571 register int pixcode;
574 JSAMPROW colorindex0 = cquantize->colorindex[0];
575 JSAMPROW colorindex1 = cquantize->colorindex[1];
576 JSAMPROW colorindex2 = cquantize->colorindex[2];
580 int row_index, col_index;
586 row_index = cquantize->row_index;
587 input_ptr = input_buf[
row];
589 dither0 = cquantize->odither[0][row_index];
590 dither1 = cquantize->odither[1][row_index];
591 dither2 = cquantize->odither[2][row_index];
594 for (col =
width; col > 0; col--) {
596 dither0[col_index]]);
598 dither1[col_index]]);
600 dither2[col_index]]);
601 *output_ptr++ = (
JSAMPLE) pixcode;
602 col_index = (col_index + 1) & ODITHER_MASK;
604 row_index = (row_index + 1) & ODITHER_MASK;
605 cquantize->row_index = row_index;
615 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
616 register LOCFSERROR
cur;
621 register FSERRPTR errorptr;
641 for (ci = 0; ci < nc; ci++) {
642 input_ptr = input_buf[
row] + ci;
644 if (cquantize->on_odd_row) {
646 input_ptr += (
width-1) * nc;
647 output_ptr +=
width-1;
650 errorptr = cquantize->fserrors[ci] + (
width+1);
655 errorptr = cquantize->fserrors[ci];
657 colorindex_ci = cquantize->colorindex[ci];
658 colormap_ci = cquantize->sv_colormap[ci];
662 belowerr = bpreverr = 0;
664 for (col =
width; col > 0; col--) {
682 *output_ptr += (
JSAMPLE) pixcode;
694 errorptr[0] = (FSERROR) (bpreverr +
cur);
696 bpreverr = belowerr +
cur;
711 errorptr[0] = (FSERROR) bpreverr;
713 cquantize->on_odd_row = (cquantize->on_odd_row ?
FALSE :
TRUE);
725 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
731 cquantize->fserrors[
i] = (FSERRPTR)
744 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->
cquantize;
749 cinfo->
colormap = cquantize->sv_colormap;
756 cquantize->pub.color_quantize = color_quantize3;
758 cquantize->pub.color_quantize = color_quantize;
762 cquantize->pub.color_quantize = quantize3_ord_dither;
764 cquantize->pub.color_quantize = quantize_ord_dither;
765 cquantize->row_index = 0;
770 if (! cquantize->is_padded)
771 create_colorindex(cinfo);
773 if (cquantize->odither[0] ==
NULL)
774 create_odither_tables(cinfo);
777 cquantize->pub.color_quantize = quantize_fs_dither;
778 cquantize->on_odd_row =
FALSE;
780 if (cquantize->fserrors[0] ==
NULL)
781 alloc_fs_workspace(cinfo);
785 FMEMZERO((
void FAR *) cquantize->fserrors[
i], arraysize);
788 ERREXIT(cinfo, JERR_NOT_COMPILED);
813 ERREXIT(cinfo, JERR_MODE_CHANGE);
824 my_cquantize_ptr cquantize;
826 cquantize = (my_cquantize_ptr)
830 cquantize->pub.start_pass = start_pass_1_quant;
831 cquantize->pub.finish_pass = finish_pass_1_quant;
832 cquantize->pub.new_color_map = new_color_map_1_quant;
833 cquantize->fserrors[0] =
NULL;
834 cquantize->odither[0] =
NULL;
838 ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
844 create_colormap(cinfo);
845 create_colorindex(cinfo);
854 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 *
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)
int JSAMPARRAY int int num_rows
#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