Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with DRAW or my "scanning" routine?
#1
Is the problem with my scanning/conversion routine or how DRAW actually draws?
(The draw statements it produces could be optimized to be briefer, I just haven't done that here. I want to get the scanning and rendered correctly first).

Code: (Select All)
'***************************************************************
'scanning a section of the screen converting and writing it with DRAW
'why doesn't it work?
'***************************************************************
Screen _NewImage(480, 400, 256)
$Console
_Console Off
Randomize Timer
Cls
_PrintMode _KeepBackground
_PrintString (0, 0), "AB"
'Line (1, 1)-(1, 14), 15
_Delay 0.5
msg$ = "<-- scanning this as a sample image"
_PrintString (40, 0), msg$
x = 0: y = 0
dd$ = ""
wid = 16
ht = 16
Draw "s4"
dd$ = Scan_draw$(x, y, ht, wid)
_Delay 1
Locate 4, 4
Line (40, 0)-(40 + Len(msg$) * 8, 15), 0, BF
msg$ = "ready (press any key)"
_PrintString (0, 100), msg$
Sleep
Line (0, 100)-(Len(msg$) * 8, 115), 0, BF
Locate 4, 4
Print "Draw Scanned image, Why isn't it drawing correctly?"
Print "Is the problem in the scanning routine or in how draw functions?"
putdraw 50, 0, dd$
drawto_console dd$
Input alldone$
End
'***************************************************************
' subroutines for making use of draw strings in 256 color mode.
' color 0 is treated as transpaernt
Sub putdraw (xx, yy, dd$)
    Draw "bm" + Str$(xx) + "," + Str$(yy) + dd$
End Sub
Sub drawto_console (dd$)
    'program must have console output activated earlier
    'prints the string in a clean console window so it may be copied and pasted on any system with console support
    sd& = _Dest
    _Console On
    _Dest _Console
    Cls
    Print dd$
    Print
    Print "Copy and Paste the above text for future use in DRAW commands"
    _Dest sd&
End Sub
Function Scan_draw$ (sx, sy, ht, wid)
    'scan a screen area starting at point sx,sy and saving it to the string DRW$ for use in later draw commands
    'simply scans each row and tracks color changes
    For y = 0 To ht - 1
        x = 0
        Do
            klr = Point(sx + x, sy + y)
            n = -1
            Do
                n = n + 1
                nklr = Point(x + n, y)

            Loop Until nklr <> klr Or x + n >= wid
            If klr = 0 Then
                dd$ = dd$ + "br" + _Trim$(Str$(n))
            Else
                dd$ = dd$ + "C" + _Trim$(Str$(klr)) + " " + "R" + _Trim$(Str$(n))
            End If
            x = x + n
        Loop Until x >= wid
        dd$ = dd$ + "bd1bl" + Str$(wid)
    Next y
    Scan_draw$ = dd$
End Function
Reply
#2
part of the my issue seems to be how Draw renders a segment.
 R1    doesn't draw just 1 pixel to the right it draws the current pixel plus one pixel to the right.

so to render a single point in DRAW  one would have to have the string segment "R0"    (or so I believe).
as a result my scanning is off due to my not understanding this behavior in DRAW.
Reply
#3
I get blurry copy of AB from that, what else is supposed to happen?
b = b + ...
Reply
#4
(06-23-2023, 09:21 PM)James D Jarvis Wrote: part of the my issue seems to be how Draw renders a segment.
 R1    doesn't draw just 1 pixel to the right it draws the current pixel plus one pixel to the right.

so to render a single point in DRAW  one would have to have the string segment "R0"    (or so I believe).
as a result my scanning is off due to my not understanding this behavior in DRAW.

this is the result on my Lenovo (application window has been put in Fullscreen mode using Alt+Enter)

[Image: immagine-2023-06-24-015300180.png]

As you can see, AB got by drawing with the data get by scanning the screen seems to be bold.

moreover
DRAW has these features  DRAW wikipage

about pixel you should know that S4 = 1 pixel 
Quote:
  • "S n" changes the pixel move size of the lines. Default is 4 (1 pixel) minimum. "S8" would double the pixel line moves.
so if you have set S4 at the beginning of the string for DRAW You must have a duplicate of the area scanned.
It is possible that the bold effect comes out from string passed to DRAW.
Reply
#5
Going deeper in the issue

S4 has been declared a pixel but it is not so true
for whatching why,  run this code

Code: (Select All)
_Title "DRAW demo"
Screen _NewImage(480, 400, 256)

For a = 1 To 10
    PSet (a + 50, 50)
Next a
Draw "s4 bm51,55r10"
Draw "s3 bm51,60r10"
Draw "s2 bm51,65r10"
Draw "s1 bm51,70r10"

For a = 1 To 10
    PSet (70, a + 20)
Next a
Draw "s4bm 75,21d10"
Draw "s3bm 80,21d10"
Draw "s2bm 85,21d10"
Draw "s1bm 90,21d10"
I can affirm that
  1.  there is no issue in QB64 both QB64 and QB64pe. I would mean that the matter is so and so it must be
  2.  this is an inheritance of QB45, a bug of QB45 that lives with it and its clone. Yes to be a clone you must have also the bugs of the original program.
If you REMmed out the first two rows of code and you add on the top  SCREEN 13, you'll get the same output of QB64 from QB45.

Thanks for reading
Reply
#6
@James D Jarvis

SOLVED!
the issue starts from the bug  that if you set a position on the screen and then you use a DRAW command to draws a line also of one pixel (S4r1) it draws the pixel of r command plus the pixel of the starting position!

buuut if you see at this your code you get the right output using a simple continue r command without bling moving of the graphic cursor.

Code: (Select All)
Rem 26 06 2023 SOLVED  TdB
'***************************************************************
'scanning a section of the screen converting and writing it with DRAW
'why doesn't it work?
'***************************************************************
Screen _NewImage(480, 400, 256)
$Console
_Console Off
Randomize Timer
Cls
_PrintMode _KeepBackground
_PrintString (0, 0), "AB"
'Line (1, 1)-(1, 14), 15
_Delay 0.5
msg$ = "<-- scanning this as a sample image"
_PrintString (40, 0), msg$
x = 0: y = 0
dd$ = ""
wid = 16
ht = 16
Draw "s4"
dd$ = Scan_draw$(x, y, ht, wid)
_Delay 1
Locate 4, 4
Line (40, 0)-(40 + Len(msg$) * 8, 15), 0, BF
msg$ = "ready (press any key)"
_PrintString (0, 100), msg$

Sleep
Line (0, 100)-(Len(msg$) * 8, 115), 0, BF
Locate 4, 4
Print "Draw Scanned image, Why isn't it drawing correctly?"
Print "Is the problem in the scanning routine or in how draw functions?"
putdraw 50, 0, dd$
drawto_console dd$
Input alldone$
End
'***************************************************************
' subroutines for making use of draw strings in 256 color mode.
' color 0 is treated as transpaernt
Sub putdraw (xx, yy, dd$)
    Draw "bm" + Str$(xx) + "," + Str$(yy) + dd$
End Sub
Sub drawto_console (dd$)
    'program must have console output activated earlier
    'prints the string in a clean console window so it may be copied and pasted on any system with console support
    sd& = _Dest
    _Console On
    _Dest _Console
    Cls
    Print dd$
    Print
    Print "Copy and Paste the above text for future use in DRAW commands"
    _Dest sd&
End Sub
Function Scan_draw$ (sx, sy, ht, wid)
    'scan a screen area starting at point sx,sy and saving it to the string DRW$ for use in later draw commands
    'simply scans each row and tracks color changes
    For y = 0 To ht - 1
        x = 0
        Do
            klr = Point(sx + x, sy + y)
            n = -1
            Do
                n = n + 1
                nklr = Point(x + n, y)

            Loop Until nklr <> klr Or x + n >= wid
            'If klr = 0 Then
            '    dd$ = dd$ + "br" + _Trim$(Str$(n))
            'Else
            dd$ = dd$ + "C" + _Trim$(Str$(klr)) + " " + "R" + _Trim$(Str$(n))
            ' End If
            x = x + n
        Loop Until x >= wid
        dd$ = dd$ + "bd1bl" + Str$(wid)
    Next y
    Scan_draw$ = dd$
End Function
in other words you have typed too code, REM out these lines of code 
Quote:'If klr = 0 Then
            '    dd$ = dd$ + "br" + _Trim$(Str$(n))
            'Else
       
            ' End If
and let work the  R command!
Quote:            dd$ = dd$ + "C" + _Trim$(Str$(klr)) + " " + "R" + _Trim$(Str$(n))
good continuation of developing you app
Reply
#7
Thumbs Up 
(06-25-2023, 06:12 PM)TempodiBasic Wrote: @James D Jarvis

SOLVED!
the issue starts from the bug  that if you set a position on the screen and then you use a DRAW command to draws a line also of one pixel (S4r1) it draws the pixel of r command plus the pixel of the starting position!

buuut if you see at this your code you get the right output using a simple continue r command without bling moving of the graphic cursor.

Code: (Select All)
Rem 26 06 2023 SOLVED  TdB
'***************************************************************
'scanning a section of the screen converting and writing it with DRAW
'why doesn't it work?
'***************************************************************
Screen _NewImage(480, 400, 256)
$Console
_Console Off
Randomize Timer
Cls
_PrintMode _KeepBackground
_PrintString (0, 0), "AB"
'Line (1, 1)-(1, 14), 15
_Delay 0.5
msg$ = "<-- scanning this as a sample image"
_PrintString (40, 0), msg$
x = 0: y = 0
dd$ = ""
wid = 16
ht = 16
Draw "s4"
dd$ = Scan_draw$(x, y, ht, wid)
_Delay 1
Locate 4, 4
Line (40, 0)-(40 + Len(msg$) * 8, 15), 0, BF
msg$ = "ready (press any key)"
_PrintString (0, 100), msg$

Sleep
Line (0, 100)-(Len(msg$) * 8, 115), 0, BF
Locate 4, 4
Print "Draw Scanned image, Why isn't it drawing correctly?"
Print "Is the problem in the scanning routine or in how draw functions?"
putdraw 50, 0, dd$
drawto_console dd$
Input alldone$
End
'***************************************************************
' subroutines for making use of draw strings in 256 color mode.
' color 0 is treated as transpaernt
Sub putdraw (xx, yy, dd$)
    Draw "bm" + Str$(xx) + "," + Str$(yy) + dd$
End Sub
Sub drawto_console (dd$)
    'program must have console output activated earlier
    'prints the string in a clean console window so it may be copied and pasted on any system with console support
    sd& = _Dest
    _Console On
    _Dest _Console
    Cls
    Print dd$
    Print
    Print "Copy and Paste the above text for future use in DRAW commands"
    _Dest sd&
End Sub
Function Scan_draw$ (sx, sy, ht, wid)
    'scan a screen area starting at point sx,sy and saving it to the string DRW$ for use in later draw commands
    'simply scans each row and tracks color changes
    For y = 0 To ht - 1
        x = 0
        Do
            klr = Point(sx + x, sy + y)
            n = -1
            Do
                n = n + 1
                nklr = Point(x + n, y)

            Loop Until nklr <> klr Or x + n >= wid
            'If klr = 0 Then
            '    dd$ = dd$ + "br" + _Trim$(Str$(n))
            'Else
            dd$ = dd$ + "C" + _Trim$(Str$(klr)) + " " + "R" + _Trim$(Str$(n))
            ' End If
            x = x + n
        Loop Until x >= wid
        dd$ = dd$ + "bd1bl" + Str$(wid)
    Next y
    Scan_draw$ = dd$
End Function
in other words you have typed too code, REM out these lines of code 
Quote:'If klr = 0 Then
            '    dd$ = dd$ + "br" + _Trim$(Str$(n))
            'Else
       
            ' End If
and let work the  R command!
Quote:            dd$ = dd$ + "C" + _Trim$(Str$(klr)) + " " + "R" + _Trim$(Str$(n))
good continuation of developing you app

If the goal was to remove blur then you did it TempodiBasic! Smile
b = b + ...
Reply
#8
(06-25-2023, 06:12 PM)TempodiBasic Wrote: @James D Jarvis

SOLVED!
the issue starts from the bug  that if you set a position on the screen and then you use a DRAW command to draws a line also of one pixel (S4r1) it draws the pixel of r command plus the pixel of the starting position!

buuut if you see at this your code you get the right output using a simple continue r command without bling moving of the graphic cursor.

Code: (Select All)
Rem 26 06 2023 SOLVED  TdB
'***************************************************************
'scanning a section of the screen converting and writing it with DRAW
'why doesn't it work?
'***************************************************************
Screen _NewImage(480, 400, 256)
$Console
_Console Off
Randomize Timer
Cls
_PrintMode _KeepBackground
_PrintString (0, 0), "AB"
'Line (1, 1)-(1, 14), 15
_Delay 0.5
msg$ = "<-- scanning this as a sample image"
_PrintString (40, 0), msg$
x = 0: y = 0
dd$ = ""
wid = 16
ht = 16
Draw "s4"
dd$ = Scan_draw$(x, y, ht, wid)
_Delay 1
Locate 4, 4
Line (40, 0)-(40 + Len(msg$) * 8, 15), 0, BF
msg$ = "ready (press any key)"
_PrintString (0, 100), msg$

Sleep
Line (0, 100)-(Len(msg$) * 8, 115), 0, BF
Locate 4, 4
Print "Draw Scanned image, Why isn't it drawing correctly?"
Print "Is the problem in the scanning routine or in how draw functions?"
putdraw 50, 0, dd$
drawto_console dd$
Input alldone$
End
'***************************************************************
' subroutines for making use of draw strings in 256 color mode.
' color 0 is treated as transpaernt
Sub putdraw (xx, yy, dd$)
    Draw "bm" + Str$(xx) + "," + Str$(yy) + dd$
End Sub
Sub drawto_console (dd$)
    'program must have console output activated earlier
    'prints the string in a clean console window so it may be copied and pasted on any system with console support
    sd& = _Dest
    _Console On
    _Dest _Console
    Cls
    Print dd$
    Print
    Print "Copy and Paste the above text for future use in DRAW commands"
    _Dest sd&
End Sub
Function Scan_draw$ (sx, sy, ht, wid)
    'scan a screen area starting at point sx,sy and saving it to the string DRW$ for use in later draw commands
    'simply scans each row and tracks color changes
    For y = 0 To ht - 1
        x = 0
        Do
            klr = Point(sx + x, sy + y)
            n = -1
            Do
                n = n + 1
                nklr = Point(x + n, y)

            Loop Until nklr <> klr Or x + n >= wid
            'If klr = 0 Then
            '    dd$ = dd$ + "br" + _Trim$(Str$(n))
            'Else
            dd$ = dd$ + "C" + _Trim$(Str$(klr)) + " " + "R" + _Trim$(Str$(n))
            ' End If
            x = x + n
        Loop Until x >= wid
        dd$ = dd$ + "bd1bl" + Str$(wid)
    Next y
    Scan_draw$ = dd$
End Function
in other words you have typed too code, REM out these lines of code 
Quote:'If klr = 0 Then
            '    dd$ = dd$ + "br" + _Trim$(Str$(n))
            'Else
       
            ' End If
and let work the  R command!
Quote:            dd$ = dd$ + "C" + _Trim$(Str$(klr)) + " " + "R" + _Trim$(Str$(n))
good continuation of developing you app

Thank you.  Thank you everyone. It's close but I'm trying to not encode and render C0. I know I can get this done with some other method but I'm experimenting on using DRAW. I could certainly draw to an intermediate image and use putimage to render but that would defeat much of the purpose of using DRAW.
Reply
#9
SOLVED again , now saving the feature of  drawing only foregorund colors of the image

please play the code and comments let understand where and why the issue arises
Code: (Select All)
Rem 27 06 2023 / 28 06 2023  SOLVED saving the feature of drawing only foreground of image
Rem but James D Jarvis  wants to draw only foreground of image, NO background like for a vector image
'***************************************************************
'scanning a section of the screen converting and writing it with DRAW
'why doesn't it work?
'***************************************************************
Screen _NewImage(480, 400, 256)
$Console
_Console Off
Randomize Timer
Cls
_PrintMode _KeepBackground
_PrintString (0, 0), "AB"
'Line (1, 1)-(1, 14), 15
_Delay 0.5
msg$ = "<-- scanning this as a sample image"
_PrintString (40, 0), msg$
x = 0: y = 0
dd$ = ""
wid = 16
ht = 16
Draw "s4"
dd$ = Scan_draw$(x, y, ht, wid)
_Delay 1
Locate 4, 4
Line (40, 0)-(40 + Len(msg$) * 8, 15), 0, BF
msg$ = "ready (press any key)"
_PrintString (0, 100), msg$

Sleep
Line (0, 100)-(Len(msg$) * 8, 115), 0, BF
Locate 4, 4
Print "Draw Scanned image, Why isn't it drawing correctly?"
Print "Is the problem in the scanning routine or in how draw functions?"
Print "it is a problem arising from the translation of scanned data into Draw commands!"
putdraw 50, 0, dd$
putdraw 1, 20, dd$
drawto_console dd$
Input alldone$
End
'***************************************************************
' subroutines for making use of draw strings in 256 color mode.
' color 0 is treated as transpaernt
Sub putdraw (xx, yy, dd$)
    Draw "bm" + Str$(xx) + "," + Str$(yy) + dd$
End Sub
Sub drawto_console (dd$)
    'program must have console output activated earlier
    'prints the string in a clean console window so it may be copied and pasted on any system with console support
    sd& = _Dest
    _Console On
    _Dest _Console
    Cls
    Print dd$
    Print
    Print "Copy and Paste the above text for future use in DRAW commands"
    _Dest sd&
End Sub
Function Scan_draw$ (sx, sy, ht, wid)
    'scan a screen area starting at point sx,sy and saving it to the string DD$ for use in later draw commands
    'simply scans each row and tracks color changes
    For y = 0 To ht - 1
        x = 0
        Do
            klr = Point(sx + x, sy + y) 'here cohordinates are relative to topleft starter point  sx,sy
            n = -1 ' why do you need to start from -1? So you are including also n = 0 that is the same point valutated here above
            Do
                n = n + 1
                nklr = Point(x + n, y) 'here cohordinates are absolute starting from topleft starter point 0,0
            Loop Until nklr <> klr Or x + n >= wid
            'n, going out of loop, is bringing the value of the next color    or got right edge
            If klr = 0 Then
                dd$ = dd$ + "br" + _Trim$(Str$(n)) ' it moves blind the graphic cursor towards the right edge  with step of 2 pixels ata a time
            Else
                ' R draws the starting point + the n pixels, so to solve we go back 1 pixel, then we draw n-1 pixels and then we go forwards 2 pixels
                dd$ = dd$ + "bm-1,+0" + "C" + _Trim$(Str$(klr)) + " " + "R" + _Trim$(Str$(n - 1)) + "bm+2,+0" ' it draws a line to right from the starter point
            End If
            x = x + n
        Loop Until x >= wid
        dd$ = dd$ + "bd1bl" + Str$(wid) ' here it moves the graphic cursor to the first point of the next row
    Next y
    Scan_draw$ = dd$
End Function

[Image: immagine-2023-06-28-013636796.png]

Short version for who has no time to read code and code comments:
Commands of DRAW draw from the starting point of the screen towards the direction selected of N times (if S4 each n = 1 pixel)
So if you type DRAW "s4c15 r1" it draws 5 pixels to right 1 of starting position + 4 of movement towards right edge of image/screen.
As you understand you are not able to draw a single pixel until you do not use M command that uses absolute/relative cohordinates and let move also 1 pixel towards the choosen direction.
Reply
#10
Woo Hoo!

    THANK YOU!!!  This little bit right here was what I just couldn't get right. I haven't posted the ridiculous number of variations of logic I had tried. 

THANKS AGAIN!
Code: (Select All)
                ' R draws the starting point + the n pixels, so to solve we go back 1 pixel, then we draw n-1 pixels and then we go forwards 2 pixels
                dd$ = dd$ + "bm-1,+0" + "C" + _Trim$(Str$(klr)) + " " + "R" + _Trim$(Str$(n - 1)) + "bm+2,+0" ' it draws a line to right from the starter point
Reply




Users browsing this thread: 2 Guest(s)