1. Re: converting bitmaps to use standard palette and still look goo
Lewis wrote:
> Does anyone know how to get this [palette conversion]
> function to work or has anyone already written something
> that does this or know of one?
Pete has a program on his home page that does this using assembly. I've
written a version in "pure" Euphoria. It's passed a sequence of RGB tuples,
and returns a list of indexes to the current palette that are the "closest"
match.
Hope this helps!
-- David Cuny
----------------------------------------------------------------------------
--
function convertToPalette( sequence rgbList )
-- convert the color list to palette indexes
integer best, err
sequence pal, colorIndex
-- get palette
pal = get_all_palette()
-- build holder for results
colorIndex = repeat( 0, length( rgbList ) )
-- look at each entry
for i = 1 to length( rgbList ) do
-- set the last best match as impossibly bad
best = #FF
-- look through the palette
for j = 1 to length( pal ) do
-- error amount for this entry
err = 0
-- for each {rgb}
for k = 1 to 3 do
-- error is difference between the two
err = err + abs( pal[j][k] - rgbList[i][k] )
end for
-- better match than prior best match?
if err <= best then
-- save error amount
best = err
-- store the palette index
colorIndex[i] = j-1
end if
end for
end for
return colorIndex
end function
----------------------------------------------------------------------------
--