First post, by videogamer555
When I do Ctrl+F5 to save a screenshot, it saves a PNG in indexed palette mode, with a copy of the VGA palette being the palette for the PNG file. However the values for indexes 16 to 31 (the grayscale entries part of the palette) seem to be incorrect. For example at index 17, it should be the darkest gray in that section of the palette with RGB values of 17,17,17. However instead the RGB values are 20,20,20
Likewise at index 18, it should have RGB values of 34,34,34. However instead the RGB values are 32,32,32.
To scale 16 values (range of values being 0 to 15) into 256 values (range of values being 0 to 255) all you need to do is multiply by 17, as the number 15 goes into 255 exactly 17 times. And since the indexes for the grayscale part of the palette start with index 16, all you need to do is first subtract by 16.
The formula for generating the RGB values for that set of grayscale colors for the palette should be: (index-16)*17
So with index=16 you have (16-16)*17 = 0 (RGB values are therefore 0,0,0 here)
With index=17 you have (17-16)*17 = 17 (RGB values are therefore 17,17,17 here)
With index=18 you have (18-16)*17 = 34 (RGB values are therefore 34,34,34 here)
But those are not the values I'm getting. Instead I'm getting the incorrect value of RGB=20,20,20 at index 17. And I'm getting the incorrect value of RGB=32,32,32 at index=18. Likewise all the remaining RGB values for the grayscale colors up to index 30 are incorrect. And then it's correct again at index 31 with the RGB values being 255,255,255. So only the RGB values for index 16 and index 31 are correct in this grayscale part of the palette.
Fortunately the EGA part of the 256 color palette (the first 16 indexes from 0 to 15 within the overall 256 color VGA palette) do have correct RGB values. And I have no idea how the pastel and dark pastel colors part of the palette are intended to be calculated, so I haven't checked them for accuracy yet.
It does seem though that the grayscale part of the VGA palette have been incorrectly calculated. I even tried various things like first scaling it into 64 values (I know that in 256 color mode only 64 levels of brightness are possible with each channel, due to this mode only using 6 bits per channel instead of the full 8 bits per channel) but even attempting to first scale the values into the 0-to-63 range and then scaling them again into the 0-to-255 range, still didn't produce results that match the values in the DOSBox color palette for the grayscale part of the palette. It did give some rounding errors, but those errors didn't generate the exact RGB values found in the DOSBox 256 color palette for mode 0x13.
Either there's something in the VGA official specs that involves calculating these using an algorithm that isn't the obvious one, or there's a bug in the DOSBox palette.