00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #define JPEG_INTERNALS
00014 #include "jinclude.h"
00015 #include "jpeglib.h"
00016
00017 #ifdef QUANT_1PASS_SUPPORTED
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #define ODITHER_SIZE 16
00072
00073 #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE)
00074 #define ODITHER_MASK (ODITHER_SIZE-1)
00075
00076 typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
00077 typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
00078
00079 static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
00080
00081
00082
00083
00084 { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
00085 { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
00086 { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
00087 { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
00088 { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
00089 { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
00090 { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
00091 { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
00092 { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
00093 { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
00094 { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
00095 { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
00096 { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
00097 { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
00098 { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
00099 { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
00100 };
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 #if BITS_IN_JSAMPLE == 8
00128 typedef INT16 FSERROR;
00129 typedef int LOCFSERROR;
00130 #else
00131 typedef INT32 FSERROR;
00132 typedef INT32 LOCFSERROR;
00133 #endif
00134
00135 typedef FSERROR FAR *FSERRPTR;
00136
00137
00138
00139
00140 #define MAX_Q_COMPS 4
00141
00142 typedef struct {
00143 struct jpeg_color_quantizer pub;
00144
00145
00146 JSAMPARRAY sv_colormap;
00147 int sv_actual;
00148
00149 JSAMPARRAY colorindex;
00150
00151
00152
00153
00154 boolean is_padded;
00155
00156 int Ncolors[MAX_Q_COMPS];
00157
00158
00159 int row_index;
00160 ODITHER_MATRIX_PTR odither[MAX_Q_COMPS];
00161
00162
00163 FSERRPTR fserrors[MAX_Q_COMPS];
00164 boolean on_odd_row;
00165 } my_cquantizer;
00166
00167 typedef my_cquantizer * my_cquantize_ptr;
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 LOCAL(int)
00186 select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
00187
00188
00189
00190 {
00191 int nc = cinfo->out_color_components;
00192 int max_colors = cinfo->desired_number_of_colors;
00193 int total_colors, iroot, i, j;
00194 boolean changed;
00195 long temp;
00196 static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
00197
00198
00199
00200 iroot = 1;
00201 do {
00202 iroot++;
00203 temp = iroot;
00204 for (i = 1; i < nc; i++)
00205 temp *= iroot;
00206 } while (temp <= (long) max_colors);
00207 iroot--;
00208
00209
00210 if (iroot < 2)
00211 ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
00212
00213
00214 total_colors = 1;
00215 for (i = 0; i < nc; i++) {
00216 Ncolors[i] = iroot;
00217 total_colors *= iroot;
00218 }
00219
00220
00221
00222
00223
00224
00225 do {
00226 changed = FALSE;
00227 for (i = 0; i < nc; i++) {
00228 j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
00229
00230 temp = total_colors / Ncolors[j];
00231 temp *= Ncolors[j]+1;
00232 if (temp > (long) max_colors)
00233 break;
00234 Ncolors[j]++;
00235 total_colors = (int) temp;
00236 changed = TRUE;
00237 }
00238 } while (changed);
00239
00240 return total_colors;
00241 }
00242
00243
00244 LOCAL(int)
00245 output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
00246
00247
00248 {
00249
00250
00251
00252
00253
00254 return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
00255 }
00256
00257
00258 LOCAL(int)
00259 largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
00260
00261
00262 {
00263
00264 return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
00265 }
00266
00267
00268
00269
00270
00271
00272 LOCAL(void)
00273 create_colormap (j_decompress_ptr cinfo)
00274 {
00275 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
00276 JSAMPARRAY colormap;
00277 int total_colors;
00278 int i,j,k, nci, blksize, blkdist, ptr, val;
00279
00280
00281 total_colors = select_ncolors(cinfo, cquantize->Ncolors);
00282
00283
00284 if (cinfo->out_color_components == 3)
00285 TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
00286 total_colors, cquantize->Ncolors[0],
00287 cquantize->Ncolors[1], cquantize->Ncolors[2]);
00288 else
00289 TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
00290
00291
00292
00293
00294
00295 colormap = (*cinfo->mem->alloc_sarray)
00296 ((j_common_ptr) cinfo, JPOOL_IMAGE,
00297 (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
00298
00299
00300
00301 blkdist = total_colors;
00302
00303 for (i = 0; i < cinfo->out_color_components; i++) {
00304
00305 nci = cquantize->Ncolors[i];
00306 blksize = blkdist / nci;
00307 for (j = 0; j < nci; j++) {
00308
00309 val = output_value(cinfo, i, j, nci-1);
00310
00311 for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
00312
00313 for (k = 0; k < blksize; k++)
00314 colormap[i][ptr+k] = (JSAMPLE) val;
00315 }
00316 }
00317 blkdist = blksize;
00318 }
00319
00320
00321
00322
00323 cquantize->sv_colormap = colormap;
00324 cquantize->sv_actual = total_colors;
00325 }
00326
00327
00328
00329
00330
00331
00332 LOCAL(void)
00333 create_colorindex (j_decompress_ptr cinfo)
00334 {
00335 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
00336 JSAMPROW indexptr;
00337 int i,j,k, nci, blksize, val, pad;
00338
00339
00340
00341
00342
00343
00344 if (cinfo->dither_mode == JDITHER_ORDERED) {
00345 pad = MAXJSAMPLE*2;
00346 cquantize->is_padded = TRUE;
00347 } else {
00348 pad = 0;
00349 cquantize->is_padded = FALSE;
00350 }
00351
00352 cquantize->colorindex = (*cinfo->mem->alloc_sarray)
00353 ((j_common_ptr) cinfo, JPOOL_IMAGE,
00354 (JDIMENSION) (MAXJSAMPLE+1 + pad),
00355 (JDIMENSION) cinfo->out_color_components);
00356
00357
00358 blksize = cquantize->sv_actual;
00359
00360 for (i = 0; i < cinfo->out_color_components; i++) {
00361
00362 nci = cquantize->Ncolors[i];
00363 blksize = blksize / nci;
00364
00365
00366 if (pad)
00367 cquantize->colorindex[i] += MAXJSAMPLE;
00368
00369
00370
00371 indexptr = cquantize->colorindex[i];
00372 val = 0;
00373 k = largest_input_value(cinfo, i, 0, nci-1);
00374 for (j = 0; j <= MAXJSAMPLE; j++) {
00375 while (j > k)
00376 k = largest_input_value(cinfo, i, ++val, nci-1);
00377
00378 indexptr[j] = (JSAMPLE) (val * blksize);
00379 }
00380
00381 if (pad)
00382 for (j = 1; j <= MAXJSAMPLE; j++) {
00383 indexptr[-j] = indexptr[0];
00384 indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
00385 }
00386 }
00387 }
00388
00389
00390
00391
00392
00393
00394
00395 LOCAL(ODITHER_MATRIX_PTR)
00396 make_odither_array (j_decompress_ptr cinfo, int ncolors)
00397 {
00398 ODITHER_MATRIX_PTR odither;
00399 int j,k;
00400 INT32 num,den;
00401
00402 odither = (ODITHER_MATRIX_PTR)
00403 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00404 SIZEOF(ODITHER_MATRIX));
00405
00406
00407
00408
00409
00410 den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
00411 for (j = 0; j < ODITHER_SIZE; j++) {
00412 for (k = 0; k < ODITHER_SIZE; k++) {
00413 num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
00414 * MAXJSAMPLE;
00415
00416
00417
00418 odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
00419 }
00420 }
00421 return odither;
00422 }
00423
00424
00425
00426
00427
00428
00429
00430
00431 LOCAL(void)
00432 create_odither_tables (j_decompress_ptr cinfo)
00433 {
00434 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
00435 ODITHER_MATRIX_PTR odither;
00436 int i, j, nci;
00437
00438 for (i = 0; i < cinfo->out_color_components; i++) {
00439 nci = cquantize->Ncolors[i];
00440 odither = NULL;
00441 for (j = 0; j < i; j++) {
00442 if (nci == cquantize->Ncolors[j]) {
00443 odither = cquantize->odither[j];
00444 break;
00445 }
00446 }
00447 if (odither == NULL)
00448 odither = make_odither_array(cinfo, nci);
00449 cquantize->odither[i] = odither;
00450 }
00451 }
00452
00453
00454
00455
00456
00457
00458 METHODDEF(void)
00459 color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
00460 JSAMPARRAY output_buf, int num_rows)
00461
00462 {
00463 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
00464 JSAMPARRAY colorindex = cquantize->colorindex;
00465 register int pixcode, ci;
00466 register JSAMPROW ptrin, ptrout;
00467 int row;
00468 JDIMENSION col;
00469 JDIMENSION width = cinfo->output_width;
00470 register int nc = cinfo->out_color_components;
00471
00472 for (row = 0; row < num_rows; row++) {
00473 ptrin = input_buf[row];
00474 ptrout = output_buf[row];
00475 for (col = width; col > 0; col--) {
00476 pixcode = 0;
00477 for (ci = 0; ci < nc; ci++) {
00478 pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
00479 }
00480 *ptrout++ = (JSAMPLE) pixcode;
00481 }
00482 }
00483 }
00484
00485
00486 METHODDEF(void)
00487 color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
00488 JSAMPARRAY output_buf, int num_rows)
00489
00490 {
00491 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
00492 register int pixcode;
00493 register JSAMPROW ptrin, ptrout;
00494 JSAMPROW colorindex0 = cquantize->colorindex[0];
00495 JSAMPROW colorindex1 = cquantize->colorindex[1];
00496 JSAMPROW colorindex2 = cquantize->colorindex[2];
00497 int row;
00498 JDIMENSION col;
00499 JDIMENSION width = cinfo->output_width;
00500
00501 for (row = 0; row < num_rows; row++) {
00502 ptrin = input_buf[row];
00503 ptrout = output_buf[row];
00504 for (col = width; col > 0; col--) {
00505 pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
00506 pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
00507 pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
00508 *ptrout++ = (JSAMPLE) pixcode;
00509 }
00510 }
00511 }
00512
00513
00514 METHODDEF(void)
00515 quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
00516 JSAMPARRAY output_buf, int num_rows)
00517
00518 {
00519 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
00520 register JSAMPROW input_ptr;
00521 register JSAMPROW output_ptr;
00522 JSAMPROW colorindex_ci;
00523 int * dither;
00524 int row_index, col_index;
00525 int nc = cinfo->out_color_components;
00526 int ci;
00527 int row;
00528 JDIMENSION col;
00529 JDIMENSION width = cinfo->output_width;
00530
00531 for (row = 0; row < num_rows; row++) {
00532
00533 jzero_far((void FAR *) output_buf[row],
00534 (size_t) (width * SIZEOF(JSAMPLE)));
00535 row_index = cquantize->row_index;
00536 for (ci = 0; ci < nc; ci++) {
00537 input_ptr = input_buf[row] + ci;
00538 output_ptr = output_buf[row];
00539 colorindex_ci = cquantize->colorindex[ci];
00540 dither = cquantize->odither[ci][row_index];
00541 col_index = 0;
00542
00543 for (col = width; col > 0; col--) {
00544
00545
00546
00547
00548
00549
00550
00551 *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
00552 input_ptr += nc;
00553 output_ptr++;
00554 col_index = (col_index + 1) & ODITHER_MASK;
00555 }
00556 }
00557
00558 row_index = (row_index + 1) & ODITHER_MASK;
00559 cquantize->row_index = row_index;
00560 }
00561 }
00562
00563
00564 METHODDEF(void)
00565 quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
00566 JSAMPARRAY output_buf, int num_rows)
00567
00568 {
00569 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
00570 register int pixcode;
00571 register JSAMPROW input_ptr;
00572 register JSAMPROW output_ptr;
00573 JSAMPROW colorindex0 = cquantize->colorindex[0];
00574 JSAMPROW colorindex1 = cquantize->colorindex[1];
00575 JSAMPROW colorindex2 = cquantize->colorindex[2];
00576 int * dither0;
00577 int * dither1;
00578 int * dither2;
00579 int row_index, col_index;
00580 int row;
00581 JDIMENSION col;
00582 JDIMENSION width = cinfo->output_width;
00583
00584 for (row = 0; row < num_rows; row++) {
00585 row_index = cquantize->row_index;
00586 input_ptr = input_buf[row];
00587 output_ptr = output_buf[row];
00588 dither0 = cquantize->odither[0][row_index];
00589 dither1 = cquantize->odither[1][row_index];
00590 dither2 = cquantize->odither[2][row_index];
00591 col_index = 0;
00592
00593 for (col = width; col > 0; col--) {
00594 pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
00595 dither0[col_index]]);
00596 pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
00597 dither1[col_index]]);
00598 pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
00599 dither2[col_index]]);
00600 *output_ptr++ = (JSAMPLE) pixcode;
00601 col_index = (col_index + 1) & ODITHER_MASK;
00602 }
00603 row_index = (row_index + 1) & ODITHER_MASK;
00604 cquantize->row_index = row_index;
00605 }
00606 }
00607
00608
00609 METHODDEF(void)
00610 quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
00611 JSAMPARRAY output_buf, int num_rows)
00612
00613 {
00614 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
00615 register LOCFSERROR cur;
00616 LOCFSERROR belowerr;
00617 LOCFSERROR bpreverr;
00618 LOCFSERROR bnexterr;
00619 LOCFSERROR delta;
00620 register FSERRPTR errorptr;
00621 register JSAMPROW input_ptr;
00622 register JSAMPROW output_ptr;
00623 JSAMPROW colorindex_ci;
00624 JSAMPROW colormap_ci;
00625 int pixcode;
00626 int nc = cinfo->out_color_components;
00627 int dir;
00628 int dirnc;
00629 int ci;
00630 int row;
00631 JDIMENSION col;
00632 JDIMENSION width = cinfo->output_width;
00633 JSAMPLE *range_limit = cinfo->sample_range_limit;
00634 SHIFT_TEMPS
00635
00636 for (row = 0; row < num_rows; row++) {
00637
00638 jzero_far((void FAR *) output_buf[row],
00639 (size_t) (width * SIZEOF(JSAMPLE)));
00640 for (ci = 0; ci < nc; ci++) {
00641 input_ptr = input_buf[row] + ci;
00642 output_ptr = output_buf[row];
00643 if (cquantize->on_odd_row) {
00644
00645 input_ptr += (width-1) * nc;
00646 output_ptr += width-1;
00647 dir = -1;
00648 dirnc = -nc;
00649 errorptr = cquantize->fserrors[ci] + (width+1);
00650 } else {
00651
00652 dir = 1;
00653 dirnc = nc;
00654 errorptr = cquantize->fserrors[ci];
00655 }
00656 colorindex_ci = cquantize->colorindex[ci];
00657 colormap_ci = cquantize->sv_colormap[ci];
00658
00659 cur = 0;
00660
00661 belowerr = bpreverr = 0;
00662
00663 for (col = width; col > 0; col--) {
00664
00665
00666
00667
00668
00669
00670
00671
00672 cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
00673
00674
00675
00676
00677 cur += GETJSAMPLE(*input_ptr);
00678 cur = GETJSAMPLE(range_limit[cur]);
00679
00680 pixcode = GETJSAMPLE(colorindex_ci[cur]);
00681 *output_ptr += (JSAMPLE) pixcode;
00682
00683
00684
00685 cur -= GETJSAMPLE(colormap_ci[pixcode]);
00686
00687
00688
00689
00690 bnexterr = cur;
00691 delta = cur * 2;
00692 cur += delta;
00693 errorptr[0] = (FSERROR) (bpreverr + cur);
00694 cur += delta;
00695 bpreverr = belowerr + cur;
00696 belowerr = bnexterr;
00697 cur += delta;
00698
00699
00700
00701
00702 input_ptr += dirnc;
00703 output_ptr += dir;
00704 errorptr += dir;
00705 }
00706
00707
00708
00709
00710 errorptr[0] = (FSERROR) bpreverr;
00711 }
00712 cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
00713 }
00714 }
00715
00716
00717
00718
00719
00720
00721 LOCAL(void)
00722 alloc_fs_workspace (j_decompress_ptr cinfo)
00723 {
00724 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
00725 size_t arraysize;
00726 int i;
00727
00728 arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
00729 for (i = 0; i < cinfo->out_color_components; i++) {
00730 cquantize->fserrors[i] = (FSERRPTR)
00731 (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
00732 }
00733 }
00734
00735
00736
00737
00738
00739
00740 METHODDEF(void)
00741 start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
00742 {
00743 my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
00744 size_t arraysize;
00745 int i;
00746
00747
00748 cinfo->colormap = cquantize->sv_colormap;
00749 cinfo->actual_number_of_colors = cquantize->sv_actual;
00750
00751
00752 switch (cinfo->dither_mode) {
00753 case JDITHER_NONE:
00754 if (cinfo->out_color_components == 3)
00755 cquantize->pub.color_quantize = color_quantize3;
00756 else
00757 cquantize->pub.color_quantize = color_quantize;
00758 break;
00759 case JDITHER_ORDERED:
00760 if (cinfo->out_color_components == 3)
00761 cquantize->pub.color_quantize = quantize3_ord_dither;
00762 else
00763 cquantize->pub.color_quantize = quantize_ord_dither;
00764 cquantize->row_index = 0;
00765
00766
00767
00768
00769 if (! cquantize->is_padded)
00770 create_colorindex(cinfo);
00771
00772 if (cquantize->odither[0] == NULL)
00773 create_odither_tables(cinfo);
00774 break;
00775 case JDITHER_FS:
00776 cquantize->pub.color_quantize = quantize_fs_dither;
00777 cquantize->on_odd_row = FALSE;
00778
00779 if (cquantize->fserrors[0] == NULL)
00780 alloc_fs_workspace(cinfo);
00781
00782 arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
00783 for (i = 0; i < cinfo->out_color_components; i++)
00784 jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
00785 break;
00786 default:
00787 ERREXIT(cinfo, JERR_NOT_COMPILED);
00788 break;
00789 }
00790 }
00791
00792
00793
00794
00795
00796
00797 METHODDEF(void)
00798 finish_pass_1_quant (j_decompress_ptr cinfo)
00799 {
00800
00801 }
00802
00803
00804
00805
00806
00807
00808
00809 METHODDEF(void)
00810 new_color_map_1_quant (j_decompress_ptr cinfo)
00811 {
00812 ERREXIT(cinfo, JERR_MODE_CHANGE);
00813 }
00814
00815
00816
00817
00818
00819
00820 GLOBAL(void)
00821 jinit_1pass_quantizer (j_decompress_ptr cinfo)
00822 {
00823 my_cquantize_ptr cquantize;
00824
00825 cquantize = (my_cquantize_ptr)
00826 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00827 SIZEOF(my_cquantizer));
00828 cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
00829 cquantize->pub.start_pass = start_pass_1_quant;
00830 cquantize->pub.finish_pass = finish_pass_1_quant;
00831 cquantize->pub.new_color_map = new_color_map_1_quant;
00832 cquantize->fserrors[0] = NULL;
00833 cquantize->odither[0] = NULL;
00834
00835
00836 if (cinfo->out_color_components > MAX_Q_COMPS)
00837 ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
00838
00839 if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
00840 ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
00841
00842
00843 create_colormap(cinfo);
00844 create_colorindex(cinfo);
00845
00846
00847
00848
00849
00850
00851
00852 if (cinfo->dither_mode == JDITHER_FS)
00853 alloc_fs_workspace(cinfo);
00854 }
00855
00856 #endif