10 #define JPEG_INTERNALS 15 #ifdef QUANT_1PASS_SUPPORTED 69 #define ODITHER_SIZE 16 71 #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) 72 #define ODITHER_MASK (ODITHER_SIZE-1) 82 { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
83 { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
84 { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
85 { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
86 { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
87 { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
88 { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
89 { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
90 { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
91 { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
92 { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
93 { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
94 { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
95 { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
96 { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
97 { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
125 #if BITS_IN_JSAMPLE == 8 138 #define MAX_Q_COMPS 4 189 int nc = cinfo->out_color_components;
190 int max_colors = cinfo->desired_number_of_colors;
191 int total_colors, iroot, i, j;
194 static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
202 for (i = 1; i < nc; i++)
204 }
while (temp <= (
long) max_colors);
209 ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (
int) temp);
213 for (i = 0; i < nc; i++) {
215 total_colors *= iroot;
225 for (i = 0; i < nc; i++) {
226 j = (cinfo->out_color_space ==
JCS_RGB ? RGB_order[i] : i);
228 temp = total_colors / Ncolors[j];
229 temp *= Ncolors[j]+1;
230 if (temp > (
long) max_colors)
233 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],
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++) {
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++)
337 int i,j,k, nci, blksize,
val, pad;
352 cquantize->
colorindex = (*cinfo->mem->alloc_sarray)
360 for (i = 0; i < cinfo->out_color_components; i++) {
363 blksize = blksize / nci;
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++) {
441 for (j = 0; j < i; j++) {
442 if (nci == cquantize->
Ncolors[j]) {
443 odither = cquantize->
odither[j];
449 cquantize->
odither[i] = odither;
470 int nc = cinfo->out_color_components;
475 for (col =
width; col > 0; col--) {
477 for (ci = 0; ci < nc; ci++) {
504 for (col =
width; col > 0; col--) {
524 int row_index, col_index;
525 int nc = cinfo->out_color_components;
536 for (ci = 0; ci < nc; 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]];
579 int row_index, col_index;
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;
626 int nc = cinfo->out_color_components;
633 JSAMPLE *range_limit = cinfo->sample_range_limit;
640 for (ci = 0; ci < nc; ci++) {
645 input_ptr += (
width-1) * nc;
646 output_ptr +=
width-1;
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;
728 arraysize = (
size_t) ((cinfo->output_width + 2) *
SIZEOF(
FSERROR));
729 for (i = 0; i < cinfo->out_color_components; i++) {
750 cinfo->actual_number_of_colors = cquantize->
sv_actual;
753 switch (cinfo->dither_mode) {
755 if (cinfo->out_color_components == 3)
761 if (cinfo->out_color_components == 3)
773 if (cquantize->
odither[0] == NULL)
783 arraysize = (size_t) ((cinfo->output_width + 2) *
SIZEOF(
FSERROR));
784 for (i = 0; i < cinfo->out_color_components; i++)
788 ERREXIT(cinfo, JERR_NOT_COMPILED);
813 ERREXIT(cinfo, JERR_MODE_CHANGE);
840 if (cinfo->desired_number_of_colors > (
MAXJSAMPLE+1))
select_ncolors(j_decompress_ptr cinfo, int Ncolors[])
jzero_far(void FAR *target, size_t bytestozero)
alloc_fs_workspace(j_decompress_ptr cinfo)
ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]
quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE]
jinit_1pass_quantizer(j_decompress_ptr cinfo)
quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
int(* ODITHER_MATRIX_PTR)[ODITHER_SIZE]
struct jpeg_common_struct * j_common_ptr
#define GETJSAMPLE(value)
#define ERREXIT(cinfo, code)
void BASE_IMPEXP colormap(const TColormap &color_map, const float color_index, float &r, float &g, float &b)
Transform a float number in the range [0,1] into RGB components.
make_odither_array(j_decompress_ptr cinfo, int ncolors)
start_pass_1_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
#define TRACEMS1(cinfo, lvl, code, p1)
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
largest_input_value(j_decompress_ptr cinfo, int ci, int j, int maxj)
quantize3_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
create_colormap(j_decompress_ptr cinfo)
create_odither_tables(j_decompress_ptr cinfo)
create_colorindex(j_decompress_ptr cinfo)
int JSAMPARRAY int int num_rows
new_color_map_1_quant(j_decompress_ptr cinfo)
finish_pass_1_quant(j_decompress_ptr)
color_quantize3(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
#define ERREXIT1(cinfo, code, p1)
struct jpeg_color_quantizer pub
output_value(j_decompress_ptr cinfo, int ci, int j, int maxj)
GLenum GLenum GLvoid * row
#define RIGHT_SHIFT(x, shft)
FSERRPTR fserrors[MAX_Q_COMPS]
color_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE]
#define TRACEMS4(cinfo, lvl, code, p1, p2, p3, p4)
my_cquantizer * my_cquantize_ptr