< prev index next >

modules/javafx.graphics/src/main/native-iio/libjpeg7/jquant2.c

Print this page


   1 /*
   2  * jquant2.c
   3  *
   4  * Copyright (C) 1991-1996, Thomas G. Lane.

   5  * This file is part of the Independent JPEG Group's software.
   6  * For conditions of distribution and use, see the accompanying README file.
   7  *
   8  * This file contains 2-pass color quantization (color mapping) routines.
   9  * These routines provide selection of a custom color map for an image,
  10  * followed by mapping of the image to that color map, with optional
  11  * Floyd-Steinberg dithering.
  12  * It is also possible to use just the second pass to map to an arbitrary
  13  * externally-given color map.
  14  *
  15  * Note: ordered dithering is not supported, since there isn't any fast
  16  * way to compute intercolor distances; it's unclear that ordered dither's
  17  * fundamental assumptions even hold with an irregularly spaced color map.
  18  */
  19 
  20 #define JPEG_INTERNALS
  21 #include "jinclude.h"
  22 #include "jpeglib.h"
  23 
  24 #ifdef QUANT_2PASS_SUPPORTED


1186       cquantize->pub.color_quantize = pass2_fs_dither;
1187     else
1188       cquantize->pub.color_quantize = pass2_no_dither;
1189     cquantize->pub.finish_pass = finish_pass2;
1190 
1191     /* Make sure color count is acceptable */
1192     i = cinfo->actual_number_of_colors;
1193     if (i < 1)
1194       ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
1195     if (i > MAXNUMCOLORS)
1196       ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
1197 
1198     if (cinfo->dither_mode == JDITHER_FS) {
1199       size_t arraysize = (size_t) ((cinfo->output_width + 2) *
1200                                    (3 * SIZEOF(FSERROR)));
1201       /* Allocate Floyd-Steinberg workspace if we didn't already. */
1202       if (cquantize->fserrors == NULL)
1203         cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
1204           ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
1205       /* Initialize the propagated errors to zero. */
1206       jzero_far((void FAR *) cquantize->fserrors, arraysize);
1207       /* Make the error-limit table if we didn't already. */
1208       if (cquantize->error_limiter == NULL)
1209         init_error_limit(cinfo);
1210       cquantize->on_odd_row = FALSE;
1211     }
1212 
1213   }
1214   /* Zero the histogram or inverse color map, if necessary */
1215   if (cquantize->needs_zeroed) {
1216     for (i = 0; i < HIST_C0_ELEMS; i++) {
1217       jzero_far((void FAR *) histogram[i],
1218                 HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
1219     }
1220     cquantize->needs_zeroed = FALSE;
1221   }
1222 }
1223 
1224 
1225 /*
1226  * Switch to a new external colormap between output passes.
1227  */
1228 
1229 METHODDEF(void)
1230 new_color_map_2_quant (j_decompress_ptr cinfo)
1231 {
1232   my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
1233 
1234   /* Reset the inverse color map */
1235   cquantize->needs_zeroed = TRUE;
1236 }
1237 


   1 /*
   2  * jquant2.c
   3  *
   4  * Copyright (C) 1991-1996, Thomas G. Lane.
   5  * Modified 2011 by Guido Vollbeding.
   6  * This file is part of the Independent JPEG Group's software.
   7  * For conditions of distribution and use, see the accompanying README file.
   8  *
   9  * This file contains 2-pass color quantization (color mapping) routines.
  10  * These routines provide selection of a custom color map for an image,
  11  * followed by mapping of the image to that color map, with optional
  12  * Floyd-Steinberg dithering.
  13  * It is also possible to use just the second pass to map to an arbitrary
  14  * externally-given color map.
  15  *
  16  * Note: ordered dithering is not supported, since there isn't any fast
  17  * way to compute intercolor distances; it's unclear that ordered dither's
  18  * fundamental assumptions even hold with an irregularly spaced color map.
  19  */
  20 
  21 #define JPEG_INTERNALS
  22 #include "jinclude.h"
  23 #include "jpeglib.h"
  24 
  25 #ifdef QUANT_2PASS_SUPPORTED


1187       cquantize->pub.color_quantize = pass2_fs_dither;
1188     else
1189       cquantize->pub.color_quantize = pass2_no_dither;
1190     cquantize->pub.finish_pass = finish_pass2;
1191 
1192     /* Make sure color count is acceptable */
1193     i = cinfo->actual_number_of_colors;
1194     if (i < 1)
1195       ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
1196     if (i > MAXNUMCOLORS)
1197       ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
1198 
1199     if (cinfo->dither_mode == JDITHER_FS) {
1200       size_t arraysize = (size_t) ((cinfo->output_width + 2) *
1201                                    (3 * SIZEOF(FSERROR)));
1202       /* Allocate Floyd-Steinberg workspace if we didn't already. */
1203       if (cquantize->fserrors == NULL)
1204         cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
1205           ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
1206       /* Initialize the propagated errors to zero. */
1207       FMEMZERO((void FAR *) cquantize->fserrors, arraysize);
1208       /* Make the error-limit table if we didn't already. */
1209       if (cquantize->error_limiter == NULL)
1210         init_error_limit(cinfo);
1211       cquantize->on_odd_row = FALSE;
1212     }
1213 
1214   }
1215   /* Zero the histogram or inverse color map, if necessary */
1216   if (cquantize->needs_zeroed) {
1217     for (i = 0; i < HIST_C0_ELEMS; i++) {
1218       FMEMZERO((void FAR *) histogram[i],
1219                HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
1220     }
1221     cquantize->needs_zeroed = FALSE;
1222   }
1223 }
1224 
1225 
1226 /*
1227  * Switch to a new external colormap between output passes.
1228  */
1229 
1230 METHODDEF(void)
1231 new_color_map_2_quant (j_decompress_ptr cinfo)
1232 {
1233   my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
1234 
1235   /* Reset the inverse color map */
1236   cquantize->needs_zeroed = TRUE;
1237 }
1238 


< prev index next >