1#
2# The Python Imaging Library.
3# $Id$
4#
5# PIXAR raster support for PIL
6#
7# history:
8# 97-01-29 fl Created
9#
10# notes:
11# This is incomplete; it is based on a few samples created with
12# Photoshop 2.5 and 3.0, and a summary description provided by
13# Greg Coats <gcoats@labiris.er.usgs.gov>. Hopefully, "L" and
14# "RGBA" support will be added in future versions.
15#
16# Copyright (c) Secret Labs AB 1997.
17# Copyright (c) Fredrik Lundh 1997.
18#
19# See the README file for information on usage and redistribution.
20#
21from __future__ import annotations
22
23from . import Image, ImageFile
24from ._binary import i16le as i16
25
26#
27# helpers
28
29
30def _accept(prefix: bytes) -> bool:
31 return prefix[:4] == b"\200\350\000\000"
32
33
34##
35# Image plugin for PIXAR raster images.
36
37
38class PixarImageFile(ImageFile.ImageFile):
39 format = "PIXAR"
40 format_description = "PIXAR raster image"
41
42 def _open(self) -> None:
43 # assuming a 4-byte magic label
44 assert self.fp is not None
45
46 s = self.fp.read(4)
47 if not _accept(s):
48 msg = "not a PIXAR file"
49 raise SyntaxError(msg)
50
51 # read rest of header
52 s = s + self.fp.read(508)
53
54 self._size = i16(s, 418), i16(s, 416)
55
56 # get channel/depth descriptions
57 mode = i16(s, 424), i16(s, 426)
58
59 if mode == (14, 2):
60 self._mode = "RGB"
61 # FIXME: to be continued...
62
63 # create tile descriptor (assuming "dumped")
64 self.tile = [("raw", (0, 0) + self.size, 1024, (self.mode, 0, 1))]
65
66
67#
68# --------------------------------------------------------------------
69
70Image.register_open(PixarImageFile.format, PixarImageFile, _accept)
71
72Image.register_extension(PixarImageFile.format, ".pxr")