private void fill_inverse_cmap(int c0, int c1, int c2)
{
/* Convert cell coordinates to update box ID */
c0 >>= BOX_C0_LOG;
c1 >>= BOX_C1_LOG;
c2 >>= BOX_C2_LOG;
/* Compute true coordinates of update box's origin corner.
* Actually we compute the coordinates of the center of the corner
* histogram cell, which are the lower bounds of the volume we care about.
*/
int minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
int minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
int minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
/* Determine which colormap entries are close enough to be candidates
* for the nearest entry to some cell in the update box.
*/
/* This array lists the candidate colormap indexes. */
byte[] colorlist = new byte[MAXNUMCOLORS];
int numcolors = find_nearby_colors(minc0, minc1, minc2, colorlist);
/* Determine the actually nearest colors. */
/* This array holds the actually closest colormap index for each cell. */
byte[] bestcolor = new byte[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
find_best_colors(minc0, minc1, minc2, numcolors, colorlist, bestcolor);
/* Save the best color numbers (plus 1) in the main cache array */
c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
c1 <<= BOX_C1_LOG;
c2 <<= BOX_C2_LOG;
int bestcolorIndex = 0;
for (int ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++)
{
for (int ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++)
{
int histogramIndex = (c1 + ic1) * HIST_C2_ELEMS + c2;
for (int ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++)
{
m_histogram[c0 + ic0][histogramIndex] = (ushort) ((int)bestcolor[bestcolorIndex] + 1);
histogramIndex++;
bestcolorIndex++;
}
}
}
}
}