lmp
Module¶
Source code: lmp.py
The lmp
module provides an Lmp
class which derives
from ReadWriteFile
and is used to read and write Quake
lmp data.
Lmp
Class¶
- class vgio.quake.lmp.Lmp¶
Class for working with Lmp files
There are three different types of lump files:
- 2D image - The majority of the lump files are 2D images. If a lump
is a 2D image it will have width, height, and pixels attributes.
- Palette - The palette lump has the palette attribute which is a
list of 256 RGB tuples. This is used to map color indexes to actual RGB triples.
- Colormap - The colormap lump has the colormap attribute which is a
list of 16384 color indexes. It functions as a 256 x 64 table for mapping colors to different values for lighting.
Example
Basic usage:
from vgio.quake.lmp import Lmp l = Lmp.open(file)
- width¶
(2D image lump only) The width of the lump.
- height¶
(2D image lump only) The height of the lump.
- pixels¶
(2D image lump only) The raw pixel data.
- palette¶
(Palette lump only) A sequence of 256 RGB tuples.
- colormap¶
(Color Map lump only) A sequence of 16384 color indexes.
- Lmp.__init__()¶
Initializes a ReadWriteFile object. Derving classes must call this.
- classmethod Lmp.open(file, mode='r')¶
Open a ReadWriteFile object where file can be a path to a file (a string), or a file-like object.
The mode parameter should be ‘r’ to read an existing file, ‘w’ to truncate and write a new file, or ‘a’ to append to an existing file.
open() is also a context manager and supports the with statement:
with ReadWriteFile.open('file.ext') as file: file.save('file2.ext')
- Parameters
file – Either the path to the file, a file-like object, or bytes.
mode – An optional string that indicates which mode to open the file
- Returns
An ReadWriteFile object constructed from the information read from the file-like object.
- Raises
ValueError – If an invalid file mode is given.
TypeError – If attempting to write to a bytes object.
OSError – If the file argument is not a file-like object.
- Lmp.close()¶
Closes the file pointer if possible. If mode is ‘w’ or ‘a’, the file will be written to.
- Lmp.save(file)¶
Writes data to file.
- Parameters
file – Either the path to the file, or a file-like object.
- Raises
OSError – If file argument is not a file-like object.