[cairo-commit] rcairo/src/lib/cairo color.rb, NONE, 1.1 context.rb,
1.2, 1.3 pattern.rb, NONE, 1.1
Kouhei Sutou
commit at pdx.freedesktop.org
Sun Apr 15 20:12:58 PDT 2007
Committed by: kou
Update of /cvs/cairo/rcairo/src/lib/cairo
In directory kemper:/tmp/cvs-serv27775/src/lib/cairo
Modified Files:
context.rb
Added Files:
color.rb pattern.rb
Log Message:
* src/lib/cairo/color.rb: added high-level color class including
CMYK support.
* src/rb_cairo_pattern.c, src/lib/cairo.rb,
src/lib/cairo/context.rb, src/lib/cairo/pattern.rb: supported
Cairo::Color.
--- NEW FILE: color.rb ---
module Cairo
module Color
class Base
end
class RGB < Base
def initialize(r, g, b, a=1.0)
@red = r
@green = g
@blue = b
@alpha = a
end
def to_a
[@red, @green, @blue, @alpha]
end
alias_method :to_ary, :to_a
def to_rgb
clone
end
def to_cmyk
cmy = [1.0 - @red, 1.0 - @green, 1.0 - @blue]
key_plate = cmy.min
if key_plate < 1.0
one_k = 1.0 - key_plate
cmyk = cmy.collect {|value| (value - key_plate) / one_k} + [key_plate]
else
cmyk = [0, 0, 0, key_plate]
end
cmyka = cmyk + [@alpha]
CMYK.new(*cmyka)
end
end
class CMYK < Base
def initialize(c, m, y, k, a=1.0)
@cyan = c
@magenta = m
@yellow = y
@key_plate = k
@alpha = a
end
def to_a
[@cyan, @magenta, @yellow, @key_plate, @alpha]
end
alias_method :to_ary, :to_a
def to_rgb
one_k = 1.0 - @key_plate
rgba = [
(1.0 - @cyan) * one_k,
(1.0 - @magenta) * one_k,
(1.0 - @yellow) * one_k,
@alpha,
]
RGB.new(*rgba)
end
def to_cmyk
clone
end
end
end
end
Index: context.rb
===================================================================
RCS file: /cvs/cairo/rcairo/src/lib/cairo/context.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- context.rb 15 Apr 2007 06:15:22 -0000 1.2
+++ context.rb 16 Apr 2007 03:12:49 -0000 1.3
@@ -3,6 +3,7 @@
require 'cairo/context/circle'
require 'cairo/context/path'
require 'cairo/context/blur'
+require 'cairo/context/color'
module Cairo
class Context
@@ -11,5 +12,6 @@
include Circle
include Path
include Blur
+ include Color
end
end
--- NEW FILE: pattern.rb ---
require 'cairo/color'
module Cairo
class SolidPattern
if method_defined?(:rgba)
def color
Color::RGB.new(*rgba)
end
end
end
class GradientPattern
def add_color_stop(*args)
if args.size == 1 and args.first.is_a?(Color)
add_color_stop_rgba(*args.first.to_rgb.to_a)
else
add_color_stop_rgba(*args)
end
end
if method_defined?(:get_color_stop_rgba)
def get_color_stop(index)
Color::RGB.new(*get_color_stop_rgba(index))
end
end
end
end
More information about the cairo-commit
mailing list