Code: Select all
Function AddMatrixColor(img,mtrx,border As Byte=0)
w = ImageWidth(img)-1
h = ImageHeight(img)-1
img2 = MakeImage(w+1,h+1)
size = MEMBlockSize(mtrx)
mtrxX = PeekShort(mtrx,size-4)
mtrxY = PeekShort(mtrx,size-2)
mtrxW = PeekShort(mtrx,size-8)
mtrxH = PeekShort(mtrx,size-6)
Lock Image(img)
Lock Image(img2)
For x = 0 To w
For y = 0 To h
If x < mtrxX Or y < mtrxY Or w-x < mtrxW-mtrxX-1 Or h-y < mtrxH-mtrxY-1 Then
If border Then
PickImageColor2 img,x,y
PutPixel2 x,y,getRGB(BLUE)+(getRGB(GREEN) Shl 8) + (getRGB(BLUE) Shl 16),Image(img2)
EndIf
Else
r# = 0
g# = 0
b# = 0
For x2 = -mtrxX To mtrxW-mtrxX-1
For y2 = -mtrxY To mtrxH-mtrxY-1
PickImageColor2 img,x+x2,y+y2
m# = PeekFloat(mtrx,((x2+mtrxX)+(y2+mtrxY)*mtrxW)*4)
r# = r# + Float(getRGB(RED))*m#
g# = g# + Float(getRGB(GREEN))*m#
b# = b# + Float(getRGB(BLUE))*m#
Next y2
Next x2
r2 = Max(0,Min(255,r#))
g2 = Max(0,Min(255,g#))
b2 = Max(0,Min(255,b#))
PutPixel2 x,y,b2 + (g2 Shl 8) + (r2 Shl 16),Image(img2)
EndIf
Next y
Next x
Unlock Image(img)
Unlock Image(img2)
Return img2
EndFunction
Function AddMatrix(img,mtrx,border As Byte=0)
w = ImageWidth(img)-1
h = ImageHeight(img)-1
img2 = MakeImage(w+1,h+1)
size = MEMBlockSize(mtrx)
mtrxX = PeekShort(mtrx,size-4)
mtrxY = PeekShort(mtrx,size-2)
mtrxW = PeekShort(mtrx,size-8)
mtrxH = PeekShort(mtrx,size-6)
Lock Image(img)
Lock Image(img2)
For x = 0 To w
For y = 0 To h
If x < mtrxX Or y < mtrxY Or w-x < mtrxW-mtrxX-1 Or h-y < mtrxH-mtrxY-1 Then
If border Then
PutPixel2 x,y,GetPixel2(x,y,Image(img)),Image(img2)
EndIf
Else
r# = 0
g# = 0
b# = 0
For x2 = -mtrxX To mtrxW-mtrxX-1
For y2 = -mtrxY To mtrxH-mtrxY-1
PickImageColor2 img,x+x2,y+y2
m# = PeekFloat(mtrx,((x2+mtrxX)+(y2+mtrxY)*mtrxW)*4)
r# = r# + Float(getRGB(RED))*m#
g# = g# + Float(getRGB(GREEN))*m#
b# = b# + Float(getRGB(BLUE))*m#
Next y2
Next x2
sum = Max(0,Min(255,(r#+g#+b#)/3))
PutPixel2 x,y,sum + (sum Shl 8) + (sum Shl 16),Image(img2)
EndIf
Next y
Next x
Unlock Image(img)
Unlock Image(img2)
Return img2
EndFunction
Function MakeBlurMatrix()
mtrx = MakeMEMBlock(44)
PokeFloat mtrx,0,0:PokeFloat mtrx,4,0.2:PokeFloat mtrx,8,0
PokeFloat mtrx,12,0.2:PokeFloat mtrx,16,0.2:PokeFloat mtrx,20,0.2
PokeFloat mtrx,24,0:PokeFloat mtrx,28,0.2:PokeFloat mtrx,32,0
PokeShort mtrx,36,3:PokeShort mtrx,38,3
PokeShort mtrx,40,1:PokeShort mtrx,40,1
Return mtrx
EndFunction
Function MakeEdgeEnhanceMatrix(force# = 1)
mtrx = MakeMEMBlock(16)
PokeFloat mtrx,0,-1*force#:PokeFloat mtrx,4,2*force#
PokeShort mtrx,8,2:PokeShort mtrx,10,1
PokeShort mtrx,12,1:PokeShort mtrx,14,0
Return mtrx
EndFunction
Function MakeSharpenMatrix(force# = 1)
mtrx = MakeMEMBlock(44)
PokeFloat mtrx,0,0:PokeFloat mtrx,4,-1*force#:PokeFloat mtrx,8,0
PokeFloat mtrx,12,-1*force#:PokeFloat mtrx,16,4*force#:PokeFloat mtrx,20,-1*force#
PokeFloat mtrx,24,0:PokeFloat mtrx,28,-1*force#:PokeFloat mtrx,32,0
PokeShort mtrx,36,3:PokeShort mtrx,38,3
PokeShort mtrx,40,1:PokeShort mtrx,40,1
Return mtrx
EndFunction
Function MakeEmbossMatrix(force# = 1)
mtrx = MakeMEMBlock(44)
PokeFloat mtrx,0,-2*force#:PokeFloat mtrx,4,-1*force#:PokeFloat mtrx,8,0
PokeFloat mtrx,12,-1*force#:PokeFloat mtrx,16,1*force#:PokeFloat mtrx,20,1*force#
PokeFloat mtrx,24,0:PokeFloat mtrx,28,1*force#:PokeFloat mtrx,32,2*force#
PokeShort mtrx,36,3:PokeShort mtrx,38,3
PokeShort mtrx,40,1:PokeShort mtrx,40,1
Return mtrx
EndFunction
Function MakeEdgeDetectMatrix(force# = 1)
mtrx = MakeMEMBlock(44)
PokeFloat mtrx,0,0:PokeFloat mtrx,4,1*force:PokeFloat mtrx,8,0
PokeFloat mtrx,12,1*force#:PokeFloat mtrx,16,-4*force#:PokeFloat mtrx,20,1*force#
PokeFloat mtrx,24,0:PokeFloat mtrx,28,1*force#:PokeFloat mtrx,32,0
PokeShort mtrx,36,3:PokeShort mtrx,38,3
PokeShort mtrx,40,1:PokeShort mtrx,40,1
Return mtrx
EndFunction
SCREEN 600,400
img = LoadImage("Media/tileset.bmp")
mtrx = MakeBlurMatrix()
img2 = AddMatrixColor(img,mtrx)
DrawImage img,0,0
DrawImage img2,300,0
DrawScreen
WaitKey
Sisältää valmiiksi 5 matriisia kuvan käsittelyyn. mm. terävöittämiseen ja reunojen etsintään.
Matriisin voi lisätä kuvaan joko väreillä(AddMatrixColor) tai harmaa sävyillä(AddMatrix)
Vielä kun joku keksii miten kannattaisi tehdä reunat... Tällä hetkellä funktio ei piirrä reunoja tai piirtää ne muokkaamattomina...
En nyt ehdi selittelemään enempää pitää mennä pihatöihin.