# HG changeset patch # User Fredrik Lundh # Date 1237273274 -3600 # Branch openexr # Node ID b690bc800a00ee4b29d5b4e4571910578bf627e3 # Parent 454b4d2672f38b368713d1f3365c6fff62597620 Added OpenEXR plugin (identify only). diff -r 454b4d2672f38b368713d1f3365c6fff62597620 -r b690bc800a00ee4b29d5b4e4571910578bf627e3 CONTENTS --- a/CONTENTS Tue Mar 17 07:33:41 2009 +0100 +++ b/CONTENTS Tue Mar 17 08:01:14 2009 +0100 @@ -159,6 +159,7 @@ Imaging/PIL/MpegImagePlugin.py Imaging/PIL/MspImagePlugin.py Imaging/PIL/OleFileIO.py +Imaging/PIL/OpenExrImagePlugin.py Imaging/PIL/PaletteFile.py Imaging/PIL/PalmImagePlugin.py Imaging/PIL/PcdImagePlugin.py diff -r 454b4d2672f38b368713d1f3365c6fff62597620 -r b690bc800a00ee4b29d5b4e4571910578bf627e3 PIL/OpenExrImagePlugin.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PIL/OpenExrImagePlugin.py Tue Mar 17 08:01:14 2009 +0100 @@ -0,0 +1,137 @@ +# +# The Python Imaging Library. +# $Id$ +# +# OpenEXR file handler (work in progress) +# +# history: +# 2009-03-16 fl Created (identify only) +# +# Copyright (c) 2009 by Fredrik Lundh +# +# See the README file for information on usage and redistribution. +# + +import struct +import Image, ImageFile + +# Image.DEBUG = 2 + +class AttributeStream: + def __init__(self, fp): + self.fp = fp + self.buf = "" + def readstr(self): + while "\0" not in self.buf: + s = self.fp.read(512) + if not s: + raise SyntaxError("unexpected end of file") + self.buf = self.buf + s + value, self.buf = self.buf.split("\0", 1) + return value + def read(self, size): + if len(self.buf) < size: + s = self.fp.read(size - len(self.buf)) + if not s: + raise SyntaxError("unexpected end of file") + self.buf = self.buf + s + value, self.buf = self.buf[:size], self.buf[size:] + return value + +def chlist(x): + channels = [] + while x: + name, x = x.split("\0", 1) + if not name: + break + type, linear, x_sampling, y_sampling = struct.unpack("<4i", x[:16]) + x = x[16:] + channels.append((name, type, linear, (x_sampling, y_sampling))) + return channels + +class preview: + def __init__(self, x): + self.mode = "RGBA" + self.size = struct.unpack("<4I", x[:8]) + self.data = x[8:] + def __repr__(self): + return "" % (self.mode, self.size, id(self)) + +converters = dict( + box2f=lambda x: struct.unpack("<4f", x), + box2i=lambda x: struct.unpack("<4i", x), + chlist=chlist, + chromacities=lambda x: struct.unpack("<8f", x), + compression=ord, + double=lambda x: struct.unpack("