Here's an example I've just knocked up:
// Project: Make Greyscale
// Created: 2020-12-31
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Make Greyscale" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
img1 = LoadImage("1_IDLE_004.png")
img2 = LoadImage("1_IDLE_004.png")
spr1 = CreateSprite(img1)
SetSpritePosition(spr1, 0, 200)
spr2 = CreateSprite(img2)
SetSpritePosition(spr2, GetSpriteWidth(spr1), 200)
do
Print("Press <1> to convert to greyscale based on RED channel")
Print("Press <2> to convert to greyscale based on GREEN channel")
Print("Press <3> to convert to greyscale based on BLUE channel")
Print("Press <4> to convert to greyscale based on ALPHA channel")
Print("Press <5> to convert to greyscale based on average colour")
Print("Press <SPACE> to reset colour")
for k = 1 to 5
if GetRawKeyPressed(k+48)
MakeGreyscale(spr2, k)
endif
next k
if GetRawKeyPressed(32)
SetSpriteImage(spr2, LoadImage("1_IDLE_004.png"))
endif
Sync()
loop
function MakeGreyscale(spr, mode)
img = GetSpriteImageID(spr)
mb = CreateMemblockFromImage(img)
size = GetMemblockSize(mb)
for k = 12 to size-4 step 4
b = GetMemblockByte(mb, k)
g = GetMemblockByte(mb, k+1)
r = GetMemblockByte(mb, k+2)
a = GetMemblockByte(mb, k+3)
select mode
case 1
SetMemblockByte(mb, k, r)
SetMemblockByte(mb, k+1, r)
SetMemblockByte(mb, k+2, r)
endcase
case 2
SetMemblockByte(mb, k, g)
SetMemblockByte(mb, k+1, g)
SetMemblockByte(mb, k+2, g)
endcase
case 3
SetMemblockByte(mb, k, b)
SetMemblockByte(mb, k+1, b)
SetMemblockByte(mb, k+2, b)
endcase
case 4
SetMemblockByte(mb, k, a)
SetMemblockByte(mb, k+1, a)
SetMemblockByte(mb, k+2, a)
endcase
case 5
avg = (r+g+b)/3
SetMemblockByte(mb, k, avg)
SetMemblockByte(mb, k+1, avg)
SetMemblockByte(mb, k+2, avg)
endcase
endselect
next k
CreateImageFromMemblock(img, mb)
DeleteMemblock(mb)
endfunction
I used the attached image which is FREE on craftpix.net but it works with any image