< Previous | Contents | Next >

Example

image

local p = Pixel() local histoR = {} local histoG = {} local histoB = {} local histoA = {}

local r,g,b,a

-- initialise the histogram table for i = 0,255 do

histoR[i] = 0

histoG[i] = 0

histoB[i] = 0

histoA[i] = 0

end

for y=0,Height-1 do

if self.Status ~= "OK" then break end

for x=0,Width-1 do

img:GetPixel(x,y, p)

-- convert float 0..1 values into int 0.255 r = math.floor(p.R * 255)

g = math.floor(p.G * 255) b = math.floor(p.B * 255)

a = math.floor(p.A * 255)

-- check for out-of-range colors

if r >= 0 and r <= 255 then histoR[r] = histoR[r] + 1 end

A simple 8 bit histogram function



if

g

>=

0

and

g

<=

255

then

histoG[g]

=

histoG[g]

+

1

end

if

b

>=

0

and

b

<=

255

then

histoB[b]

=

histoB[b]

+

1

end

if

a

>=

0

and

a

<=

255

then

histoA[a]

=

histoA[a]

+

1

end


end
















end