Manipulating imagedata - quickest technique?
David Bovill
david at openpartnership.net
Mon Apr 3 09:21:28 EDT 2006
David Burgun wrote:
> I wrote an External Command to do image processing work. It is *way*
> faster than doing it in TranScript. It also implemented an image cache.
>
> If you want to write an External Command, I can give you some pointers.
That would be very useful David. For this example - writing an external
for image contrast and brightness - how long would it take - that is for
someone who knows how to do it :)
Mark Smith wrote:
> on doLighten imageName
>
...
> repeat for each line L in the keys of pixArray
> put min(pixArray[L] * 1.5,255) into pixArray[L]
> end repeat
...
> end doLighten
Thanks for the code Mark...
A question about how "lighten" works... I have some functions for HSV to
RGB conversion (they are a bit old and am sure can be optimized) - using
HSV sliders on individual colours - I get - but as i don't have
photoshop installed here - I am not sure how it should work with an image?
If I change a Velocity slider for an image does it:
a) set all velocity values for each pixel to the new value
b) multiply each existing pixel velocity value by a percentage
change and then set
Oh and why should multiplying each rgb value by 1.5 lighten an image?
function colour_RGBtoHSV r, g, b
-- version original,10/3/03
if g is empty then
put item 3 of r into b
put item 2 of r into g
put item 1 of r into r
end if
colour_ConvertRGBtoHSV r, g, b, h, s, v
return h,s,v
end colour_RGBtoHSV
function colour_HSVtoRGB h, s, v
-- version original,10/3/03
if s is empty then
put item 3 of h into v
put item 2 of h into s
put item 1 of h into h
end if
colour_ConvertHSVtoRGB h, s, v, r, g, b
return r,g,b
end colour_HSVtoRGB
on colour_ConvertRGBtoHSV r, g, b, @h, @s, @v
set the numberFormat to "0.###############"
put r / 255 into r
put g / 255 into g
put b / 255 into b
put max(r,g,b) into maxv
put min(r,g,b) into minv
put maxv - minv into diff
if maxv <> 0 and diff <> 0 then
put diff / maxv into s
put (maxv - r) / diff into rc
put (maxv - g) / diff into gc
put (maxv - b) / diff into bc
if r = maxv then put bc - gc into h
else if g = maxv then put 2 + rc - bc into h
else if b = maxv then put 4 + gc - rc into h
multiply h by 60
if h < 0 then
add 360 to h
end if
else
put 0 into s
put 0 into h
end if
put round(h) into h
put round(s * 100) into s
put round(maxv * 100) into v
end colour_ConvertRGBtoHSV
on colour_ConvertHSVtoRGB h, s, v, @r, @g, @b
set the numberFormat to "0.###############"
divide s by 100
divide v by 100
if s is 0 then put v,v,v into rgb
else
divide h by 60
put trunc(h) into i
put h - i into f
put v * (1 - s) into p
put v * (1 - s * f) into q
put v * (1 - s * (1- f)) into t
if i is 0 then put v,t,p into rgb
if i is 1 then put q,v,p into rgb
if i is 2 then put p,v,t into rgb
if i is 3 then put p,q,v into rgb
if i is 4 then put t,p,v into rgb
if i is 5 then put v,p,q into rgb
end if
put round(item 1 of rgb * 255) into r
put round(item 2 of rgb * 255) into g
put round(item 3 of rgb * 255) into b
end colour_ConvertHSVtoRGB
More information about the use-livecode
mailing list