fb:porticula NoPaste
Bildervergleicher
Uploader: | csde_rats |
Datum/Zeit: | 22.12.2010 22:30:33 |
' Copyright 2010 Marian Beermann (www.marianbeermann.de)
' Mal auf die schnelle fürs 3dc-forum gefrickelt
' http://www.forum-3dcenter.org/vbulletin/showthread.php?p=8464171&posted=1#post8464171
#Include "crt.bi"
Type TGAHeader Field=1
As Byte idlen
As Byte cmtype
As Byte imtype
As UShort cmorg
As UShort cmcnt
As Byte cmsize
As UShort imxorg
As UShort imyorg
As UShort imwidth
As UShort imheight
As Byte imdepth
As Byte imdes
End Type
Type pixel
As UByte red
As UByte blue
As UByte green
As UByte alpha
End Type
Dim Shared As Integer gWidth, gHeight
Sub main()
Dim As String inFile, outFile, inFile2
Dim As TGAHeader tga
Dim As ULong bytesRead
Dim As Integer x, y
Dim As Any Ptr descBytes
Dim As pixel pix, refpix
Dim As pixel Ptr srcImage, srcImage2, dstImage
inFile = Command(1)
inFile2 = Command(2)
outFile = Command(3)
Open inFile For Binary As #1
Open outFile For Binary As #2
Open inFile2 For Binary As #3
Get #1, , tga
Put #2, , tga
descBytes = Cast(UByte Ptr, Allocate(SizeOf(UByte) * tga.idlen))
Get #1, , tga.idlen
Put #2, , tga.idlen
gWidth = tga.imwidth
gHeight = tga.imheight
srcImage = Cast(pixel Ptr, Allocate(SizeOf(pixel) * gHeight * gWidth))
srcImage2 = Cast(pixel Ptr, Allocate(SizeOf(pixel) * gHeight * gWidth))
dstImage = Cast(pixel Ptr, Allocate(SizeOf(pixel) * gHeight * gWidth))
For y = 0 To gHeight
For x = 0 To gWidth
Get #1, , pix.blue
Get #1, , pix.green
Get #1, , pix.red
Get #3, , refpix.blue
Get #3, , refpix.green
Get #3, , refpix.red
If tga.imdepth = 32 Then
Get #1, , pix.alpha
Get #3, , refpix.alpha
Else
pix.alpha = 0
refpix.alpha = 0
EndIf
'Or _
' ( _
' ( _
' (pix.red < (refpix.red + refpix.red * TOL)) And _
' (pix.blue < (refpix.blue + refpix.blue * TOL)) And _
' (pix.green < (refpix.green + refpix.green * TOL)) _
' ) _
' And _
' ( _
' (pix.red > (refpix.red - refpix.red * TOL)) And _
' (pix.blue > (refpix.blue - refpix.blue * TOL)) And _
' (pix.green > (refpix.green - refpix.green * TOL)) _
' ) _
' ) _
Dim TOL As Double = 0.2
If _
( _
( _
(pix.red = refpix.red) And _
(pix.blue = refpix.blue) And _
(pix.green = refpix.green) _
) _
) _
Then
pix.blue = 0
pix.green = 0
pix.alpha = 0
pix.red = 0
Else
pix.blue = 0
pix.green = 255
pix.alpha = 0
pix.red = 0
EndIf
Put #2, , pix.blue
Put #2, , pix.green
Put #2, , pix.red
If tga.imdepth = 32 Then
Put #2, , pix.alpha
EndIf
Next x
Next y
DeAllocate(srcImage)
DeAllocate(dstImage)
DeAllocate(descBytes)
Close #1, #2, #3
End Sub
main()
End