2013-10-11 17:28:32 +00:00
|
|
|
#
|
|
|
|
# The Python Imaging Library.
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# PCD file handling
|
|
|
|
#
|
|
|
|
# History:
|
|
|
|
# 96-05-10 fl Created
|
|
|
|
# 96-05-27 fl Added draft mode (128x192, 256x384)
|
|
|
|
#
|
|
|
|
# Copyright (c) Secret Labs AB 1997.
|
|
|
|
# Copyright (c) Fredrik Lundh 1996.
|
|
|
|
#
|
|
|
|
# See the README file for information on usage and redistribution.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2014-09-30 16:15:32 +00:00
|
|
|
from PIL import Image, ImageFile, _binary
|
|
|
|
|
2015-11-25 01:25:01 +00:00
|
|
|
__version__ = "0.1"
|
|
|
|
|
2014-09-30 16:15:32 +00:00
|
|
|
i8 = _binary.i8
|
2013-10-11 17:28:32 +00:00
|
|
|
|
2015-11-25 01:25:01 +00:00
|
|
|
|
2013-10-11 17:28:32 +00:00
|
|
|
##
|
|
|
|
# Image plugin for PhotoCD images. This plugin only reads the 768x512
|
|
|
|
# image from the file; higher resolutions are encoded in a proprietary
|
|
|
|
# encoding.
|
|
|
|
|
|
|
|
class PcdImageFile(ImageFile.ImageFile):
|
|
|
|
|
|
|
|
format = "PCD"
|
|
|
|
format_description = "Kodak PhotoCD"
|
|
|
|
|
|
|
|
def _open(self):
|
|
|
|
|
|
|
|
# rough
|
|
|
|
self.fp.seek(2048)
|
|
|
|
s = self.fp.read(2048)
|
|
|
|
|
2014-09-30 16:15:32 +00:00
|
|
|
if s[:4] != b"PCD_":
|
|
|
|
raise SyntaxError("not a PCD file")
|
2013-10-11 17:28:32 +00:00
|
|
|
|
2014-09-30 16:15:32 +00:00
|
|
|
orientation = i8(s[1538]) & 3
|
2013-10-11 17:28:32 +00:00
|
|
|
if orientation == 1:
|
2015-11-25 01:25:01 +00:00
|
|
|
self.tile_post_rotate = 90 # hack
|
2013-10-11 17:28:32 +00:00
|
|
|
elif orientation == 3:
|
|
|
|
self.tile_post_rotate = -90
|
|
|
|
|
|
|
|
self.mode = "RGB"
|
2015-11-25 01:25:01 +00:00
|
|
|
self.size = 768, 512 # FIXME: not correct for rotated images!
|
|
|
|
self.tile = [("pcd", (0, 0)+self.size, 96*2048, None)]
|
2013-10-11 17:28:32 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# registry
|
|
|
|
|
2015-11-25 01:25:01 +00:00
|
|
|
Image.register_open(PcdImageFile.format, PcdImageFile)
|
2013-10-11 17:28:32 +00:00
|
|
|
|
2015-11-25 01:25:01 +00:00
|
|
|
Image.register_extension(PcdImageFile.format, ".pcd")
|