Look at FillGrayscalePalette for details.
function ImFillGrayscalePalette(Pal: PPalette32; Entries: LongInt): Boolean; cdecl;
ImagingExport (at line 171)