private void create_colormap()
{
/* Select number of colors for each component */
int total_colors = select_ncolors(m_Ncolors);
/* Report selected color counts */
if (m_cinfo.m_out_color_components == 3)
m_cinfo.TRACEMS(1, J_MESSAGE_CODE.JTRC_QUANT_3_NCOLORS, total_colors, m_Ncolors[0], m_Ncolors[1], m_Ncolors[2]);
else
m_cinfo.TRACEMS(1, J_MESSAGE_CODE.JTRC_QUANT_NCOLORS, total_colors);
/* Allocate and fill in the colormap. */
/* The colors are ordered in the map in standard row-major order, */
/* i.e. rightmost (highest-indexed) color changes most rapidly. */
byte[][] colormap = jpeg_common_struct.AllocJpegSamples(total_colors, m_cinfo.m_out_color_components);
/* blksize is number of adjacent repeated entries for a component */
/* blkdist is distance between groups of identical entries for a component */
int blkdist = total_colors;
for (int i = 0; i < m_cinfo.m_out_color_components; i++)
{
/* fill in colormap entries for i'th color component */
int nci = m_Ncolors[i]; /* # of distinct values for this color */
int blksize = blkdist / nci;
for (int j = 0; j < nci; j++)
{
/* Compute j'th output value (out of nci) for component */
int val = output_value(j, nci - 1);
/* Fill in all colormap entries that have this value of this component */
for (int ptr = j * blksize; ptr < total_colors; ptr += blkdist)
{
/* fill in blksize entries beginning at ptr */
for (int k = 0; k < blksize; k++)
colormap[i][ptr + k] = (byte)val;
}
}
/* blksize of this color is blkdist of next */
blkdist = blksize;
}
/* Save the colormap in private storage,
* where it will survive color quantization mode changes.
*/
m_sv_colormap = colormap;
m_sv_actual = total_colors;
}