Esme Povirk (@madewokherd) commented about dlls/windowscodecs/imgfactory.c:
bmi->bmiHeader.biBitCount = 0; GetDIBits(hdc, hbm, 0, 0, NULL, bmi, DIB_RGB_COLORS); bmi->bmiHeader.biHeight = -bm.bmHeight; GetDIBits(hdc, hbm, 0, bm.bmHeight, buffer, bmi, DIB_RGB_COLORS);
I think this GetDIBits call will read the palette, and it would be simpler to use that.