[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ff-cvs] libvob ./Makefile vob/color/spaces.py vob/demo/...
From: |
Tuomas J. Lukka |
Subject: |
[ff-cvs] libvob ./Makefile vob/color/spaces.py vob/demo/... |
Date: |
Mon, 22 Sep 2003 04:49:01 -0400 |
CVSROOT: /cvsroot/libvob
Module name: libvob
Branch:
Changes by: Tuomas J. Lukka <address@hidden> 03/09/22 04:49:01
Modified files:
. : Makefile
vob/color : spaces.py
vob/demo/lava : color.py
Added files:
lava/usertest : color6.jvk
vob/color : CIE_standard_observer.py matrix.py
vob/demo/lava : chroma.py gamma.py
vob/usertest : color6.py
Log message:
Arch sync
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/Makefile.diff?tr1=1.45&tr2=1.46&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/lava/usertest/color6.jvk?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/color/CIE_standard_observer.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/color/matrix.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/color/spaces.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/demo/lava/chroma.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/demo/lava/gamma.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/demo/lava/color.py.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/usertest/color6.py?rev=1.1
Patches:
Index: libvob/Makefile
diff -u libvob/Makefile:1.45 libvob/Makefile:1.46
--- libvob/Makefile:1.45 Sat Aug 16 05:04:54 2003
+++ libvob/Makefile Mon Sep 22 04:49:00 2003
@@ -51,19 +51,21 @@
JYTHON=$(JAVA) $(JVMFLAGS) -Dpython.cachedir=. -Dpython.path=$(JYTHONPATH)
-Dpython.verbose=message $(EDITOR_OPTION) org.python.util.jython
endif
+# Have to use params for find for it not to descend into the {arch} dirs.
+FINDSRC=[a-zA-Z0-9]*
clean:
- find -name "*.gen.*"|xargs rm -f
- find -name "*.dep" |xargs rm -f
- find -name "*.bin" |xargs rm -f
- find -name "*.generated.*"|xargs rm -f
- find -name "*.o" |xargs rm -f
- find -name "*.class" |xargs rm -f
- find -name "*.transjniobj" |xargs rm -f
- find -name "*.vobjniobj" |xargs rm -f
+ find $(FINDSRC) -name "*.gen.*"|xargs rm -f
+ find $(FINDSRC) -name "*.dep" |xargs rm -f
+ find $(FINDSRC) -name "*.bin" |xargs rm -f
+ find $(FINDSRC) -name "*.generated.*"|xargs rm -f
+ find $(FINDSRC) -name "*.o" |xargs rm -f
+ find $(FINDSRC) -name "*.class" |xargs rm -f
+ find $(FINDSRC) -name "*.transjniobj" |xargs rm -f
+ find $(FINDSRC) -name "*.vobjniobj" |xargs rm -f
# remove files where "gen" or "dep" is in last suffix
- find -regex ".+\.[^.]*gen[^.]*" |xargs rm -f
- find -regex ".+\.[^.]*dep[^.]*" |xargs rm -f
+ find $(FINDSRC) -regex ".+\.[^.]*gen[^.]*" |xargs rm -f
+ find $(FINDSRC) -regex ".+\.[^.]*dep[^.]*" |xargs rm -f
rm -f src/jni/Generator
rm -f org/nongnu/libvob/gl/GLRen.java
rm -f org/nongnu/libvob/impl/gl/GLVobCoorder_Gen.java
Index: libvob/vob/color/spaces.py
diff -u libvob/vob/color/spaces.py:1.4 libvob/vob/color/spaces.py:1.5
--- libvob/vob/color/spaces.py:1.4 Sun Sep 14 06:46:53 2003
+++ libvob/vob/color/spaces.py Mon Sep 22 04:49:01 2003
@@ -1,7 +1,7 @@
#
-# Copyright (c) 2003, Janne Kujala
+# Copyright (c) 2003, Janne V. Kujala
#
-# This file is part of Gzz.
+# This file is part of Libvob.
#
# Gzz is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by
@@ -23,10 +23,26 @@
# Some color space conversions
+from __future__ import nested_scopes
+
import math
-# The gamma used for converting linear RGB to monitor RGB
+from matrix import *
+
+# CIE1931 x,y-chromaticity coordinates of the
+# red, green and blue phosphors of the monitor
+# used in RGB <-> XYZ conversions
+
+R = .64,.33 # these are the HDTV/sRGB/EBU/ITU primaries
+G = .30,.60
+B = .15,.06
+
+# coordinates of the white point (i.e., R = G = B = 1) --
+# this determines the relative luminances of the primaries
+# W = .312713,.329016 # = D65 standard illuminant
+W = .3127268660,.3290235126 # = D65 standard illuminant [CIE 15.2, p.55]
+# The gamma used for converting linear RGB to monitor RGB
gamma = 2.2
# The uncorrected display gamma of PC's is typically 2.2, i.e.,
@@ -38,34 +54,89 @@
def linear_to_monitor(rgb):
def f(x):
- if x < 0: return 0
+ if x < 0: return -f(-x)
return x**(1.0/gamma)
return (f(rgb[0]), f(rgb[1]), f(rgb[2]))
def monitor_to_linear(rgb):
def f(x):
- if x < 0: return 0
+ if x < 0: return -f(-x)
return x**gamma
+
+
return (f(rgb[0]), f(rgb[1]), f(rgb[2]))
-# RGB709 <-> CIE XYZ conversions
+
+def normalize(col):
+ sum = 0.0
+ for c in col:
+ sum += c
+ return [ c / sum for c in col ]
+
+
+def D(T):
+ """Return x,y coordinates of the CIE D illuminant specified by T
+
+ 4000 <= T <= 25000 is the correlated color temperature
+ """
+ if T <= 7000:
+ x = -4.6070E9 * T**-3. + 2.9678E6 * T**-2. + 0.09911E3 * T**-1. +
0.244063
+ else:
+ x = -2.0064E9 * T**-3. + 1.9018E6 * T**-2. + 0.24748E3 * T**-1. +
0.237040
+ y = -3.000 * x**2. + 2.870 * x - 0.275
+
+ return x,y
+
+def init():
+ global R,G,B,W,Wr,Wg,Wb,RGBtoXYZmat,XYZtoRGBmat
+ # Compute z-coordinates
+ R = (R[0], R[1], 1 - R[0] - R[1])
+ G = (G[0], G[1], 1 - G[0] - G[1])
+ B = (B[0], B[1], 1 - B[0] - B[1])
+ W = (W[0], W[1], 1 - W[0] - W[1])
+
+ # Compute luminance weights for the primaries using the white point
+ Wr = (R[1] * det([W,G,B])) / (W[1] * det([R,G,B]))
+ Wg = (G[1] * det([R,W,B])) / (W[1] * det([R,G,B]))
+ Wb = (B[1] * det([R,G,W])) / (W[1] * det([R,G,B]))
+
+ RGBtoXYZmat = transpose((mul(Wr / R[1], R),
+ mul(Wg / G[1], G),
+ mul(Wb / B[1], B)))
+
+ XYZtoRGBmat = inverse(RGBtoXYZmat)
+
+init()
+
+def set_temp(T):
+ global W
+ W = D(T)
+ init()
+
+#print RGBtoXYZmat[0]
+#print RGBtoXYZmat[1]
+#print RGBtoXYZmat[2]
+#print
+#print XYZtoRGBmat[0]
+#print XYZtoRGBmat[1]
+#print XYZtoRGBmat[2]
+
+# RGB <-> CIE XYZ conversions
def RGBtoXYZ(v):
- mat = [[ 0.412453, 0.35758 , 0.180423],
- [ 0.212671, 0.71516 , 0.072169],
- [ 0.019334, 0.119193, 0.950227]];
-
- return [ mat[0][0] * v[0] + mat[0][1] * v[1] + mat[0][2] * v[2],
- mat[1][0] * v[0] + mat[1][1] * v[1] + mat[1][2] * v[2],
- mat[2][0] * v[0] + mat[2][1] * v[1] + mat[2][2] * v[2] ]
+ #mat = [[ 0.412453, 0.35758 , 0.180423],
+ # [ 0.212671, 0.71516 , 0.072169],
+ # [ 0.019334, 0.119193, 0.950227]];
+
+ return matvecmul(RGBtoXYZmat, v)
def XYZtoRGB(v):
- mat = [[ 3.240479,-1.53715 ,-0.498535],
- [-0.969256, 1.875991, 0.041556],
- [ 0.055648,-0.204043, 1.057311]];
- return [ (mat[0][0] * v[0] + mat[0][1] * v[1] + mat[0][2] * v[2]),
- (mat[1][0] * v[0] + mat[1][1] * v[1] + mat[1][2] * v[2]),
- (mat[2][0] * v[0] + mat[2][1] * v[1] + mat[2][2] * v[2]) ]
+ #mat = [[ 3.240479,-1.53715 ,-0.498535],
+ # [-0.969256, 1.875991, 0.041556],
+ # [ 0.055648,-0.204043, 1.057311]];
+
+ return matvecmul(XYZtoRGBmat, v)
+
# CIE L*a*b* conversions
@@ -108,6 +179,53 @@
return XYZtoRGB(XYZ);
+
+# CIE L*u*v* conversions
+
+def XYZtoUCS(XYZ):
+ X,Y,Z = XYZ
+ u_ = 4. * X / (X + 15 * Y + 3 * Z)
+ v_ = 9. * Y / (X + 15 * Y + 3 * Z)
+ return Y, u_, v_
+
+def UCStoXYZ(Yu_v_):
+ Y,u_,v_ = Yu_v_
+ x, y = UCStoCIE1931(u_, v_)
+ z = 1 - x - y
+ s = Y / y
+ return s * x, s * y, s * z
+
+
+def CIE1931toUCS(x, y):
+ u_ = 4. * x / (-2 * x + 12 * y + 3)
+ v_ = 9. * y / (-2 * x + 12 * y + 3)
+ return u_, v_
+
+def UCStoCIE1931(u_, v_):
+ x = 6.75 * u_ / (4.5 * u_ - 12 * v_ + 9)
+ y = 3.00 * v_ / (4.5 * u_ - 12 * v_ + 9)
+ return x, y
+
+def RGBtoLUV(RGB):
+ Y, u_, v_ = XYZtoUCS(RGBtoXYZ(RGB))
+ Yn,un_,vn_ = XYZtoUCS(RGBtoXYZ([1,1,1]))
+
+ L = YtoL(Y / Yn)
+ U = 13 * L * (u_ - un_)
+ V = 13 * L * (v_ - vn_)
+
+ return L, U, V
+
+def LUVtoRGB(LUV):
+ Yn,un_,vn_ = XYZtoUCS(RGBtoXYZ([1,1,1]))
+
+ Y = LtoY(LUV[0]) * Yn
+ u_ = LUV[1] / (13 * LUV[0]) + un_
+ v_ = LUV[2] / (13 * LUV[0]) + vn_
+
+ return XYZtoRGB(UCStoXYZ((Y, u_, v_)))
+
+
def LABhue(RGB):
LAB = RGBtoLAB(RGB)
return math.atan2(LAB[2],LAB[1])
@@ -124,47 +242,6 @@
def getL(rgb): return RGBtoLAB(rgb)[0]
-def getRandomColor(minL, maxL, rnd):
- """Get a random color deterministically.
-
- minL, maxL: minimum and maximum luminance value
- rnd: a random number generator, corresponding to
- java.util.Random for the API. The same color
- is always returned if the PRNG returns the
- same list of values.
- """
- rgb = [-1]
- while len(filter((lambda x: x<0 or x>1), rgb)) > 0:
- L = minL + (maxL - minL) * rnd.nextDouble()
- a = 200 * rnd.nextDouble() - 100
- b = 200 * rnd.nextDouble() - 100
- # XXX: (a,b) is sampled from a square
- rgb = LABtoRGB([L,a,b])
- return rgb
-
-def getRandomColor2(minL, maxL, rnd):
- """Get a random color deterministically with uniformly distributed hue.
-
- minL, maxL: minimum and maximum luminance value
- rnd: a random number generator, corresponding to
- java.util.Random for the API. The same color
- is always returned if the PRNG returns the
- same list of values.
- """
- rgb = [-1]
- L = minL + (maxL - minL) * rnd.nextDouble()
- ang = rnd.nextDouble() * 2 * math.pi
- r = rnd.nextDouble() * 100
- # XXX: used to be "r = 100" producing only saturated colors!
- # XXX: sampling saturation from the uniform distribution
- # is not necessarily ideal
- a = r * math.cos(ang)
- b = r * math.sin(ang)
- rgb = LABtoRGB([L,a,b])
-
- return LABclamp(rgb)
-
-
def inUnit(vec):
"""Tests whether the vector is inside the unit cube [0,1]^n"""
return len(filter((lambda x: x<0 or x>1), vec)) == 0
@@ -194,37 +271,31 @@
# The YST color space below is a linear color space with
# a luminance component and a color plane vector whose angle and
# radius specify the hue and saturation, respectively.
-# Opposite colors are 180 degrees apart.
#
# The Y component is the CIE Y luminance (but the weights can be changed) and
# the ST-plane has the RGB primaries 120 (R = 0, G = 120, B = 240) degrees
apart
# at radius 1.
#
# Luminance weights of the RGB primaries used in YST color space functions
-Wr = 0.212671
-Wg = 0.715160
-Wb = 0.072169
-
-#Wr,Wg,Wb = 0.3, 0.59, 0.11
+#Wr = 0.212671
+#Wg = 0.715160
+#Wb = 0.072169
+#Note: the weigths are computed from the values specified at the beginning
+#of this file
def YSTtoRGB(v):
- n = 1.0 / (Wr+Wg+Wb)
- mat = [ [n, n*(Wg+Wb), n*(Wb - Wg) / math.sqrt(3) ],
- [n, n*(-Wr), n*(2*Wb + Wr) / math.sqrt(3) ],
- [n, n*(-Wr), n*-(2*Wg + Wr) / math.sqrt(3) ] ]
+ mat = [ [1, Wg+Wb, (Wb - Wg) / math.sqrt(3) ],
+ [1, -Wr, (2*Wb + Wr) / math.sqrt(3) ],
+ [1, -Wr, -(2*Wg + Wr) / math.sqrt(3) ] ]
- return [ mat[0][0] * v[0] + mat[0][1] * v[1] + mat[0][2] * v[2],
- mat[1][0] * v[0] + mat[1][1] * v[1] + mat[1][2] * v[2],
- mat[2][0] * v[0] + mat[2][1] * v[1] + mat[2][2] * v[2] ]
+ return matvecmul(mat, v)
def RGBtoYST(v):
mat = [[ Wr, Wg, Wb ],
[ 1, -.5, -.5],
[ 0, .5*math.sqrt(3), -.5*math.sqrt(3) ]]
- return [ mat[0][0] * v[0] + mat[0][1] * v[1] + mat[0][2] * v[2],
- mat[1][0] * v[0] + mat[1][1] * v[1] + mat[1][2] * v[2],
- mat[2][0] * v[0] + mat[2][1] * v[1] + mat[2][2] * v[2] ]
+ return matvecmul(mat, v)
def maxYSTsat(YST):
"""Return the maximum saturation factor in RGB cube of the given color"""
@@ -276,6 +347,6 @@
returns: luminance between 0 and 1
"""
if L <= 8:
- return pow(L * (27./24389), 1.0)
+ return L * (27./24389)
else:
return pow((L + 16.0) / 116, 3.0)
Index: libvob/vob/demo/lava/color.py
diff -u libvob/vob/demo/lava/color.py:1.3 libvob/vob/demo/lava/color.py:1.4
--- libvob/vob/demo/lava/color.py:1.3 Mon Sep 1 10:03:36 2003
+++ libvob/vob/demo/lava/color.py Mon Sep 22 04:49:01 2003
@@ -27,54 +27,29 @@
from vob.putil.demokeys import *
from vob.paper.texcache import getCachedTexture
-#from vob.color.spaces import YSTtoRGB,gamma
-
-# Luminance weights of the RGB primaries used in YST color space functions
-Wr = 0.212671
-Wg = 0.715160
-Wb = 0.072169
-
-#Wr,Wg,Wb = 0.3, 0.59, 0.11
-
-# Gamma correction used with the perceptual non-linearity in YtoL and LtoY
-# conversion functions.
-#
-gamma = 2.2
-#
-# The uncorrected display gamma of PC's is typically 2.2, i.e.,
-# RGB values map to physical intensities with an exponent of 2.2.
-# So, gamma correction of 2.2 here should result in linear
-# intensity. (The CIE L* computation assumes linear intensity).
-
-def YSTtoRGB(v):
- n = 1.0 / (Wr+Wg+Wb)
- mat = [ [n, n*(Wg+Wb), n*(Wb - Wg) / math.sqrt(3) ],
- [n, n*(-Wr), n*(2*Wb + Wr) / math.sqrt(3) ],
- [n, n*(-Wr), n*-(2*Wg + Wr) / math.sqrt(3) ] ]
-
- return [ mat[0][0] * v[0] + mat[0][1] * v[1] + mat[0][2] * v[2],
- mat[1][0] * v[0] + mat[1][1] * v[1] + mat[1][2] * v[2],
- mat[2][0] * v[0] + mat[2][1] * v[1] + mat[2][2] * v[2] ]
+import vob.color.spaces
+from vob.color.spaces import YSTtoRGB,gamma,set_temp,linear_to_monitor
+#set_temp(6500)
def getcol(l, x, y):
col = YSTtoRGB( (l, x, y) )
- col = map(lambda x: x**(1./gamma), col)
+ col = linear_to_monitor(col)
return col
class Scene:
+ """Color circle"""
def __init__(self):
self.key = KeyPresses(
self,
- SlideLin("l1", 200, 20, "l1", "Left", "Right"),
- SlideLin("l2", 300, 20, "l2", "Up", "Down"),
+ SlideLin("c", .5, .1, "chroma", "Left", "Right"),
+ SlideLin("Y", .5, .05, "luminance", "Down", "Up"),
SlideLin("ang", 0, .1, "Rotation", "Prior", "Next"),
)
def scene(self, vs):
-
- vs.put( background( getcol(.4, 0, 0) ) )
+ vs.put( background( getcol(self.Y, 0, 0) ) )
code = """
Begin QUAD_STRIP
@@ -89,7 +64,7 @@
x = math.cos(a)
y = math.sin(a)
- col = getcol(.4, .41 * x, .41 * y)
+ col = getcol(self.Y, self.c * x, self.c * y)
for i in range(0,3):
if col[i] < min[i]: min[i] = col[i]
@@ -108,6 +83,6 @@
print "MIN: %5.3f %5.3f %5.3f" % tuple(min)
print "MAX: %5.3f %5.3f %5.3f" % tuple(max)
- cs = vs.orthoCS(0, "cs1", 0, 512, 384, 300, 300);
+ cs = vs.orthoCS(0, "cs1", 0, 512, 384, 300, -300);
vs.map.put(getDList(code), cs)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [ff-cvs] libvob ./Makefile vob/color/spaces.py vob/demo/...,
Tuomas J. Lukka <=