Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/PIL/PcdImagePlugin.py: 97%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#
2# The Python Imaging Library.
3# $Id$
4#
5# PCD file handling
6#
7# History:
8# 96-05-10 fl Created
9# 96-05-27 fl Added draft mode (128x192, 256x384)
10#
11# Copyright (c) Secret Labs AB 1997.
12# Copyright (c) Fredrik Lundh 1996.
13#
14# See the README file for information on usage and redistribution.
15#
16from __future__ import annotations
18from . import Image, ImageFile
20##
21# Image plugin for PhotoCD images. This plugin only reads the 768x512
22# image from the file; higher resolutions are encoded in a proprietary
23# encoding.
26class PcdImageFile(ImageFile.ImageFile):
27 format = "PCD"
28 format_description = "Kodak PhotoCD"
30 def _open(self) -> None:
31 # rough
32 assert self.fp is not None
34 self.fp.seek(2048)
35 s = self.fp.read(1539)
37 if not s.startswith(b"PCD_"):
38 msg = "not a PCD file"
39 raise SyntaxError(msg)
41 orientation = s[1538] & 3
42 self.tile_post_rotate = None
43 if orientation == 1:
44 self.tile_post_rotate = 90
45 elif orientation == 3:
46 self.tile_post_rotate = 270
48 self._mode = "RGB"
49 self._size = (512, 768) if orientation in (1, 3) else (768, 512)
50 self.tile = [ImageFile._Tile("pcd", (0, 0, 768, 512), 96 * 2048)]
52 def load_prepare(self) -> None:
53 if self._im is None and self.tile_post_rotate:
54 self.im = Image.core.new(self.mode, (768, 512))
55 ImageFile.ImageFile.load_prepare(self)
57 def load_end(self) -> None:
58 if self.tile_post_rotate:
59 # Handle rotated PCDs
60 self.im = self.rotate(self.tile_post_rotate, expand=True).im
63#
64# registry
66Image.register_open(PcdImageFile.format, PcdImageFile)
68Image.register_extension(PcdImageFile.format, ".pcd")