pyffi.formats.tga — Targa (.tga)

Implementation

class pyffi.formats.tga.TgaFormat

Bases: pyffi.object_models.xml.FileFormat

This class implements the TGA format.

class ColorMapType(**kwargs)

Bases: pyffi.object_models.xml.enum.EnumBase

An unsigned 8-bit integer, describing the color map type.

class TgaFormat.FooterString(template=None, argument=None, parent=None)

Bases: pyffi.object_models.xml.basic.BasicBase

The Targa footer signature.

get_hash(data=None)

Return a hash value for the signature.

Returns:An immutable object that can be used as a hash.
get_size(data=None)

Return number of bytes that the signature occupies in a file.

Returns:Number of bytes.
get_value()

Get signature.

Returns:The signature.
read(stream, data)

Read signature from stream.

Parameters:stream (file) – The stream to read from.
set_value(value)

Set signature.

Parameters:value (str) – The value to assign.
write(stream, data)

Write signature to stream.

Parameters:stream (file) – The stream to read from.
class TgaFormat.ImageType(**kwargs)

Bases: pyffi.object_models.xml.enum.EnumBase

An unsigned 8-bit integer, describing the image type.

TgaFormat.PixelData

alias of UndecodedData

TgaFormat.byte

alias of Byte

TgaFormat.char

alias of Char

TgaFormat.float

alias of Float

TgaFormat.int

alias of Int

TgaFormat.short

alias of Short

TgaFormat.ubyte

alias of UByte

TgaFormat.uint

alias of UInt

TgaFormat.ushort

alias of UShort

Regression tests

Read a TGA file

>>> # check and read tga file
>>> stream = open('tests/tga/test.tga', 'rb')
>>> data = TgaFormat.Data()
>>> data.inspect(stream)
>>> data.read(stream)
>>> stream.close()
>>> data.header.width
60
>>> data.header.height
20

Parse all TGA files in a directory tree

>>> for stream, data in TgaFormat.walkData('tests/tga'):
...     data.read(stream)
...     print(stream.name)
tests/tga/test.tga
tests/tga/test_footer.tga

Create a TGA file from scratch and write to file

>>> data = TgaFormat.Data()
>>> from tempfile import TemporaryFile
>>> stream = TemporaryFile()
>>> data.write(stream)
>>> stream.close()