First, a big thanks Grindstone. I really wanted to understand this subject, and help files won't go in depth. I agree to your corrections but have now some little comments.
About the End return value, it is in the documentation. Apparently End won't clean the things properly unless returning a value. Seriously, I don't understand why that and I'm just following the help file here. And I've noticed others programs ending this way.
Of course, but here again following the doc, each row is "padded" with some 16 bits or something like that. So what does it mean? That's rather unclear, and I've translated this by :
...
Obviously you're right again, but documentation says that for accessing pixel data (for customizing Put method and so on) you have to skip header named
Ok, Static is just a keyword I like. I've decided using it for global variable just as a convention - if of course no bad side effect is to be expected.
Yes Grindstone, you can use RGB statement even for 8 bits. At least for 8 bits just write RGB( X, X, color from 0 to 15). The 2 first places are not used as far as I've been testing.
Yes, I'm just doing this for posting code. My goal is to divide the source in as much include as necerssary for clarity.
Now Grindstone, as I didn't know if I would get a so quick and clean answer, I've been making this tool for screenPtr study !
The 2 last functions of the whole code can hold a custom ScreenPtr reader.
Code: Select all
''
''SCanning Screen and ScreenPtr comparatively
''
#Include "fbgfx.bi"
Static Shared As Integer w, h, d, bpp, pitch
Declare Function GetGraphicsParameter() As Integer
Declare Function DataSize() As Integer
Function GetGraphicsParameter() As Integer
ScreenInfo w, h , d, bpp, pitch
Return Cast(Integer, ScreenPtr())
End Function 'INT := GetGraphicsParameter()
Function DataSize() As Integer
GetGraphicsParameter()
DataSize = (((w * bpp + &hF) and not &hF) * h) ''from documentation
End Function 'INT := DataSize()
Type CROSSHAIR
Declare Sub DecreaseSweeperLength()
Declare Sub IncreaseSweeperLength()
Declare Sub DrawMethod(ByVal _CenterColor As ULong =-1)
As UInteger _sweeperLength = 0
As UInteger _length = 10
As Single _x = 0
As Single _y = 0
As Single _dx = 0
As Single _dy = 0
As ULong _color = RGB(15, 15, 15)
End Type 'CROSSHAIR
Sub CROSSHAIR.DecreaseSweeperLength()
This._sweeperLength -= 1 * ((This._sweeperLength <= 4)+1)
End Sub 'CROSSHAIR.DecreaseSweeperLength()
Sub CROSSHAIR.IncreaseSweeperLength()
This._sweeperLength += 1 * ((This._sweeperLength > 100)+1)
End Sub 'CROSSHAIR.IncreaseSweeperLength()
Sub CROSSHAIR.DrawMethod(ByVal _CenterColor As ULong =-1)
Dim As UInteger _l = This._length
If Abs(This._length) < 4 Then _l = 4
With This
Line (._x-4, ._y-._sweeperLength)-(._x+4, ._y-._sweeperLength), ._color
Line (._x-4, ._y+._sweeperLength)-(._x+4, ._y+._sweeperLength), ._color
Line (._x-_l, ._y)-(._x-4, ._y), ._color
Line (._x+4, ._y)-(._x+_l, ._y), ._color
Line (._x, ._y-_l)-(._x, ._y-4), ._color
Line (._x, ._y+4)-(._x, ._y+_l), ._color
Line (._x-4, ._y-4)-(._x-4, ._y+4), ._color
Line (._x-4, ._y-4)-(._x+4, ._y-4), ._color
Line (._x-4, ._y+4)-(._x+4, ._y+4), ._color
Line (._x+4, ._y+4)-(._x+4, ._y-4), ._color
End With 'This
If _CenterColor <>-1 Then
Circle (This._x, This._y), _l, _CenterColor
Circle (This._x, This._y), 0.7*4, _CenterColor + 1+Rnd*4
Line (This._x-0.7*_l, This._y-0.7*_l)-(This._x+0.7*_l, This._y+0.7*_l), _CenterColor
Line (This._x-0.7*_l, This._y+0.7*_l)-(This._x+0.7*_l, This._y-0.7*_l), _CenterColor
EndIf
End Sub 'CROSSHAIR.DrawMethod()
Declare Function DrawBackGround(ByVal ImageToDraw As FB.IMAGE Ptr =0) As Integer
Declare Sub ViewReport()
Enum _MOVEDIRECTION
_noMove = 0
_up = 1
_down = 2
_left = 3
_right = 4
_fastUp = 1
_fastDown = 2
_fastLeft = 3
_fastRight = 4
End Enum '_MOVEDIRECTION
Declare Function MoveCross(ByVal Movdir As _MOVEDIRECTION = 0) As Integer
Declare Function UserAccessToScreenPtr1() As ULong
Declare Function UserAccessToScreenPtr2() As ULong
''-----------------------------------------------------Init()
''Initialize graphics screen
ScreenRes 600, 350, 8, 4
''Get this screen address
Static Shared As Any Ptr mainScrPtr
mainScrPtr = ScreenPtr()
Static Shared As UByte activeScreen
activeScreen = 0
''Set BackGround
GetGraphicsParameter()
Color ,RGB(bpp*8, bpp*8, 3*bpp)
Cls
? "Screen " & w &"x"& h &"x"& d
? "BPP " & bpp
? "PITCH " & pitch
? "PixelData_Row size " & -(Int(-w/16))*16
? "PixelData size " & DataSize()
? : ? "[ESC] to quit"
? "[SPACE] to see sweeped area"
? "[ENTER]/[BACK]"
? "to Deploy/Shrink sweeper"
For _i As Integer = 0 To 30
Circle (w\2, h\2), (( w + h - Abs( w - h) ) / 2 +_i)/3
Paint (w\2, h\2), 1, 15
Next _i
View ( 1 , h*0.9 ) - ( w-2, h-2 ), RGB(d*5/8, d*5/8, d*5/8), RGB(d*1/8, d*1/8, d*1/8)
View Screen
''Store BackGround
Static Shared As FB.IMAGE Ptr backGroundImage(0 To 4)
backGroundImage(0) = ImageCreate(w, h, , d)
backGroundImage(1) = ImageCreate(w\2, h\2, , d)
backGroundImage(2) = ImageCreate(w\2, h\2, , d)
backGroundImage(3) = ImageCreate(w\2, h\2, , d)
backGroundImage(4) = ImageCreate(w\2, h\2, , d)
Get (0,0)-(w-1, h-1), backGroundImage(0)
Get (0,0)-(w\2-1, h\2-1), backGroundImage(1)
Get (w\2, 0)-(w-1, h\2-1), backGroundImage(2)
Get (w\2, h\2)-(w-1, h-1), backGroundImage(3)
Get (0, h\2)-(w\2-1, h-1), backGroundImage(4)
''ResultImage
Static Shared As FB.IMAGE Ptr resultImage
resultImage = ImageCreate(w, h, , d)
''Naive ProcessedImage
Static Shared As FB.IMAGE Ptr processedImage
processedImage = ImageCreate(w, h, , d)
''User ProcessedImage
Static Shared As FB.IMAGE Ptr userProcessedImage(1 To 2)
userProcessedImage(1) = ImageCreate(w, h, , d)
userProcessedImage(2) = ImageCreate(w, h, , d)
''Set CrossHair
Static Shared As CROSSHAIR cross
With cross
._x = w\2
._y = h\2
._length = 20
._color = RGB(d*15/8, d*15/8, d*15/8)
._sweeperLength = 20
End With 'cross
cross.DrawMethod()
''ProcessingCursorImage
Static Shared As FB.IMAGE Ptr ProcessingCursorImage
processingCursorImage = ImageCreate(5, 2*cross._sweeperLength+1, , d)
''-----------------------------------------------------Main()
resultImage = BackGroundImage(0)
Do
If MultiKey(FB.SC_ENTER) Or MultiKey(FB.SC_D)Then
While InKey<>"" : Wend
cross.IncreaseSweeperLength
EndIf
If MultiKey(FB.SC_BACKSPACE) Or MultiKey(FB.SC_S) Then
While InKey<>"" : Wend
cross.DecreaseSweeperLength
EndIf
If MultiKey(FB.SC_SPACE) Then
While InKey<>"" : Wend
Sleep 100
Select Case resultImage
Case BackGroundImage(0)
ScreenSet 1,1
activeScreen = 1
resultImage = processedImage
Sleep 100
Exit Select
Case processedImage
ScreenSet 2,2
activeScreen = 2
resultImage = userProcessedImage(1)
Sleep 100
Exit Select
Case userProcessedImage(1)
ScreenSet 3,3
activeScreen = 3
resultImage = userProcessedImage(2)
Sleep 100
Exit Select
Case Else
ScreenSet 0,0
activeScreen = 0
resultImage = BackGroundImage(0)
Sleep 100
End Select 'resultImage
EndIf
If MultiKey(FB.SC_UP) Then
MoveCross(_up)
ElseIf MultiKey(FB.SC_DOWN) Then
MoveCross(_down)
ElseIf MultiKey(FB.SC_LEFT) Then
MoveCross(_left)
ElseIf MultiKey(FB.SC_RIGHT) Then
MoveCross(_right)
ElseIf Multikey(FB.SC_RSHIFT) Andalso MultiKey(FB.SC_UP) Then
MoveCross(_fastUp)
ElseIf Multikey(FB.SC_RSHIFT) Andalso MultiKey(FB.SC_DOWN) Then
MoveCross(_fastDown)
ElseIf Multikey(FB.SC_RSHIFT) Andalso MultiKey(FB.SC_LEFT) Then
MoveCross(_fastLeft)
ElseIf Multikey(FB.SC_RSHIFT) Andalso MultiKey(FB.SC_RIGHT) Then
MoveCross(_fastRight)
Else
MoveCross(_noMove)
EndIf
Loop Until MultiKey(FB.SC_ESCAPE)
'DeAllocate mainScrPtr 'Not to be done since it is ScreenPtr here
DeAllocate resultImage
DeAllocate processedImage
DeAllocate userProcessedImage(1)
DeAllocate userProcessedImage(2)
DeAllocate backGroundImage(0)
DeAllocate backGroundImage(1)
DeAllocate backGroundImage(2)
DeAllocate backGroundImage(3)
DeAllocate backGroundImage(4)
Sleep : End 0
''------------------------------------------------------End()
Function DrawBackGround(ByVal ImageToDraw As FB.IMAGE Ptr =0) As Integer
If ImageToDraw = backGroundImage(0) Or ImageToDraw = 0 Then
Put (0, 0) , backGroundImage(1), PSet
Put (w\2, 0) , backGroundImage(2), PSet
Put (w\2, h\2) , backGroundImage(3), PSet
Put (0, h\2) , backGroundImage(4), PSet
Else
Put (0,0), ImageToDraw, PSet
EndIf
Return -1
End Function 'INT := DrawBackGround(FB.IMAGE)
''---------------------------------------------------------()
Sub ViewReport()
View ( 1 , h*0.9 ) - ( w-2, h-2 ), RGB(d*5/8, d*5/8, d*5/8), RGB(d*1/8, d*1/8, d*1/8)
Draw String (0,0), Str(cross._x)
Draw String (0,10), Str(cross._y)
Draw String (0,20), "Active Screen " & activeScreen
'Note : Point(x,y) still referes to parent window
Draw String (40, 0), "Color = " & Point(cross._x, cross._y, backGroundImage(0))
Draw String (139, 0), "main ScreenPtrColor = " & _
Point(cross._x, cross._y, mainScrPtr)
Draw String (139, 10), "current ScrPtrColor = " & _
Point(cross._x, cross._y, ScreenPtr())
Draw String (139, 20), "(naive access)"
Draw String (349, 00), "user1 ScreenPtrColor = " & UserAccessToScreenPtr1()
Draw String (349, 10), "user2 ScreenPtrColor = " & UserAccessToScreenPtr2()
Draw String (349, 20), "(byte array access)"
View Screen
End Sub 'ViewReport()
''---------------------------------------------------------()
Function MoveCross(ByVal Movdir As _MOVEDIRECTION = 0) As Integer
GetGraphicsParameter()
While InKey<>"" : Wend
ScreenLock
Select Case Movdir
Case _MOVEDIRECTION._up
DrawBackGround(resultImage)
cross._y -= 1
cross.DrawMethod()
If cross._y - 1 < 0 Then cross._y += 1
Case _MOVEDIRECTION._fastUp
DrawBackGround(resultImage)
cross._y -= 2
cross.DrawMethod()
If cross._y - 1 < 0 Then cross._y += 2
Case _MOVEDIRECTION._down
DrawBackGround(resultImage)
cross._y += 1
cross.DrawMethod()
If cross._y > 0.89*h Then cross._y -= 2
cross.DrawMethod()
Case _MOVEDIRECTION._fastDown
DrawBackGround(resultImage)
cross._y += 2
cross.DrawMethod()
If cross._y > 0.89*h Then cross._y -= 4
cross.DrawMethod()
Case _MOVEDIRECTION._left
DrawBackGround(resultImage)
cross._x -= 1
cross.DrawMethod()
If cross._x - 1 < 0 Then cross._x += 1
Case _MOVEDIRECTION._fastLeft
DrawBackGround(resultImage)
cross._x -= 2
cross.DrawMethod()
If cross._x - 1 < 0 Then cross._x += 2
Case _MOVEDIRECTION._right
DrawBackGround(resultImage)
cross._x += 1
cross.DrawMethod()
If cross._x > w Then cross._x -= 2
cross.DrawMethod()
Case _MOVEDIRECTION._fastRight
DrawBackGround(resultImage)
cross._x += 2
cross.DrawMethod()
If cross._x > w Then cross._x -= 4
cross.DrawMethod()
Case Else
DrawBackGround(resultImage)
cross.DrawMethod()
End Select 'Movdir
Sleep 5
processingCursorImage = ImageCreate(5, 2*cross._sweeperLength+1, , d)
For s As Integer = -cross._sweeperLength To cross._sweeperLength
PSet processedImage, (cross._x, cross._y+s), Point(cross._x, cross._y+s, mainScrPtr)
PSet userProcessedImage(1), (cross._x, cross._y+s), UserAccessToScreenPtr1()
PSet userProcessedImage(2), (cross._x, cross._y+s), UserAccessToScreenPtr2()
Next s
If cross._x<w-5 And _
cross._y-cross._sweeperLength > 0 And _
cross._y+cross._sweeperLength < h Then
Get processedImage, _
(cross._x+1, cross._y-cross._sweeperLength+1)- _
(cross._x-1, cross._y+cross._sweeperLength-1), _
processingCursorImage
EndIf
Put (cross._x-2, cross._y-cross._sweeperLength), processingCursorImage, Xor
ViewReport()
cross.DrawMethod(Point(cross._x, cross._y, backGroundImage(0)))
ScreenUnLock
Return -1
End Function 'INT := MoveCross(_MOVEDIRECTION [=0])
''---------------------------------------------------------()
Function UserAccessToScreenPtr1() As ULong
Dim As UByte Ptr ubyteScrPtr
ubyteScrPtr = CPtr (UByte Ptr, mainScrPtr)
Return ubyteScrPtr[cross._x\pitch*cross._y+cross._y]
End Function 'ULONG := UserAccessToScreenPtr1()
Function UserAccessToScreenPtr2() As ULong
Dim As UByte Ptr ubyteScrPtr
ubyteScrPtr = CPtr (UByte Ptr, mainScrPtr)
Return ubyteScrPtr[cross._x\pitch*cross._y+cross._y]
End Function 'ULONG := UserAccessToScreenPtr2()
''---------------------------------------------------------()