如何使用python从文件规范生成文件读取器?

2024-05-06 21:37:15 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧,我在处理文件方面还是个新手,有没有人有教程告诉我如何从文件规范中获取信息,这样我就可以用python操作文件了。我想学习如何在将来做这件事,但具体来说,我现在感兴趣的格式叫sff,基本上是一种包含pcx图像的存档类型,其中包含每个帧的一些信息,最终目标是我要解压它并将pcx的子组转换成动画GIF(我已经可以完成最后一部分了,我现在只是想弄清楚如何打开sff)。我尝试过从python文档中读取二进制文件,并使用seek read和strikeunpack来拼凑信息,但它似乎并不像我期望的那样有效。现在我被困在seek(24)read(4)(这应该给出下一个子标题的位置),并得到\x00\x02\x00\x00的结果。我猜是hex(但我不知道如何让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.
*--------------------------------------------------------------------------*/

Tags: 文件oftheinimageifbytesis