[PYTHON IMAGE-SIG] PIL and palettes and drawing.

Anthony Baxter Anthony Baxter <arb@connect.com.au>
Wed, 18 Dec 1996 00:16:11 +1100


------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <4788.850828567.1@connect.com.au>

>>> Fredrik Lundh wrote
> Does What I Want as well.  I'll add some "wellknown colour names", a
> few standard palettes that I have somewhere, and eliminate the need
> for attach.  Stay tuned for a 0.2b4 (early January, probably).

Oops, I left a debugging 'print' in the code that I sent to the list.
Ah well.

I was planning on making it possible to use the X11 rgb colours if they
are available.  Quick hacky patch to my previously posted ImagePalette
is at the end of this mail.

> My current priorities wrt. palette-aware formats:
> 	1. fix PNG write support
> 	2. redesign the TIFF writer; its not very good as it stands

These two would be Really Nice. If the TIFF writer works, I can play
with plugging it into our fax gateway here. Ooo - the possibilities
are endless (and quite twisted :)

>          [GIF writing]
> 	   Same rules apply to everyone using PIL to write an
> 	   application...  I'm tempted to add a "not to be used
> 	   for any purpose by Unisys" to the PIL license...)

Sounds like a plan to me. :)

Anthony


------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <4788.850828567.2@connect.com.au>
Content-Description: add RGB dbm handling to ImagePalette

*** ImagePalette.py.orig	Wed Dec 18 00:04:26 1996
--- ImagePalette.py	Wed Dec 18 00:12:50 1996
***************
*** 14,19 ****
--- 14,21 ----
  import array
  import Image
  
+ Colours={}
+ 
  class ImagePalette:
  
      def __init__(self,mode="RGB",palette=None):
***************
*** 36,54 ****
      def set(self,num,col):
  	if type(col) is type(()):
  	    r,g,b=col
- 	    self.palette[0+(num*3)] = r
- 	    self.palette[1+(num*3)] = g
- 	    self.palette[2+(num*3)] = b
- 	    return None
  	if type(col) is type(''):
  	    if col[0] == '#' and len(col) == 7:
  		import string
! 		self.palette[0+(num*3)] = string.atoi(col[1:3],16)
! 		self.palette[1+(num*3)] = string.atoi(col[3:5],16)
! 		self.palette[2+(num*3)] = string.atoi(col[5:7],16)
! 		return None
! 	    # handle UNIX rgb.txt?
! 	raise ValueError,"not a valid colour setting"
  
      def attach(self,image):
  	import string
--- 38,58 ----
      def set(self,num,col):
  	if type(col) is type(()):
  	    r,g,b=col
  	if type(col) is type(''):
  	    if col[0] == '#' and len(col) == 7:
  		import string
! 		r = string.atoi(col[1:3],16)
! 		g = string.atoi(col[3:5],16)
! 		b = string.atoi(col[5:7],16)
! 	    if Colours and len(Colours) and Colours.has_key(col):
! 		(r,g,b) = Colours[col]
! 
! 	try:
! 	    self.palette[0+(num*3)] = r
! 	    self.palette[1+(num*3)] = g
! 	    self.palette[2+(num*3)] = b
! 	except:
! 	    raise ValueError,"not a valid colour"
  
      def attach(self,image):
  	import string
***************
*** 99,105 ****
   
  # add some psuedocolour palettes as well
  
! 	
  
  def test():
      im=Image.open("ltest.gif")
--- 103,115 ----
   
  # add some psuedocolour palettes as well
  
! def RGBdbm(file="/usr/openwin/lib/rgb"):
!     import dbm
!     df=dbm.open(file)
!     for i in df.keys():
! 	Colours[i]=(ord(df[i][0]),ord(df[i][2]),ord(df[i][4]))
!     df.close()
! 
  
  def test():
      im=Image.open("ltest.gif")

------- =_aaaaaaaaaa0--

=================
IMAGE-SIG - SIG on Image Processing with Python

send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org
=================