gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/gfx demo/color/colors.py libcolor/spaces.py...


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx demo/color/colors.py libcolor/spaces.py...
Date: Tue, 15 Oct 2002 04:28:36 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/10/15 04:28:36

Modified files:
        gfx/demo/color : colors.py 
        gfx/libcolor   : spaces.py 
        gfx/libpaper   : colors.py papermill.py 

Log message:
        cleanup

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/color/colors.py.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libcolor/spaces.py.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/colors.py.diff?tr1=1.15&tr2=1.16&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/papermill.py.diff?tr1=1.47&tr2=1.48&r1=text&r2=text

Patches:
Index: gzz/gfx/demo/color/colors.py
diff -c gzz/gfx/demo/color/colors.py:1.9 gzz/gfx/demo/color/colors.py:1.10
*** gzz/gfx/demo/color/colors.py:1.9    Mon Oct 14 13:49:30 2002
--- gzz/gfx/demo/color/colors.py        Tue Oct 15 04:28:35 2002
***************
*** 466,486 ****
          """
      
          for L in [5*r for r in range(10,20)]:
!             r,g,b = LABtoRGB((L, 0, 0))
              code += """
                  Begin TRIANGLE_FAN
                  Color %s %s %s
                  Vertex 0 0
              """ % (r, g, b)
  
!             for hue in [d * 5 for d in range(-18*2,18*2+1)]:
  
!                 angle0 = (hue / 180.0) * pi
!                 angle = getangle((hue + 360) % 360 / 360.0)
                  
!                 r,g,b = LABclamp(LABtoRGB((L, 100 * cos(angle), 100 * 
sin(angle))))
!                 lab = RGBtoLAB((r,g,b))
!                 radius = sqrt(lab[1]**2 + lab[2]**2) * .015
                  
                  x,y = radius * cos(angle0), radius * sin(angle0)
  
--- 466,497 ----
          """
      
          for L in [5*r for r in range(10,20)]:
!             Y = LtoY(L)
!             r,g,b = YSTtoRGB((Y, 0, 0))
              code += """
                  Begin TRIANGLE_FAN
                  Color %s %s %s
                  Vertex 0 0
              """ % (r, g, b)
  
!             # Add orange color to the color circle
!             def getangle(f):
!                 # 0 = red, 120 = green, 240 = blue
!                 angles = [ 0, 30, 60, 120, 180, 240, 300, 360 ]
!                 n = len(angles) - 1
!                 f *= n / 360.0
!                 while f < 0: f += n
!                 index = int(f) % n
!                 fract = f - int(f)
!                 return (1 - fract) * angles[index] + fract * angles[index + 1]
  
!             for hue in [d * 5 for d in range(-18*2,18*2+1)]:
!                 angle0 = hue / 180.0 * pi
!                 angle = getangle(hue) / 180.0 * pi
                  
!                 r,g,b = clampSat( YSTtoRGB((Y, cos(angle), sin(angle))))
!                 yst = RGBtoYST((r,g,b))
!                 radius = sqrt(yst[1]**2 + yst[2]**2) * 1.5
                  
                  x,y = radius * cos(angle0), radius * sin(angle0)
  
Index: gzz/gfx/libcolor/spaces.py
diff -c gzz/gfx/libcolor/spaces.py:1.10 gzz/gfx/libcolor/spaces.py:1.11
*** gzz/gfx/libcolor/spaces.py:1.10     Mon Oct 14 13:49:30 2002
--- gzz/gfx/libcolor/spaces.py  Tue Oct 15 04:28:36 2002
***************
*** 37,59 ****
      LAB = RGBtoLAB(RGB)
      return math.atan2(LAB[2],LAB[1])
  
- 
- 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]
- 
- 
  def abdiff(a, b):
      u = RGBtoLAB(a)
      v = RGBtoLAB(b)
--- 37,42 ----
***************
*** 147,152 ****
--- 130,137 ----
  Wg = 0.715160
  Wb = 0.072169
  
