Hash :
2cbeb8ab
Author :
Date :
1991-10-07T00:00:00
The Independent JPEG Group's JPEG software v1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
/*
* jquant2.c
*
* Copyright (C) 1991, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains 2-pass color quantization (color mapping) routines.
* These routines are invoked via the methods color_quant_prescan,
* color_quant_doit, and color_quant_init/term.
*/
#include "jinclude.h"
#ifdef QUANT_2PASS_SUPPORTED
/*
* Initialize for two-pass color quantization.
*/
METHODDEF void
color_quant_init (decompress_info_ptr cinfo)
{
TRACEMS(cinfo->emethods, 1, "color_quant_init 2 pass");
}
/*
* Prescan some rows of pixels.
* Note: this could change the data being written into the big image array,
* if there were any benefit to doing so. The doit routine is not allowed
* to modify the big image array, because the memory manager is not required
* to support multiple write passes on a big image.
*/
METHODDEF void
color_quant_prescan (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE image_data)
{
TRACEMS1(cinfo->emethods, 2, "color_quant_prescan %d rows", num_rows);
}
/*
* This routine makes the final pass over the image data.
* output_workspace is a one-component array of pixel dimensions at least
* as large as the input image strip; it can be used to hold the converted
* pixels' colormap indexes.
*/
METHODDEF void
final_pass (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE image_data, JSAMPARRAY output_workspace)
{
TRACEMS1(cinfo->emethods, 2, "final_pass %d rows", num_rows);
/* for debug purposes, just emit input data */
/* NB: this only works for PPM output */
(*cinfo->methods->put_pixel_rows) (cinfo, num_rows, image_data);
}
/*
* Perform two-pass quantization: rescan the image data and output the
* converted data via put_color_map and put_pixel_rows.
* The source_method is a routine that can scan the image data; it can
* be called as many times as desired. The processing routine called by
* source_method has the same interface as color_quantize does in the
* one-pass case, except it must call put_pixel_rows itself. (This allows
* me to use multiple passes in which earlier passes don't output anything.)
*/
METHODDEF void
color_quant_doit (decompress_info_ptr cinfo, quantize_caller_ptr source_method)
{
TRACEMS(cinfo->emethods, 1, "color_quant_doit 2 pass");
(*source_method) (cinfo, final_pass);
}
/*
* Finish up at the end of the file.
*/
METHODDEF void
color_quant_term (decompress_info_ptr cinfo)
{
TRACEMS(cinfo->emethods, 1, "color_quant_term 2 pass");
}
/*
* Map some rows of pixels to the output colormapped representation.
* Not used in two-pass case.
*/
METHODDEF void
color_quantize (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE input_data, JSAMPARRAY output_data)
{
ERREXIT(cinfo->emethods, "Should not get here!");
}
/*
* The method selection routine for 2-pass color quantization.
*/
GLOBAL void
jsel2quantize (decompress_info_ptr cinfo)
{
if (cinfo->two_pass_quantize) {
/* just one alternative for the moment */
cinfo->methods->color_quant_init = color_quant_init;
cinfo->methods->color_quant_prescan = color_quant_prescan;
cinfo->methods->color_quant_doit = color_quant_doit;
cinfo->methods->color_quant_term = color_quant_term;
cinfo->methods->color_quantize = color_quantize;
}
}
#endif /* QUANT_2PASS_SUPPORTED */