These old snippets of mine might give you some ideas.
http://forum.thegamecreators.com/?m=forum_view&t=32791&b=6
http://forum.thegamecreators.com/?m=forum_view&t=32327&b=6
There was a fairly large image library by Kenmo (I think) that did all sorts of image manipulation. I can't seem to find it.
Managed to find one of my old snippets:
load image "D:\Programming\Dark Basic\DBPro Source\michelangelo57.jpg", 1
make memblock from image 1, 1
make memblock from image 2, 1
rem get image data
imageWidth = memblock dword(1, 0)
imageHeight = memblock dword(1, 4)
imageDepth = memblock dword(1, 8)
memSize = get memblock size(1)
rem filter matrix
dim filter(5,5)
restore Emboss
for x = 1 to 5
for y = 1 to 5
read z
filter(x, y) = z
next y
next x
read filterScale
read filterOffset
rem loop through every pixel in source image
for x = 1 to imageWidth
for y = 1 to imageHeight
rem variables used for storing the added weights
r0 = 0
g0 = 0
b0 = 0
rem apply filter
for i = -2 to 2
for j = -2 to 2
x3 = x+i
y3 = y+j
weight = filter(i+3, j+3)
rem cells with 0 weight in the filter are not calculated into filtering process
rem it would not influence the result in anyway, but it would be needless calculations
if weight <> 0
rem make sure to stay within image bounds when checking surrounding pixels
if x3 > 0 and x3 <= imageWidth and y3 > 0 and y3 <= imageHeight
rem extract the color components for this pixel
pos = ((y3-1)*imageWidth + x3-1)*4 + 12
b = memblock byte(1, pos)
g = memblock byte(1, pos+1)
r = memblock byte(1, pos+2)
rem multiple pixel by the filter weight
r0 = r0 + r*weight
g0 = g0 + g*weight
b0 = b0 + b*weight
endif
endif
next j
next i
rem divide the weighted total by the filter scale and add the filter offset
r0 = r0 / filterScale + filterOffset
g0 = g0 / filterScale + filterOffset
b0 = b0 / filterScale + filterOffset
rem set the filter pixel into memblock 2
pos = ((y-1)*imageWidth + x-1)*4 + 12
write memblock dword 2, pos, rgb(r0,g0,b0)
next y
next x
make image from memblock 2, 2
rem ======================
rem For demo purposes only
rem ======================
sync on
autocam off
backdrop on
position camera 0,0,0
make object plain 1, 300,300
position object 1, -160,0,400
texture object 1, 1
make object plain 2, 300,300
position object 2, 160,0,400
texture object 2,2
do
set cursor 0,0
print "FPS: ",screen fps()
sync
loop
rem ======================
rem End demo-only code
rem ======================
rem ======================
rem Filter data
rem ======================
Blur:
data 1, 1, 1, 1, 1
data 1, 1, 1, 1, 1
data 1, 1, 1, 1, 1
data 1, 1, 1, 1, 1
data 1, 1, 1, 1, 1
data 25,0
Gaussian:
data 1, 1, 1, 1, 1
data 1, 2, 2, 2, 1
data 1, 2, 3, 2, 1
data 1, 2, 2, 2, 1
data 1, 1, 1, 1, 1
data 32, 0
Gaussian2:
data 4, 4, 4, 4, 4
data 4, 8, 8, 8, 4
data 4, 8, 1, 8, 4
data 4, 8, 8, 8, 4
data 4, 4, 4, 4, 4
data 129, 0
Sharpen:
data 0, 0, 0, 0, 0
data 0, 0,-1, 0, 0
data 0,-1, 5,-1, 0
data 0, 0,-1, 0, 0
data 0, 0, 0, 0, 0
data 1, 0
Emboss:
data 0, 0, 0, 0, 0
data 0, 0, 0, 0, 0
data 0, 0, 1, 0, 0
data 0, 0, 0,-1, 0
data 0, 0, 0, 0, 0
data 1, 128
Invert:
data 0, 0, 0, 0, 0
data 0, 0, 0, 0, 0
data 0, 0,-1, 0, 0
data 0, 0, 0, 0, 0
data 0, 0, 0, 0, 0
data 1, 255
rem increase scale to darken image
rem 100 = normal, 200 = half brightness, 300 = 1/3 brightness
Darken:
data 0, 0, 0, 0, 0
data 0, 0, 0, 0, 0
data 0, 0,100,0, 0
data 0, 0, 0, 0, 0
data 0, 0, 0, 0, 0
data 300,0