+ Wr,Wg,Wb = 0.3, 0.59, 0.11
+ 
  def YSTtoRGB(v):
      n = 1.0 / (Wr+Wg+Wb)
      mat =  [ [n, n*(Wg+Wb), n*(Wb - Wg)  / math.sqrt(3) ],
***************
*** 193,221 ****
      return YSTtoRGB((Y,r*S,r*T))
  
  
- 
  def YSThue(RGB):
      YST = RGBtoYST(RGB)
      return math.atan2(YST[2],YST[1])
  
  
  
! 
! """
! # Kluge: Emulate LAB color space using YST hues
! angles = map(YSThue, colors)
! angles = map(lambda a: a + (a < 0) * 2 * math.pi, angles)
! angles.sort()
! angles += [angles[0] + 2 * math.pi]
! 
! LABclamp = clampSat
! LABtoRGB = lambda lab: YSTtoRGB((lab[0]*.01,lab[1]*.01,lab[2]*.01))
! 
! 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)
! """
--- 178,206 ----
      return YSTtoRGB((Y,r*S,r*T))
  
  
  def YSThue(RGB):
      YST = RGBtoYST(RGB)
      return math.atan2(YST[2],YST[1])
  
  
+ def YtoL(Y):
+     """
+     Convert linear luminance into perceptual lightness (CIE L*)
+     Y: lightness between 0 and 1
+     returns: luminance between 0 and 100
+     """
+     if Y <= (216./24389):
+         return Y * (24389./27)
+     else:
+         return 116 * pow(Y, 1./3) - 16
  
! def LtoY(L):
!     """
!     Convert perceptual lightness (CIE L*) into linear luminance
!     L: luminance between 0 and 100
!     returns: lightness between 0 and 1
!     """
!     if L <= 8:
!         return L * (27./24389)
!     else:
!         return pow((L + 16.0) / 116, 3)
Index: gzz/gfx/libpaper/colors.py
diff -c gzz/gfx/libpaper/colors.py:1.15 gzz/gfx/libpaper/colors.py:1.16
*** gzz/gfx/libpaper/colors.py:1.15     Mon Oct 14 13:49:30 2002
--- gzz/gfx/libpaper/colors.py  Tue Oct 15 04:28:36 2002
***************
*** 1,6 ****
  # Choosing colors and 3-dotproduct factors for papers.
  
! from gfx.libcolor.spaces import 
getRandomColor,getRandomColor2,YSTtoRGB,clampSat
  from gfx.libcolor.spaces import RGBtoLAB,LABtoRGB,LABclamp
  
  from math import sin,cos,atan2,pi,log
--- 1,6 ----
  # Choosing colors and 3-dotproduct factors for papers.
  
! from gfx.libcolor.spaces import 
getRandomColor,getRandomColor2,YSTtoRGB,clampSat,LtoY
  from gfx.libcolor.spaces import RGBtoLAB,LABtoRGB,LABclamp
  
  from math import sin,cos,atan2,pi,log
***************
*** 58,67 ****
                  for i in range(0, colors)]
  
          # Construct colors and clamp to RGB cube keeping hue and luminance 
constant
!         yst = [(pow((lums[i] + 16.0) / 116, 3),
!                 sats[i] * cos(hues[i]*pi/180),
!                 sats[i] * sin(hues[i]*pi/180))
!                for i in range(0,colors)]
                     
          col = [clampSat(YSTtoRGB(c)) for c in yst]
          shuffle(col, rnd.nextDouble)
--- 58,67 ----
                  for i in range(0, colors)]
  
          # Construct colors and clamp to RGB cube keeping hue and luminance 
constant
!         yst = [ ( LtoY(lums[i]),
!                   sats[i] * cos(hues[i]*pi/180),
!                   sats[i] * sin(hues[i]*pi/180) )
!                 for i in range(0,colors)]
                     
          col = [clampSat(YSTtoRGB(c)) for c in yst]
          shuffle(col, rnd.nextDouble)
Index: gzz/gfx/libpaper/papermill.py
diff -c gzz/gfx/libpaper/papermill.py:1.47 gzz/gfx/libpaper/papermill.py:1.48
*** gzz/gfx/libpaper/papermill.py:1.47  Mon Oct 14 03:35:09 2002
--- gzz/gfx/libpaper/papermill.py       Tue Oct 15 04:28:36 2002
***************
*** 144,150 ****
                  else:
                      setDummyPass(pap.getPass(i))
  
!         if dbg: pap.reg.dump()
          return pap
          
      def makePaperPass(self, reg, ppass, colors, textures, rootrep, trans = 0, 
emboss = 0):
--- 144,150 ----
                  else:
                      setDummyPass(pap.getPass(i))
  
!         #if dbg: pap.reg.dump()
          return pap
          
      def makePaperPass(self, reg, ppass, colors, textures, rootrep, trans = 0, 
emboss = 0):




reply via email to

[Prev in Thread] Current Thread [Next in Thread]