diff --git a/tivars/PIL/TI8caPlugin.py b/tivars/PIL/TI8caPlugin.py index 860394c..4f2dcaf 100644 --- a/tivars/PIL/TI8caPlugin.py +++ b/tivars/PIL/TI8caPlugin.py @@ -3,6 +3,10 @@ class TI8caImageFile(TIImageFile): + """ + `ImageFile` handler for 8ca files (`TIImage`) + """ + _T = TIImage format = "8ca" @@ -10,7 +14,13 @@ class TI8caImageFile(TIImageFile): class TI8caEncoder(TIEncoder): + """ + Encoder for 8ca files (`TIImage`) + """ + _T = TIImage register(TI8caImageFile, TI8caEncoder) + +__all__ = ["TI8caEncoder", "TI8caImageFile"] diff --git a/tivars/PIL/TI8ciPlugin.py b/tivars/PIL/TI8ciPlugin.py index bac9f5f..d412216 100644 --- a/tivars/PIL/TI8ciPlugin.py +++ b/tivars/PIL/TI8ciPlugin.py @@ -3,6 +3,10 @@ class TI8ciImageFile(TIImageFile): + """ + `ImageFile` handler for 8ci files (`TIPicture`) + """ + _T = TIPicture format = "8ci" @@ -10,7 +14,13 @@ class TI8ciImageFile(TIImageFile): class TI8ciEncoder(TIEncoder): + """ + Encoder for 8ci files (`TIPicture`) + """ + _T = TIPicture register(TI8ciImageFile, TI8ciEncoder) + +__all__ = ["TI8ciEncoder", "TI8ciImageFile"] diff --git a/tivars/PIL/TI8xiPlugin.py b/tivars/PIL/TI8xiPlugin.py index 5d6b3a0..0f8aac1 100644 --- a/tivars/PIL/TI8xiPlugin.py +++ b/tivars/PIL/TI8xiPlugin.py @@ -3,6 +3,10 @@ class TI8xiImageFile(TIImageFile): + """ + `ImageFile` handler for 8xi files (`TIMonoPicture`) + """ + _T = TIMonoPicture format = "8xi" @@ -10,7 +14,13 @@ class TI8xiImageFile(TIImageFile): class TI8xiEncoder(TIEncoder): + """ + Encoder for 8xi files (`TIMonoPicture`) + """ + _T = TIMonoPicture register(TI8xiImageFile, TI8xiEncoder) + +__all__ = ["TI8xiEncoder", "TI8xiImageFile"] diff --git a/tivars/PIL/common.py b/tivars/PIL/common.py index f238f0d..39b5999 100644 --- a/tivars/PIL/common.py +++ b/tivars/PIL/common.py @@ -20,11 +20,19 @@ def register(file, encoder): class TIImageFile(ImageFile.ImageFile): + """ + Base class for PIL plugin `ImageFile` types + """ + _T = PictureEntry format = "8??" def _open(self): + """ + Loads necessary image information from an opened file + """ + with warnings.catch_warnings(): warnings.simplefilter("error") @@ -42,11 +50,33 @@ def _open(self): @classmethod def _save(cls, im, fp, format=None, **params): + """ + Saves an image to a file pointer + + This function is used to register formats with PIL and should not be called manually. + + :param im: The image to save + :param fp: The file pointer + :param format: The format to save with (defaults to the image's known format) + :param params: Additional encoder parameters (empty) + """ + ImageFile._save(im, fp, format, [(cls.format, (0, 0) + im.size, 0, im.mode)]) class TIDecoder(ImageFile.PyDecoder): + """ + Base class for PIL plugin decoders + """ + def decode(self, buffer): + """ + Decodes an input buffer and sets the image to its contents + + :param buffer: The input bytestream + :return: The number of bytes consumed and the error code (``-1, 0`` on success) + """ + var = TIVar() var.load_bytes(buffer) self.set_as_raw(np.asarray(var.entries[0].array(), dtype=np.uint8)) @@ -55,11 +85,22 @@ def decode(self, buffer): class TIEncoder(ImageFile.PyEncoder): + """ + Base class for PIL plugin encoders + """ + _pushes_fd = True _T = PictureEntry def encode(self, bufsize): + """ + Encodes the image to an output bytestream + + :param bufsize: The size of the output buffer (unused) + :return: The length of the output, the error code (``0`` on success), and the output + """ + img = self._T() img.load_array(np.asarray(self.im).reshape((img.height, img.width)).tolist()) data = img.export().bytes()