c++
for (col = cinfo->image_width; col > 0; col--) {
    t = GETJSAMPLE(*inptr++);
    if (t < cmaplen) {
        *outptr++ = colormap[0][t];
    } else {
        // Handle out-of-bounds condition
        // e.g., set *outptr++ to a default value
        *outptr++ = colormap[0][0]; // Use first color in colormap
    }
}
