Hello,

I am trying to follow the instructions for "Writing you own file decoder" in the PIL Handbook. The file I wish to import is in 16 bit little endian unsigned int and has a 128 byte header at the beginning of the file (just like in the example).

After writting the decoder and placing it in the proper directory I can open the file with the Image.open method but then the load method fails with the ValueError: unrecognized mode

However, I am using the mode indicated for my file format

Below is a copy of my interactive session where I tried to load the file:

Python 2.4.1 (#1, Aug 24 2005, 11:19:07)
[GCC 4.0.0 20041026 (Apple Computer, Inc. build 4061)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Image
>>> im = Image.open("recobj_250.sdtt")
>>>
>>> im.mode
'F;16'
>>> im.load()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.4/site-packages/PIL/ImageFile.py", line 155, in load
    self.load_prepare()
File "/usr/local/lib/python2.4/site-packages/PIL/ImageFile.py", line 221, in load_prepare
    self.im = Image.core.new(self.mode, self.size)
ValueError: unrecognized mode

I have also attached a copy of my plug-in file. Thanks in advance for any help
#SdttImagePlugin.py

import Image, ImageFile
import string

class SdttImageFile(ImageFile.ImageFile):

	format = "SDTT"
	format_description = "SDTT format: See sdr_read.py"
	
	def _open(self):
	
		#check header
		header = self.fp.read(128)
		if header[:4] != "SDTT":
			raise SyntaxError, "not a SDTT file"
		
		header = string.split(header)
		
		# size in pixels (width, height)
		self.size = string.atoi(header[1]), string.atoi(header[2])
		
		# mode setting
		bits = int(header[3])
		if bits == 16:
			self.mode = "F;16"
		else:
			raise SyntaxError, "unknown number of bits"
		
		#data descriptor
		self.tile = [("raw", (0, 0) + self.size, 128, (self.mode, 0, 1))]
	
Image.register_open("SDTT", SdttImageFile)
	
Image.register_extension("SDTT", ".sdtt")
_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to