/[gzz]/gzz/gfx/libcolor/spaces.py
ViewVC logotype

Diff of /gzz/gfx/libcolor/spaces.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by jvk, Mon Oct 14 17:49:30 2002 UTC revision 1.11 by jvk, Tue Oct 15 08:28:36 2002 UTC
# Line 37  def LABhue(RGB): Line 37  def LABhue(RGB):
37      LAB = RGBtoLAB(RGB)      LAB = RGBtoLAB(RGB)
38      return math.atan2(LAB[2],LAB[1])      return math.atan2(LAB[2],LAB[1])
39    
   
 colors = [ (1,0,0), (1,.5,0),  
            (1,1,0), #(.5,1,0),  
            (0,1,0), (0,1,1),  
            (0,0,1), (1,0,1) ]  
 angles = map(LABhue, colors)  
 angles = map(lambda a: a + (a < 0) * 2 * math.pi, angles)  
 angles.sort()  
 angles += [angles[0] + 2 * math.pi]  
   
 def getangle(f):  
     f *= len(colors)  
     index = int(f) % len(colors)  
     fract = f - int(f)  
     return (1 - fract) * angles[index] + fract * angles[index + 1]  
   
   
40  def abdiff(a, b):  def abdiff(a, b):
41      u = RGBtoLAB(a)      u = RGBtoLAB(a)
42      v = RGBtoLAB(b)      v = RGBtoLAB(b)
# Line 147  Wr = 0.212671 Line 130  Wr = 0.212671
130  Wg = 0.715160  Wg = 0.715160
131  Wb = 0.072169  Wb = 0.072169
132    
133    Wr,Wg,Wb = 0.3, 0.59, 0.11
134    
135  def YSTtoRGB(v):  def YSTtoRGB(v):
136      n = 1.0 / (Wr+Wg+Wb)      n = 1.0 / (Wr+Wg+Wb)
137      mat =  [ [n, n*(Wg+Wb), n*(Wb - Wg)  / math.sqrt(3) ],      mat =  [ [n, n*(Wg+Wb), n*(Wb - Wg)  / math.sqrt(3) ],
# Line 193  def clampSat(rgb): Line 178  def clampSat(rgb):
178      return YSTtoRGB((Y,r*S,r*T))      return YSTtoRGB((Y,r*S,r*T))
179    
180    
   
181  def YSThue(RGB):  def YSThue(RGB):
182      YST = RGBtoYST(RGB)      YST = RGBtoYST(RGB)
183      return math.atan2(YST[2],YST[1])      return math.atan2(YST[2],YST[1])
184    
185    
186    def YtoL(Y):
187        """
188        Convert linear luminance into perceptual lightness (CIE L*)
189        Y: lightness between 0 and 1
190        returns: luminance between 0 and 100
191        """
192        if Y <= (216./24389):
193            return Y * (24389./27)
194        else:
195            return 116 * pow(Y, 1./3) - 16
196    
197    def LtoY(L):
198  """      """
199  # Kluge: Emulate LAB color space using YST hues      Convert perceptual lightness (CIE L*) into linear luminance
200  angles = map(YSThue, colors)      L: luminance between 0 and 100
201  angles = map(lambda a: a + (a < 0) * 2 * math.pi, angles)      returns: lightness between 0 and 1
202  angles.sort()      """
203  angles += [angles[0] + 2 * math.pi]      if L <= 8:
204            return L * (27./24389)
205  LABclamp = clampSat      else:
206  LABtoRGB = lambda lab: YSTtoRGB((lab[0]*.01,lab[1]*.01,lab[2]*.01))          return pow((L + 16.0) / 116, 3)
   
 def RGBtoLAB(rgb):  
     yst = RGBtoYST(rgb)  
     return [ -16 + 116 * pow(yst[0], 1./3), 100 * yst[1], 100 * yst[2] ]  
   
 def LABtoRGB(lab):  
     yst = [ pow((lab[0] + 16.0) / 116, 3), lab[1] / 100.0, lab[2] / 100.0 ]  
     return YSTtoRGB(yst)  
 """  

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26