[GEM-dev] Why is [hsv2rgb] implemented as an abstraction?
Frank Barknecht
fbar at footils.org
Tue Dec 11 15:44:13 CET 2007
Hallo,
Frank Barknecht hat gesagt: // Frank Barknecht wrote:
> Chris McCormick hat gesagt: // Chris McCormick wrote:
>
> > As the resident abstractions-over-externals obsessive, I feel I should
> > put forward an argument to the contrary, just for good measure.
>
> A speed comparison with a lua/python implementation would be
> interesting. You'd still be able to quickly change it or use it as a
> base for other objects without recompiling.
Okay, I wrote a quick one using the markex code as a starting point.
It would be interesting to benchmark this with Claude's patch against
the pd-abstraction. (There's also a pdlua question for Claude hidden
inside.)
Ciao
--
Frank Barknecht _ ______footils.org__
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lhsv2rgb-help.pd
Type: application/puredata
Size: 1598 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/gem-dev/attachments/20071211/e35d2853/attachment.bin>
-------------- next part --------------
-- hsv2rgb class: almost copied from the markex object hsv2rgb
-- fbar 2007
-- Pd class:
local function FLOAT_CLAMP(f)
if f > 1 then
return 1
elseif f < 0 then
return 0
else
return f
end
end
local M = pd.Class:new():register("lhsv2rgb")
function M:initialize(name, atoms)
self.inlets = 1
self.outlets = 1
return true
end
function M:doit(h, s, v)
local r=0
local g=0
local b=0
h = FLOAT_CLAMP(h)
s = FLOAT_CLAMP(s)
v = FLOAT_CLAMP(v)
-- convert hue to degrees
h = h * 360
if s == 0.0 then -- black and white
r = v
g = v
b = v
else
if (h == 360) then h = 0 end -- 360 == 0 degrees
h = h / 60 -- hue is now [0, 6]
local i = math.floor(h)
local f = h - i -- f is the fractional part of h
local p = v * (1 - s)
local q = v * (1 - s * f)
local t = v * (1 - s * (1 - f))
if i == 0 then
r = v
g = t
b = p
elseif i == 1 then
r = q
g = v
b = p
elseif i == 2 then
r = p
g = v
b = t
elseif i == 3 then
r = p
g = q
b = v
elseif i == 4 then
r = t
g = p
b = v
elseif i == 5 then
r = v
g = p
b = q
end
end
-- Claude: Why can't I do this here::
-- self:outlet(1, "list", {r,g,b})
return {r,g,b}
end
function M:in_1_list(args)
if #args >= 3 then
self:outlet(1, "list", M:doit(unpack(args)))
end
end
More information about the GEM-dev
mailing list