c++
for (col = cinfo->image_width; col > 0; col--) {
    t = GETJSAMPLE(*inptr++);
    *outptr++ = colormap[0][MIN(t, cmaplen - 1)]; // Use MIN() to clamp
}
