10 #define JPEG_INTERNALS 15 #ifdef QUANT_1PASS_SUPPORTED 67 #define ODITHER_SIZE 16 69 #define ODITHER_CELLS (ODITHER_SIZE * ODITHER_SIZE) 70 #define ODITHER_MASK \ 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}};
123 #if BITS_IN_JSAMPLE == 8 135 #define MAX_Q_COMPS 4 187 int nc = cinfo->out_color_components;
188 int max_colors = cinfo->desired_number_of_colors;
189 int total_colors, iroot, i, j;
192 static const int RGB_order[3] = {RGB_GREEN, RGB_RED, RGB_BLUE};
201 for (i = 1; i < nc; i++) temp *= iroot;
202 }
while (temp <= (
long)max_colors);
206 if (iroot < 2)
ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (
int)temp);
210 for (i = 0; i < nc; i++)
213 total_colors *= iroot;
224 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;
277 int i, j, k, nci, blksize, blkdist, ptr,
val;
283 if (cinfo->out_color_components == 3)
285 cinfo, 1, JTRC_QUANT_3_NCOLORS, total_colors, cquantize->
Ncolors[0],
288 TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
294 colormap = (*cinfo->mem->alloc_sarray)(
301 blkdist = total_colors;
303 for (i = 0; i < cinfo->out_color_components; i++)
307 blksize = blkdist / nci;
308 for (j = 0; j < nci; j++)
314 for (ptr = j * blksize; ptr < total_colors; ptr += blkdist)
317 for (k = 0; k < blksize; k++)
340 int i, j, k, nci, blksize,
val, pad;
358 cquantize->
colorindex = (*cinfo->mem->alloc_sarray)(
365 for (i = 0; i < cinfo->out_color_components; i++)
369 blksize = blksize / nci;
391 indexptr[-j] = indexptr[0];
428 odither[j][k] = (int)(
num < 0 ? -((-
num) / den) :
num / den);
447 for (i = 0; i < cinfo->out_color_components; i++)
451 for (j = 0; j < i; j++)
453 if (nci == cquantize->
Ncolors[j])
455 odither = cquantize->
odither[j];
459 if (odither ==
nullptr)
461 cquantize->
odither[i] = odither;
482 int nc = cinfo->out_color_components;
486 ptrin = input_buf[
row];
488 for (col =
width; col > 0; col--)
491 for (ci = 0; ci < nc; ci++)
518 ptrin = input_buf[
row];
520 for (col =
width; col > 0; col--)
541 int row_index, col_index;
542 int nc = cinfo->out_color_components;
554 for (ci = 0; ci < nc; ci++)
556 input_ptr = input_buf[
row] + ci;
559 dither = cquantize->
odither[ci][row_index];
562 for (col =
width; col > 0; col--)
575 colorindex_ci[
GETJSAMPLE(*input_ptr) + dither[col_index]];
603 int row_index, col_index;
611 input_ptr = input_buf[
row];
613 dither0 = cquantize->
odither[0][row_index];
614 dither1 = cquantize->
odither[1][row_index];
615 dither2 = cquantize->
odither[2][row_index];
618 for (col =
width; col > 0; col--)
621 colorindex0[
GETJSAMPLE(*input_ptr++) + dither0[col_index]]);
623 colorindex1[
GETJSAMPLE(*input_ptr++) + dither1[col_index]]);
625 colorindex2[
GETJSAMPLE(*input_ptr++) + dither2[col_index]]);
626 *output_ptr++ = (
JSAMPLE)pixcode;
652 int nc = cinfo->out_color_components;
667 for (ci = 0; ci < nc; ci++)
669 input_ptr = input_buf[
row] + ci;
674 input_ptr += (
width - 1) * nc;
675 output_ptr +=
width - 1;
678 errorptr = cquantize->
fserrors[ci] +
695 belowerr = bpreverr = 0;
697 for (col =
width; col > 0; col--)
721 *output_ptr += (
JSAMPLE)pixcode;
733 errorptr[0] = (
FSERROR)(bpreverr + cur);
735 bpreverr = belowerr + cur;
753 errorptr[0] = (
FSERROR)bpreverr;
770 arraysize = (
size_t)((cinfo->output_width + 2) *
SIZEOF(
FSERROR));
771 for (i = 0; i < cinfo->out_color_components; i++)
792 cinfo->actual_number_of_colors = cquantize->
sv_actual;
795 switch (cinfo->dither_mode)
798 if (cinfo->out_color_components == 3)
804 if (cinfo->out_color_components == 3)
823 arraysize = (size_t)((cinfo->output_width + 2) *
SIZEOF(
FSERROR));
824 for (i = 0; i < cinfo->out_color_components; i++)
828 ERREXIT(cinfo, JERR_NOT_COMPILED);
847 ERREXIT(cinfo, JERR_MODE_CHANGE);
873 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)
for(ctr=DCTSIZE;ctr > 0;ctr--)
void 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)
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
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)
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