Skip to content

Commit 391435b

Browse files
committed
Add PIL docs
1 parent 45d1624 commit 391435b

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

tivars/PIL/TI8caPlugin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@
33

44

55
class TI8caImageFile(TIImageFile):
6+
"""
7+
`ImageFile` handler for 8ca files (`TIImage`)
8+
"""
9+
610
_T = TIImage
711

812
format = "8ca"
913
format_description = "TI (e)Z80 Image Format"
1014

1115

1216
class TI8caEncoder(TIEncoder):
17+
"""
18+
Encoder for 8ca files (`TIImage`)
19+
"""
20+
1321
_T = TIImage
1422

1523

1624
register(TI8caImageFile, TI8caEncoder)
25+
26+
__all__ = ["TI8caEncoder", "TI8caImageFile"]

tivars/PIL/TI8ciPlugin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@
33

44

55
class TI8ciImageFile(TIImageFile):
6+
"""
7+
`ImageFile` handler for 8ci files (`TIPicture`)
8+
"""
9+
610
_T = TIPicture
711

812
format = "8ci"
913
format_description = "TI (e)Z80 Color Picture Format"
1014

1115

1216
class TI8ciEncoder(TIEncoder):
17+
"""
18+
Encoder for 8ci files (`TIPicture`)
19+
"""
20+
1321
_T = TIPicture
1422

1523

1624
register(TI8ciImageFile, TI8ciEncoder)
25+
26+
__all__ = ["TI8ciEncoder", "TI8ciImageFile"]

tivars/PIL/TI8xiPlugin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@
33

44

55
class TI8xiImageFile(TIImageFile):
6+
"""
7+
`ImageFile` handler for 8xi files (`TIMonoPicture`)
8+
"""
9+
610
_T = TIMonoPicture
711

812
format = "8xi"
913
format_description = "TI (e)Z80 Monochrome Picture Format"
1014

1115

1216
class TI8xiEncoder(TIEncoder):
17+
"""
18+
Encoder for 8xi files (`TIMonoPicture`)
19+
"""
20+
1321
_T = TIMonoPicture
1422

1523

1624
register(TI8xiImageFile, TI8xiEncoder)
25+
26+
__all__ = ["TI8xiEncoder", "TI8xiImageFile"]

tivars/PIL/common.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ def register(file, encoder):
2020

2121

2222
class TIImageFile(ImageFile.ImageFile):
23+
"""
24+
Base class for PIL plugin `ImageFile` types
25+
"""
26+
2327
_T = PictureEntry
2428

2529
format = "8??"
2630

2731
def _open(self):
32+
"""
33+
Loads necessary image information from an opened file
34+
"""
35+
2836
with warnings.catch_warnings():
2937
warnings.simplefilter("error")
3038

@@ -42,11 +50,33 @@ def _open(self):
4250

4351
@classmethod
4452
def _save(cls, im, fp, format=None, **params):
53+
"""
54+
Saves an image to a file pointer
55+
56+
This function is used to register formats with PIL and should not be called manually.
57+
58+
:param im: The image to save
59+
:param fp: The file pointer
60+
:param format: The format to save with (defaults to the image's known format)
61+
:param params: Additional encoder parameters (empty)
62+
"""
63+
4564
ImageFile._save(im, fp, format, [(cls.format, (0, 0) + im.size, 0, im.mode)])
4665

4766

4867
class TIDecoder(ImageFile.PyDecoder):
68+
"""
69+
Base class for PIL plugin decoders
70+
"""
71+
4972
def decode(self, buffer):
73+
"""
74+
Decodes an input buffer and sets the image to its contents
75+
76+
:param buffer: The input bytestream
77+
:return: The number of bytes consumed and the error code (``-1, 0`` on success)
78+
"""
79+
5080
var = TIVar()
5181
var.load_bytes(buffer)
5282
self.set_as_raw(np.asarray(var.entries[0].array(), dtype=np.uint8))
@@ -55,11 +85,22 @@ def decode(self, buffer):
5585

5686

5787
class TIEncoder(ImageFile.PyEncoder):
88+
"""
89+
Base class for PIL plugin encoders
90+
"""
91+
5892
_pushes_fd = True
5993

6094
_T = PictureEntry
6195

6296
def encode(self, bufsize):
97+
"""
98+
Encodes the image to an output bytestream
99+
100+
:param bufsize: The size of the output buffer (unused)
101+
:return: The length of the output, the error code (``0`` on success), and the output
102+
"""
103+
63104
img = self._T()
64105
img.load_array(np.asarray(self.im).reshape((img.height, img.width)).tolist())
65106
data = img.export().bytes()

0 commit comments

Comments
 (0)