I noticed that LibreSprite and Aseprite only read .ico files correctly if the image is in 24-bit color depth. 2-, 4-, 8- and 32-bit color depths are not handled. In order to better understand this file format, I looked up some documentation on Wikipedia ICO (file format) and BMP, as well as Microsoft Learn: Icons, BITMAPINFOHEADER and The evolution of the ICO file format.
Libresprite also doesn't import bitmaps (.bmp) with 2-bit and 4-bit palettes correctly.
I wrote this code as an exercice to understand the position of the metadata and imagedata of these formats.
Looking into working on LibreSprite one day to better import these formats.