这个.ico文件里面有一个.png图片有什么问题?

时间:2016-10-14 23:23:34

标签: png ico

我将文件基于https://en.wikipedia.org/wiki/ICO_(file_format)https://www.w3.org/TR/PNG/。我将.ico文件从我在十六进制编辑器中的外观转换为某种伪二进制文件(字节的顺序如下所示):

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图像(放大到100x100):

由于可以显示PNG,我猜有一些我没有发现/误解的文档。如果你看到它,请指出错误!

1 个答案:

答案 0 :(得分:1)

我错过了小端部分... ICO部分的正确版本是:

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  
    }
}