0

I based the file on https://en.wikipedia.org/wiki/ICO_(file_format) and https://www.w3.org/TR/PNG/. I will translate the .ico file from how it looks in my hex editor into some kind of pseudo-binary (the order of the bytes are as written out):

ICONDIR{
    uint16_t idReserved : 00 00 
    uint16_t idType : 00 01 
    uint16_t idCount : 00 01 
    ICONDIRENTRY{
        uint8_t bWidth : 01 
        uint8_t bHeight : 01 
        uint8_t bColorCount : 00 
        uint8_t bReserved : 00 
        uint16_t wPlanes : 00 00 
        uint16_t wBitCount : 00 20 
        uint32_t dwBytesInRes : 00 00 00 49 
        uint32_t dwImageOffset : 00 00 00 16 
    }
}
PNG{
    uint8_t PNGSignature[8] : 89 50 4E 47 0D 0A 1A 0A 
    IHDR{
        uint32_t Length :  00 00 00 0D 
        uint8_t ChunkType[4] : 49 48 44 52 //IHDR
        uint32_t Width : 00 00 00 01 
        uint32_t Height : 00 00 00 01 
        uint8_t BitDepth : 08 //8 bits
        uint8_t ColourType : 06 //RGBA
        uint8_t CompressionMethod : 00 
        uint8_t FilterMethod : 00
        uint8_t InterlaceMethod : 00 
        uint32_t CRC32 : 1F 15 C4 89 //CRC32 of bits [ChunkType,...,InterlaceMethod]
    }
    IDAT{
        uint32_t Length : 00 00 00 10 
        uint8_t ChunkType[4] : 49 44 41 54 //IDAT
        ZLIB{
            (CMF.CINFO = 0000,CMF.CM = 1000) : 08 
            (FLG.FLEVEL = 10 /*Slowest Algorithm*/
            ,FLG.FDICT = 0 /* No dictionary */
            ,FLG.FCHECK = 11001 /* 0000100010011001 = 2201 = 71 x 31 */) : 99 
            DEFLATE{
                (BFINAL = 1 /* Last block */
                ,BTYPE = 00 /* No compression */
                ,<No compression ignored bytes = 00000>) : 80 
                uint16_t LEN : 00 05 
                uint16_t NLEN : FF FA 
                LITERAL_DATA_SCANLINE{
                    uint8_t FilterTypeByte : 00 // No filtering
                    PIXEL{
                        uint8_t R : FF 
                        uint8_t G : 00 
                        uint8_t B : 00 
                        uint8_t A : FF 
                    }
                }
            }
            uint32_t ADLER32 : 00 AB 00 A2 
        }
        uint32_t CRC32 : 02 EA 6B 91 //CRC32 of bits [ChunkType,ZLIB]
    }
    IEND{
        uint32_t Length : 00 00 00 00 
        uint8_t ChunkType[4] : 49 45 4E 44 
        uint32_t CRC32 : AE 42 60 82 //CRC32 of [ChunkType]
    }
}

PNG image (magnified to size 100x100):

Since the PNG can be displayed I guess there is some documentation I have not found/misinterpreted. Please point to the error if you see it!

Emil
  • 177
  • 1
  • 10

1 Answers1

1

I had missed the little-endian part... Correct version of the ICO part is:

ICONDIR{
    uint16_t idReserved : 00 00 
    uint16_t idType : 01 00 
    uint16_t idCount : 01 00 
    ICONDIRENTRY{
        uint8_t bWidth : 01 
        uint8_t bHeight : 01 
        uint8_t bColorCount : 00 
        uint8_t bReserved : 00 
        uint16_t wPlanes : 00 00 
        uint16_t wBitCount : 20 00  
        uint32_t dwBytesInRes : 49 00 00 00  
        uint32_t dwImageOffset : 16 00 00 00  
    }
}
Emil
  • 177
  • 1
  • 10