Here's my attempt at a solution to a color changer - Hope you find it useful.
Click on the color to change. Set the new color in the ChangeColors function.
Images for this demo are attached.
// ------------------------------------------- //
// Project: image_utils_6
// Description: Simple image color changer
// ------------------------------------------- //
GLOBAL px%[] //buffer - global to be seen by functions
LOCAL mx,my,mbl,mbr
LOCAL currColor
LOCAL MBLDown = FALSE //is mouse button-left down?
//load the image
LOADSPRITE "colorbox.png", 1
//load cursor
LOADSPRITE "cursor.png", 2
//main process loop
WHILE TRUE
//get mouse info
MOUSESTATE mx, my, mbl, mbr
//display input image sprite
DRAWSPRITE 1, 0,0
//get pixel color under mouse - if left mouse button is NOT down
IF NOT mbl THEN currColor = GETPIXEL(mx,my)
//draw a rectangle to show current color
DRAWRECT 450,20, 100, 100, currColor
//if left mouse button then change color
IF mbl AND NOT MBLDown
ChangeColors(currColor)
MBLDown = TRUE
ENDIF
//if left mouse button up, reset indicator
IF NOT mbl THEN MBLDown = FALSE
//draw mouse cursor - Always draw last to appear on top
DRAWSPRITE 2,mx,my
SHOWSCREEN
WEND
FUNCTION ChangeColors: color#
LOCAL width%, height%
LOCAL newColor = RGB(0,0,0) //color for replacement
LOCAL abgr%, r%, g%, b%, a%
LOCAL cabgr%, cr%, cg%, cb%, ca%
//break down color components
cabgr = color
cr = bAND(cabgr, 0xff)
cg = bAND(ASR(cabgr,8), 0xff)
cb = bAND(ASR(cabgr,16), 0xff)
ca = bAND(ASR(cabgr,24), 0xff)
//get sprite info
GETSPRITESIZE 1, width, height
//drop into sprite into buffer
SPRITE2MEM (px[],1)
//replace all occurences of color, with newcolor
//since the buffer is one long entity, we just loop through the data in sequene
FOR i% = 0 TO (width*height)-1
//break down sprite color components
abgr% = px[i]
r = bAND(abgr, 0xff)
g = bAND(ASR(abgr,8), 0xff)
b = bAND(ASR(abgr,16), 0xff)
a = bAND(ASR(abgr,24), 0xff)
//test and change
IF r = cr AND g = cg AND b = cb
px[i] = newColor
ENDIF
NEXT
//put buffer back into sprite
MEM2SPRITE(px[], 1, width, height)
ENDFUNCTION
[attachment deleted by admin]