I mean:
16 bit RGB = 1 pixel per 2 byte -> RRRRRGGGGGGBBBBB
8 bit grayscale = 1 pixel per byte -> GGGGGGGG
pix1 pix2
4 bit grayscale = 2 pixel per byte -> GGGG GGGG
It's working with the code provided by robtillaart. Yours is more compat but also (for me) more complaex to read.
If it ismore efficient regarding storage space or calculation time, I will try to implement it.
Thanks
Robert