好吧我一般都很擅长处理文件,有没有人会有一个教程,告诉我如何从文件规范中获取信息,这样我就可以在python中操作文件了。我想学习将来如何做到这一点,但具体我现在感兴趣的格式是调用sff,基本上是包含pcx图像的存档类型,其中包含有关每个帧的一些信息,最终目标是我想要的解压缩并将pcx的子组转换为动画GIF(我已经可以完成最后一部分了,我只想弄清楚如何解压缩sff)。我试图拼凑有关从python文档读取二进制文件的信息,并使用seek read和struck unpack,但它似乎没有像我期望的那样工作。现在我停留在seek(24)
read(4)
(这应该是给出下一个子标题的位置),并获得\x00\x02\x00\x00
的结果。我猜是十六进制(但我不知道如何让python告诉我)。所以我正在寻找一个教程,但也欢迎具体的答案。感谢。
这是我的规范:
/*--| SFF file structure
|--------------------------------------------------*\
Version 1.01
HEADER (512 bytes)
------
Bytes
00-11 "ElecbyteSpr\0" signature [12]
12-15 1 verhi, 1 verlo, 1 verlo2, 1 verlo3 [04]
16-19 Number of groups [04]
20-24 Number of images [04]
24-27 File offset where first subfile is located [04]
28-31 Size of subheader in bytes [04]
32 Palette type (1=SPRPALTYPE_SHARED or 0=SPRPALTYPE_INDIV) [01]
33-35 Blank; set to zero [03]
36-511 Blank; can be used for comments [476]
SUBFILEHEADER (32 bytes)
-------
Bytes
00-03 File offset where next subfile in the "linked list" is [04]
located. Null if last subfile
04-07 Subfile length (not including header) [04]
Length is 0 if it is a linked sprite
08-09 Image axis X coordinate [02]
10-11 Image axis Y coordinate [02]
12-13 Group number [02]
14-15 Image number (in the group) [02]
16-17 Index of previous copy of sprite (linked sprites only) [02]
This is the actual
18 True if palette is same as previous image [01]
19-31 Blank; can be used for comments [14]
32- PCX graphic data. If palette data is available, it is the last
768 bytes.
*--------------------------------------------------------------------------*/