QB64.org Forum

Active Forums => Programs => Topic started by: bplus on November 14, 2019, 12:20:38 am

Title: Paint Image
Post by: bplus on November 14, 2019, 12:20:38 am
Turned out pretty easy!
Code: QB64: [Select]
  1. SUB paintImage (x, y, Border~&, destHandle&, imageHandle&)
  2.     _DEST destHandle&
  3.     PAINT (x, y), _RGB32(119, 24, 49), Border~&
  4.     FOR y = 0 TO _HEIGHT(destHandle&)
  5.         FOR x = 0 TO _WIDTH(destHandle&)
  6.             _SOURCE destHandle&
  7.             IF POINT(x, y) = _RGB32(119, 24, 49) THEN
  8.                 _SOURCE imageHandle&
  9.                 PSET (x, y), POINT(x MOD _WIDTH(imageHandle&), y MOD _HEIGHT(imageHandle&))
  10.             END IF
  11.         NEXT
  12.     NEXT
  13.  

Attached is demo code for these:
  [ This attachment cannot be displayed inline in 'Print Page' view ]  
  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Paint Image
Post by: Petr on November 14, 2019, 11:10:27 am
Nice work, BPlus. Next method is with virtual screens and transparency + _PUTIMAGE.
Title: Re: Paint Image
Post by: bplus on November 14, 2019, 11:43:04 am
Nice work, BPlus. Next method is with virtual screens and transparency + _PUTIMAGE.

Thanks Petr, looks like you want to go beyond bricks ;)
Title: Re: Paint Image
Post by: Petr on November 14, 2019, 11:45:37 am
I am pleased, that you know, where I use it :)
Title: Re: Paint Image
Post by: SierraKen on November 14, 2019, 11:46:39 am
Incredible graphics, but I have no idea how you did that. LOL
Title: Re: Paint Image
Post by: SierraKen on November 14, 2019, 11:51:24 am
I just tried it and got an Invalid Handle on Line 79. But you got some awesome code there. Reminds me of how I used POINT to make text larger. I wonder if it's because I put all the files in their own directory?
Title: Re: Paint Image
Post by: bplus on November 14, 2019, 11:59:15 am
I just tried it and got an Invalid Handle on Line 79. But you got some awesome code there. Reminds me of how I used POINT to make text larger. I wonder if it's because I put all the files in their own directory?

Sounds like the image file didn't load which most likely cause is that under the Run menu of IDE > there is no bullet next to "Output EXE to Source Folder" so when you compiled the program the exe went to QB64 folder instead of the download folder with the image files.

And yes I did use that trick for blowing up text for the "B+" graphic part. ;) I have made a sub of that so I can print sized text anywhere, probably should have used it :D
Title: Re: Paint Image
Post by: Petr on November 14, 2019, 12:00:50 pm
Oh, deleted, my faul.
Title: Re: Paint Image
Post by: SierraKen on November 14, 2019, 01:23:08 pm
Yep bplus, that was the problem lol. Man that's amazing stuff, good job!
Title: Re: Paint Image
Post by: SMcNeill on November 14, 2019, 04:58:54 pm
A few points here (as I happily steal and repurpose this code for my own demo)...

_RGB32(119, 24, 49) —>  Just make these _RGB commands (no 32), and you can use this in other screen modes (like SCREEN 12 or 256-color mode).  Only thing to watch for is if the fill color is used elsewhere in the program.  In 32-bit mode, that _RGB color isn’t very likely to be used previously (a simple generation of a random color, and a check to make certain it’s not in use could eliminate all “paint bleeds”), but as we reduce our color palette smaller, it’s more likely to fill wrong areas...

I haven’t looked at Petr’s fill routine yet, but it might work better in lower colors modes, without the worry of bad fills.  I’ll need to check it out later.  ;)

Point 2: Get _DEST and _SOURCE at the start of the sub, and then restore them at exit time, if you want the routine to be more portable.  ;)
Title: Re: Paint Image
Post by: bplus on November 14, 2019, 05:07:01 pm
A few points here (as I happily steal and repurpose this code for my own demo)...

_RGB32(119, 24, 49) —>  Just make these _RGB commands (no 32), and you can use this in other screen modes (like SCREEN 12 or 256-color mode).  Only thing to watch for is if the fill color is used elsewhere in the program.  In 32-bit mode, that _RGB color isn’t very likely to be used previously (a simple generation of a random color, and a check to make certain it’s not in use could eliminate all “paint bleeds”), but as we reduce our color palette smaller, it’s more likely to fill wrong areas...

I haven’t looked at Petr’s fill routine yet, but it might work better in lower colors modes, without the worry of bad fills.  I’ll need to check it out later.  ;)

Point 2: Get _DEST and _SOURCE at the start of the sub, and then restore them at exit time, if you want the routine to be more portable.  ;)

Thanks Steve, I was just going to post your improvement:
Code: QB64: [Select]
  1. SUB paintImage (x, y, Border~&, destHandle&, imageHandle&)
  2.     d = _DEST: s = _SOURCE
  3.     _DEST destHandle&
  4.     PAINT (x, y), _RGB(119, 24, 49), Border~&
  5.     FOR y = 0 TO _HEIGHT(destHandle&)
  6.         FOR x = 0 TO _WIDTH(destHandle&)
  7.             _SOURCE destHandle&
  8.             IF POINT(x, y) = _RGB(119, 24, 49) THEN
  9.                 _SOURCE imageHandle&
  10.                 PSET (x, y), POINT(x MOD _WIDTH(imageHandle&), y MOD _HEIGHT(imageHandle&))
  11.             END IF
  12.         NEXT
  13.     NEXT
  14.     _DEST d: _SOURCE s
  15.  
I caught the saving and restoring _SOURCE and _DEST but missed the _RGB switch, dropping 32.

Update: Just checked Steve's improvements with the demo test code and ran fine, so that makes this version the best so far.
Title: Re: Paint Image
Post by: Petr on November 15, 2019, 09:39:52 am
And from that, what you write, BPlus and Steve, it shows an option for MEM and a feature that quickly finds an unused combination of RGB colors to prevent malfunction :-)
Title: Re: Paint Image
Post by: SMcNeill on November 15, 2019, 10:46:16 am
Here's a version of your paint image routine which I think would probably be "image bleed" proof:

Code: QB64: [Select]
  1. SUB paintImage (x, y, Border~&, destHandle&, imageHandle&)
  2.     DIM d AS INTEGER, s AS INTEGER
  3.     DIM w AS INTEGER, h AS INTEGER
  4.     DIM im1 AS INTEGER, im2 AS INTEGER
  5.     d = _DEST: s = _SOURCE
  6.     w = _WIDTH(destHandle&): h = _HEIGHT(destHandle&)
  7.     c1 = _RGB(119, 24, 49): c2 = _RGB(124, 49, 119)
  8.     im1 = _COPYIMAGE(destHandle&): im2 = _COPYIMAGE(destHandle&)
  9.  
  10.     _DEST im1: PAINT (x, y), c1, Border~& 'paint one background one color
  11.     _DEST im2: PAINT (x, y), c2, Border~& 'paint a second background a different color
  12.     _DEST destHandle&
  13.     w = _WIDTH(imageHandle&): h = _HEIGHT(imageHandle&)
  14.     FOR y = 0 TO _HEIGHT(destHandle&)
  15.         FOR x = 0 TO _WIDTH(destHandle&)
  16.             _SOURCE im1: p1 = POINT(x, y) 'check for proper color on one background
  17.             _SOURCE im2: p2 = POINT(x, y) 'check for proper color on second background
  18.             IF p1 = c1 AND p2 = c2 THEN 'if both our backgrounds match the expected colors then
  19.                 _SOURCE imageHandle&
  20.                 PSET (x, y), POINT(x MOD w, y MOD h) 'paint the destination with our image
  21.             END IF
  22.         NEXT
  23.     NEXT
  24.     _DEST d: _SOURCE s
  25.     _FREEIMAGE im1 'free the two temp images
  26.     _FREEIMAGE im2 'free the two temp images

Instead of painting the background of our original destination _RGB(119, 24, 29), we instead make a copy of the background and paint that copy.  Then, for error checking, we take a second copy of the original background, and paint it a second color...

Only in areas where those two changes overlap, do we actually paint our image onto the original background.

The end result works so that if our whole screen was _RGB(119, 24, 29) to begin with, we'd still only paint in the desired area, and not paint our pattern across the whole screen.  It's going to be a lot slower than what you had originally (we're copying and freeing images, painting three times in total, and getting point values from multiple screens for comparisons), but it's going to be more reliable if we're working on screens with a reduced color palette (like the SCREEN 12 which I was using for paint fill elsewhere).

It's a tradeoff of speed for safety, and I wouldn't want to use this version as a fill routine inside a game loop (I imagine your FPS would drop considerably), but it'd work nice as a simple routine to plug in and use to fill an area once, so you can use it for something else in your code elsewhere.  ;)
Title: Re: Paint Image
Post by: bplus on November 15, 2019, 11:28:08 am
Hi Steve,

Frankly my dear, I don't give a damn about SCREEN 12 mode. ;-))

Why in the wide world would you willingly and wistfully waste wonderful color options in graphics 32 for 16 colors? 0 alpha!?!? And further, be restricted in screen size to one.

If an image happens to "bleed" in a point or two, that actually might create a really cool effect, but a the sub does need a proper warning not to use the one off color allot or change the PAINT color to different if need to use _RGB(119, 24, 49)

BTW I was disappointed to learn that POINT does not recognize &H color constants, I had to switch code to _RGB32 colors in my testing of the SUB. To me, that is a bigger problem with this sub for 32 bit graphics users.
Title: Re: Paint Image
Post by: Petr on November 15, 2019, 11:29:16 am
Thank you Steve. I started writing a function that returns the number of the first unused color in the image (or -1 if there is no free color). This resulted in my question on flashing colors in text mode. If I have a function that returns a free color number, I will ensure correct operation for both the BPlus and my image fill methods, that also use PAINT; So both methods require using an free (in image unused) color.
Title: Re: Paint Image
Post by: SMcNeill on November 15, 2019, 11:46:02 am
Hi Steve,

Frankly my dear, I don't give a damn about SCREEN 12 mode. ;-))

Why in the wide world would you willingly and wistfully waste wonderful color options in graphics 32 for 16 colors? 0 alpha!?!? And further, be restricted in screen size to one.

Honestly, I don’t either.  The question about paint fills by Tempodi (and worked on by Petr), was the first time I’ve worked with SCREEN 12 in YEARS.  Occasionally I’ll do stuff in 256 color mode, but anything less than that is just a PITA and a waste of time, IMHO...

I just thought it’d be nice to highlight an error-checking method for your code, in case anyone really wanted to use it in lower color modes, but it’s not something I’d actually plug into my own programs usually.  For personal use, I tend to prefer speed over error-checking, with the assumption that if I do have problems with something, I can always debug it and add that extra functionality/protection later.  ;)
Title: Re: Paint Image
Post by: bplus on November 15, 2019, 12:10:48 pm
But don't get me wrong, you can learn some really cool stuff studying retro, seeing how clever people can be working with limited resources.

eg the very idea of painting with images!

So I am not ever going to be snubbing code just because it's in an outdated screen mode.
Title: Re: Paint Image
Post by: TempodiBasic on November 16, 2019, 10:12:47 am
Ah-a here is the idea that Steve uses to build Paint Tiling QB45 emulator for SCREEN 12!
People please tell me, better a neutral color or a copy of the area of image to be overwritten if you work in 32bit mode?
Cool paintImage!

Title: Re: Paint Image
Post by: bplus on November 16, 2019, 11:01:08 am
Ah-a here is the idea that Steve uses to build Paint Tiling QB45 emulator for SCREEN 12!
People please tell me, better a neutral color or a copy of the area of image to be overwritten if you work in 32bit mode?
Cool paintImage!



Hi TempodiBasic,

When using this SUB in 32 bit color mode:
Code: QB64: [Select]
  1. SUB paintImage (x, y, Border~&, destHandle&, imageHandle&)
  2.     d = _DEST: s = _SOURCE
  3.     _DEST destHandle&
  4.     PAINT (x, y), _RGB(119, 24, 49), Border~&
  5.     FOR y = 0 TO _HEIGHT(destHandle&)
  6.         FOR x = 0 TO _WIDTH(destHandle&)
  7.             _SOURCE destHandle&
  8.             IF POINT(x, y) = _RGB(119, 24, 49) THEN
  9.                 _SOURCE imageHandle&
  10.                 PSET (x, y), POINT(x MOD _WIDTH(imageHandle&), y MOD _HEIGHT(imageHandle&))
  11.             END IF
  12.         NEXT
  13.     NEXT
  14.     _DEST d: _SOURCE s
  15.  

The only color to watch out for is _RGB(119, 24, 49), because to find the places to PAINT the image, the area at x, y is PAINTed first with that color to the Border~& color that should enclose x, y unless you want to paint to edges and have all other areas enclosed with Border~& color.
Title: Re: Paint Image
Post by: Petr on November 19, 2019, 01:47:10 pm
Hi BPlus, here is promised function, which return unused (free) color in image. It is option for your and my fill program.

Code: QB64: [Select]
  1. 'function return unused color number, v.1
  2. im32 = _SCREENIMAGE '_LOADIMAGE("qb.png", 32)
  3. img = _NEWIMAGE(256, 100, 256)
  4. _DEST img
  5. FOR c = 0 TO 256
  6.     LINE (c, 0)-(c, 100), c / 1.1
  7.  
  8. DIM FreeColor AS _UNSIGNED LONG
  9. FreeColor = GETFREECOLOR~&(im32)
  10. PRINT _RED32(FreeColor); _GREEN32(FreeColor); _BLUE32(FreeColor); _ALPHA32(FreeColor)
  11. PRINT GETFREECOLOR(img)
  12. SCREEN im32
  13. 'LINE (0, 0)-(500, 500), FreeColor, B 'uncomment both rows, paint color, which in original is not used and program correctly test himself as bad.
  14. 'PAINT (10, 10), FreeColor, FreeColor
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. 'program correct functionality automatic test
  22. n = _MEMIMAGE(im32)
  23. w = _WIDTH(im32)
  24. h = _HEIGHT(im32)
  25. H$ = "Program OK"
  26. FOR s = 0 TO w * h - 4 STEP 4
  27.     IF FreeColor = _MEMGET(n, n.OFFSET + s, _UNSIGNED LONG) THEN H$ = "Program Failure."
  28.  
  29. FUNCTION GETFREECOLOR~& (img AS LONG)
  30.     GETFREECOLOR~& = -1 'without definitions FreeColor in my loop and none free color it return -1~& (4294967295)
  31.     DIM m AS _MEM
  32.     m = _MEMIMAGE(img)
  33.     W = _WIDTH(img)
  34.     H = _HEIGHT(img)
  35.         CASE 0: EXIT FUNCTION 'text mode not supported in this version
  36.         CASE 1
  37.             DIM C(0 TO 255)
  38.             FOR s = 0 TO W * H - 1
  39.                 C(_MEMGET(m, m.OFFSET + s, _UNSIGNED _BYTE)) = 1
  40.             NEXT
  41.             DO UNTIL C(FRC) = 0
  42.                 FRC = FRC + 1
  43.                 IF FRC > 255 THEN EXIT FUNCTION 'no free 8 bit color
  44.             LOOP
  45.             GETFREECOLOR = FRC
  46.  
  47.         CASE 4
  48.             DIM C32(W * H) AS _UNSIGNED LONG
  49.             FOR s = 0 TO W * H - 4 STEP 4
  50.                 C32(s) = _MEMGET(m, m.OFFSET + s, _UNSIGNED LONG)
  51.             NEXT
  52.             FOR a = 255 TO 0 STEP -1
  53.                 FOR g = 0 TO 255
  54.                     FOR b = 0 TO 255
  55.                         FOR r = 0 TO 255
  56.                             test = 2
  57.                             FOR ic = 0 TO W * H
  58.                                 IF _RGBA32(r, g, b, a) = C32(ic) THEN test = 1
  59.                             NEXT ic
  60.                             IF test = 2 THEN
  61.                                 GETFREECOLOR~& = _RGBA32(r, g, b, a)
  62.                                 _MEMFREE m
  63.                                 ERASE C32
  64.                                 EXIT FUNCTION
  65.                             END IF
  66.                         NEXT r
  67.                     NEXT b
  68.                 NEXT g
  69.             NEXT a
  70.     END SELECT
  71.  
Title: Re: Paint Image
Post by: bplus on November 19, 2019, 03:10:35 pm
Hi Petr,

I noticed you are testing for Alpha but neither POINT nor PAINT work with Alphas. As I mentioned previously, I was disappointed that even &H color constant values would not be recognized by POINT or PAINT even with full aplha 255 or FF. It sure would be nice if an invisible border color could be used to contain PAINTS so lines aren't left with paintImage.

Maybe you _MEMory guys can write _ALPHAPOINT and _ALPHAPAINT subroutines?


Here is another test with Brick Image:
Code: QB64: [Select]
  1. _TITLE "Brick Pattern Tile, click a spot to spray paint a brick image."
  2. CONST xmax = 800, ymax = 600
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 40
  5. 'make brick pattern
  6. brickpat& = _NEWIMAGE(16, 16, 32)
  7. _DEST brickpat&
  8. LINE (0, 0)-(_WIDTH(brickpat&) - 1, _HEIGHT(brickpat&) - 1), _RGB32(128, 0, 0), BF
  9. LINE (0, 0)-(_WIDTH(brickpat&) - 1, 0), _RGB32(200, 200, 200), BF
  10. LINE (0, 7)-(_WIDTH(brickpat&) - 1, 8), _RGB32(200, 200, 200), BF
  11. LINE (0, 15)-(_WIDTH(brickpat&) - 1, 15), _RGB32(200, 200, 200), BF
  12. LINE (0, 0)-(1, 8), _RGB32(200, 200, 200), BF
  13. LINE (7, 8)-(8, 15), _RGB32(200, 200, 200), BF
  14.  
  15. WHILE _KEYDOWN(27) = 0
  16.     mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  17.     IF mb THEN
  18.         r = r + 1
  19.         IF r > 20 THEN r = 1
  20.         CIRCLE (mx, my), 50, _RGB32(20, 20, r)
  21.         paintImage mx, my, _RGB32(20, 20, r), 0, brickpat&
  22.     END IF
  23.     _DISPLAY
  24.     _LIMIT 60
  25.  
  26. SUB paintImage (x, y, Border~&, destHandle&, imageHandle&)
  27.     d = _DEST: s = _SOURCE
  28.     _DEST destHandle&
  29.     PAINT (x, y), _RGB(119, 24, 49), Border~&
  30.     FOR y = 0 TO _HEIGHT(destHandle&)
  31.         FOR x = 0 TO _WIDTH(destHandle&)
  32.             _SOURCE destHandle&
  33.             IF POINT(x, y) = _RGB(119, 24, 49) THEN
  34.                 _SOURCE imageHandle&
  35.                 PSET (x, y), POINT(x MOD _WIDTH(imageHandle&), y MOD _HEIGHT(imageHandle&))
  36.             END IF
  37.         NEXT
  38.     NEXT
  39.     _DEST d: _SOURCE s
  40.  

Title: Re: Paint Image
Post by: Petr on November 19, 2019, 04:42:25 pm
Hi.
 Therefore, as you have noticed, my program for finding unused colors starts from alpha 255. :) OR use _DONTBLEND in program :)
What you want, PAINT with alpha, is practically a problem. Alpha shows the RGB color intensity depending on the background used. Therefore, you would have to write a complex algorithm that would not work on the principle of a uniform color boundary of the place where you do new color. I've tried to write something like my own PAINT in the past, but it's more complicated than I thought. (I stopped having fun with it, so this is uncomplete somewhere on my harddrive).
Principle of function, as I imagined it: Read the color number X, Y at the place where you want to color. Then from this point go to all sides (something as your maze search algorithm) and look for the positions of the points that have a different color than the color of the place you want to color. After you get the whole circuit completely, you paint it and color it. That's how PAINT works right now, just looking for a specific color. I suppose ALPHA would not mind such a function. The only thing she cares about is a different (any) color point than the default color (color in place where is coloring applyed. before color apply). How confirm, that circuit is complete? Hmm.... good ask :)

Title: Re: Paint Image
Post by: TempodiBasic on November 21, 2019, 06:12:16 pm
Hi Bplus

about  this
Quote
I noticed you are testing for Alpha but neither POINT nor PAINT work with Alphas. As I mentioned previously, I was disappointed that even &H color constant values would not be recognized by POINT or PAINT even with full aplha 255 or FF.
I can disagree  because it seems that POINT works
Code: QB64: [Select]
  1. CONST r1 = _RGBA32(200, 0, 0, 255), r2 = _RGBA32(200, 0, 0, 200), r3 = _RGBA32(180, 0, 0, 155)
  2.  
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4.  
  5. CIRCLE (100, 100), 100, r1
  6. PRINT POINT(100, 100); "  "; POINT(100, 200)
  7. PAINT (100, 100), r2, r1
  8. PRINT POINT(100, 100); "  "; POINT(100, 200)

About why PAINT doesn't recognize BorderColor%  because in Wiki BorderColor% can be also a Long32  and not only an integer
http://qb64.org/wiki/PAINT (http://qb64.org/wiki/PAINT)

moreover there is something broken in the PAINT command implementation for its alternating working well/bad

see here
Code: QB64: [Select]
  1. CONST r1 = _RGBA32(200, 0, 0, 255), r2 = _RGBA32(199, 0, 0, 200)
  2. CONST r3 = _RGBA32(200, 0, 0, 255), r4 = _RGBA32(199, 0, 0, 230), r5 = _RGBA32(180, 0, 0, 255)
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4.  
  5. CIRCLE (100, 100), 100, r1
  6. PRINT POINT(100, 100); "  "; POINT(100, 200)
  7. PAINT (100, 100), r2, r1
  8. PRINT POINT(100, 100); "  "; POINT(100, 200)
  9. LINE (200, 200)-STEP(50, 70), r3, B
  10. PAINT STEP(-10, -10), r4, r3 '<--- this paint works
  11. LINE (100, 100)-(150, 170), r5, BF
  12. PRINT POINT(201, 201); "  "; POINT(101, 101)
  13. PAINT (1, 1), r3, r5 '<-- this paint works
  14. LINE (300, 100)-(404, 404), r4, B
  15. PAINT (400, 400), r2, r4 ' <-- this paint doesn't work
  16.  
  17.  

but POINT seems to work in these examples.

Title: Re: Paint Image
Post by: TempodiBasic on November 21, 2019, 06:24:39 pm
Hi Petr

Quote
Principle of function, as I imagined it: Read the color number X, Y at the place where you want to color. Then from this point go to all sides (something as your maze search algorithm) and look for the positions of the points that have a different color than the color of the place you want to color. After you get the whole circuit completely, you paint it and color it. That's how PAINT works right now, just looking for a specific color. I suppose ALPHA would not mind such a function. The only thing she cares about is a different (any) color point than the default color (color in place where is coloring applyed. before color apply). How confirm, that circuit is complete? Hmm.... good ask :)

what do you think of these different implementation of  FloodFill ?
https://en.wikipedia.org/wiki/Flood_fill (https://en.wikipedia.org/wiki/Flood_fill)

I think that the 8 way direction implementation is far away from PAINT command, and you?
Title: Re: Paint Image
Post by: bplus on November 21, 2019, 07:12:17 pm
Hi TempodiBasic,

Here is my screen shot for code you say works:
 


BTW I understand why alpha should not work, it's not same color when overlaying other colors.
Title: Re: Paint Image
Post by: bplus on November 21, 2019, 09:28:33 pm
Oh hell I can't even get _RGB32 to work as CONST but &HFF.... works fine

Code: QB64: [Select]
  1.  
  2. 'CONST r1 = &HFFBB0000, r2 = &HFF00BB00 'OK paint works right with line box
  3. 'CONST r1 = _RGB32(200, 0, 0), r2 = _RGB32(0, 128, 0) ' <<<<<<<  screws up doesn't even draw box!!!
  4. SCREEN _NEWIMAGE(800, 600, 32)
  5. _SCREENMOVE 300, 40
  6.  
  7.  
  8. ' ok normal paint working
  9. r1 = _RGB32(200, 0, 0)
  10. r2 = _RGB32(0, 128, 0)
  11.  
  12. ' and alpha paint NOT working
  13. 'r1 = _RGBA32(200, 0, 0, 200)
  14. 'r2 = _RGBA32(0, 128, 0, 200)
  15.  
  16. LINE (103, 103)-STEP(100, 100), r1, B
  17. PRINT POINT(103, 103); "  "; POINT(110, 110)
  18. PAINT (109, 109), r2, r1
  19. PRINT POINT(103, 103); "  "; POINT(110, 110)
  20.  
Title: Re: Paint Image
Post by: bplus on November 22, 2019, 10:11:35 am
OK POINT will do alpha coloring and even match _RGBA32() with &HFF... colors where expected, it's just tricky specially if CLS not used immediately:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. _SCREENMOVE 300, 40
  3.  
  4.  
  5.  
  6. 'CLS '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  OHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH   AHA!
  7. ' with CLS get match right off the bat! Remove comment ' and no testing needed.
  8.  
  9. ' OK so POINT can read and match Alpha
  10.  
  11. red1 = _RGBA32(255, 0, 0, 127)
  12. red2 = &H80FF0000
  13. LINE (100, 100)-STEP(100, 400), red1, BF
  14. LINE (300, 100)-STEP(100, 400), red2, BF
  15. WHILE POINT(110, 110) <> POINT(310, 310)
  16.     CLS
  17.     a = a + 1
  18.     red1 = _RGBA32(255, 0, 0, a)
  19.     LINE (100, 100)-STEP(100, 400), red1, BF
  20.     LINE (300, 100)-STEP(100, 400), red2, BF
  21.     COLOR &HFFFFFFFF
  22.     PRINT "Red1 POINT "; POINT(110, 110); " alpha a = "; a
  23.     PRINT "Red2 POINT "; POINT(310, 310)
  24.     PRINT "press any to awaken next... "
  25.     SLEEP
  26.     IF alpha = 255 THEN EXIT WHILE
  27. PRINT "A match or Alpha ran all the way to 255, Test done."
  28.  
  29.  

OK so now I have to retest PAINT... with this fine POINT understood.
Title: Re: Paint Image
Post by: bplus on November 22, 2019, 10:35:39 am
Well CLS right off doesn't help PAINT find an Alpha Border Color but _DONTBLEND does, first time I've used it with understanding BUT _DONTBLEND ruins transparency. So no fix to erase boundary lines for Paint Image just use border lines close to colors used in image or background.

Code: QB64: [Select]
  1. 'CONST r1 = &HFFBB0000, r2 = &HFF00BB00 'OK paint works right with line box
  2. 'CONST r1 = _RGB32(200, 0, 0), r2 = _RGB32(0, 128, 0) ' <<<<<<<  screws up doesn't even draw box!!!
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4. _SCREENMOVE 300, 40
  5.  
  6.  
  7. ' ok normal paint working
  8. r1 = _RGB32(200, 0, 0)
  9. r2 = _RGB32(0, 128, 0)
  10.  
  11. ' and alpha paint NOT working
  12. 'CLS '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< might work now, nope!
  13.  
  14. r1 = _RGBA32(200, 0, 0, 1) 'try nearly invisible color
  15. r2 = _RGBA32(0, 128, 0, 200)
  16. _DONTBLEND '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OK now????  YES   but _DONTBLEND ruins transparency to make border lines invisible.
  17. LINE (103, 103)-STEP(100, 100), r1, B
  18. PRINT POINT(103, 103); "  "; POINT(110, 110)
  19. PAINT (109, 109), r2, r1
  20. PRINT POINT(103, 103); "  "; POINT(110, 110)
  21.  

Ha! I reread Petr's post and have retested pretty much what he had already said, sorry Petr some of us are slow readers (me).
I too tried my own PAINT algorithm a recursive one and crashed until limited checking to only one or two directions. So why not do one direction at a time, nope, tried and doesn't work either. I too am wondering how Pathfinding (and Fire and Minesweeper) worked so well because same deal, basically.

There must be a way, QB64 can do anything any other program can do, though might be slower....
Title: Re: Paint Image
Post by: bplus on November 22, 2019, 11:07:05 am
Hi Bplus

about  thisI can disagree  because it seems that POINT works
Code: QB64: [Select]
  1. CONST r1 = _RGBA32(200, 0, 0, 255), r2 = _RGBA32(200, 0, 0, 200), r3 = _RGBA32(180, 0, 0, 155)
  2.  
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4.  
  5. CIRCLE (100, 100), 100, r1
  6. PRINT POINT(100, 100); "  "; POINT(100, 200)
  7. PAINT (100, 100), r2, r1
  8. PRINT POINT(100, 100); "  "; POINT(100, 200)

About why PAINT doesn't recognize BorderColor%  because in Wiki BorderColor% can be also a Long32  and not only an integer
http://qb64.org/wiki/PAINT (http://qb64.org/wiki/PAINT)

moreover there is something broken in the PAINT command implementation for its alternating working well/bad

see here
Code: QB64: [Select]
  1. CONST r1 = _RGBA32(200, 0, 0, 255), r2 = _RGBA32(199, 0, 0, 200)
  2. CONST r3 = _RGBA32(200, 0, 0, 255), r4 = _RGBA32(199, 0, 0, 230), r5 = _RGBA32(180, 0, 0, 255)
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4.  
  5. CIRCLE (100, 100), 100, r1
  6. PRINT POINT(100, 100); "  "; POINT(100, 200)
  7. PAINT (100, 100), r2, r1
  8. PRINT POINT(100, 100); "  "; POINT(100, 200)
  9. LINE (200, 200)-STEP(50, 70), r3, B
  10. PAINT STEP(-10, -10), r4, r3 '<--- this paint works
  11. LINE (100, 100)-(150, 170), r5, BF
  12. PRINT POINT(201, 201); "  "; POINT(101, 101)
  13. PAINT (1, 1), r3, r5 '<-- this paint works
  14. LINE (300, 100)-(404, 404), r4, B
  15. PAINT (400, 400), r2, r4 ' <-- this paint doesn't work
  16.  
  17.  

but POINT seems to work in these examples.

OK TempdiBasic, POINT does work, thanks!

And it looks to me like where PAINT does work, your Border Color is full Alpha 255 and where it doesn't work your Border Color is not full Alpha.
Title: Re: Paint Image
Post by: SMcNeill on November 22, 2019, 02:55:27 pm
Here's half an idea for a paint fill which I was working on; you might consider finishing it up:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. _TITLE "Test Fill"
  3. LINE (100, 100)-(500, 400), -1, B
  4. Fill 200, 200, &HFFFF0000, -1
  5. CIRCLE (320, 240), 200, -1
  6. Fill 320, 240, &HFFFF0000, -1
  7. CIRCLE (320, 240), 200, -1
  8. Fill 220, 240, &HFFFF0000, -1
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. SUB Fill (Ox, Oy, fillkolor AS _UNSIGNED LONG, kolor AS _UNSIGNED LONG)
  19.     TYPE Boundry
  20.         LeftX AS INTEGER
  21.         RightX AS INTEGER
  22.     END TYPE
  23.     DIM Array(_HEIGHT - 1) AS Boundry
  24.  
  25.     FOR y = Oy TO _HEIGHT - 1
  26.         FOR x = Ox TO _WIDTH - 1
  27.             IF POINT(x + 1, y) <> kolor THEN Array(y).RightX = x ELSE EXIT FOR
  28.         NEXT
  29.         FOR x = Ox TO 0 STEP -1
  30.             IF POINT(x - 1, y) <> kolor THEN Array(y).LeftX = x ELSE EXIT FOR
  31.         NEXT
  32.         IF POINT(Ox, y + 1) = kolor THEN EXIT FOR
  33.     NEXT
  34.     FOR y = Oy TO 0 STEP -1
  35.         FOR x = Ox TO _WIDTH - 1
  36.             IF POINT(x + 1, y) <> kolor THEN Array(y).RightX = x ELSE EXIT FOR
  37.         NEXT
  38.         FOR x = Ox TO 0 STEP -1
  39.             IF POINT(x - 1, y) <> kolor THEN Array(y).LeftX = x ELSE EXIT FOR
  40.         NEXT
  41.         IF POINT(Ox, y - 1) = kolor THEN EXIT FOR
  42.     NEXT
  43.  
  44.     FOR y = 0 TO _HEIGHT - 1
  45.         LINE (Array(y).LeftX, y)-(Array(y).RightX, y), fillkolor, BF
  46.     NEXT

As you can tell, this doesn't fully fill our area for us, in all cases, but it does fill a large portion for us.  At this point, all we should really need to do is run the routine recursively again around the end points of the square we've created.  I was going to finish sorting it out, but my wife ended up in the hospital again with her asthma acting up terribly.  I don't know how much free time I'll have until she gets home again, so I might not be able to follow-up and finish the concept for quite some time if nobody else is interested in doing it...

The advantage to running the routine in this manner is that it fills huge chunks of our screen at a time in boxes, without running recursively on each point.  The number of recursive calls is going to be phenomenally smaller than what we'd have if we checked each point individually, and probably wouldn't run out of memory or stack space on us.

I won't promise that it'll work, but I think the concept is sound.  ;)
Title: Re: Paint Image
Post by: Petr on November 22, 2019, 03:53:45 pm
Hi Steve,
I'd love to look at your concept, but it won't be right away. I have a visit that I have to give attention. So maybe in two days there will be time. May it all go well with your wife and she will soon be home. P.
Title: Re: Paint Image
Post by: TempodiBasic on November 22, 2019, 06:51:57 pm
@Bplus

Quote
And it looks to me like where PAINT does work, your Border Color is full Alpha 255 and where it doesn't work your Border Color is not full Alpha

yes this code confirm the theory of 255 alpha goodness!

Code: QB64: [Select]
  1. CONST r1 = _RGBA32(200, 0, 0, 255), r2 = _RGBA32(199, 0, 0, 200)
  2. CONST r3 = _RGBA32(200, 0, 0, 255), r4 = _RGBA32(199, 0, 0, 230), r5 = _RGBA32(180, 0, 0, 255)
  3. ' r1 r3 r5 are 255Alpha, r4 230Alpha and r2 200Alpha
  4.  
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6.  
  7. CIRCLE (100, 100), 100, r1
  8. PAINT (100, 100), r2, r1 '<- r1 255Alpha  / r2 200Alpha THIS WORKS
  9. LOCATE 20, 1: PRINT "circle color r1 255 alpha, fill r2 200 alpha"
  10. LINE (200, 200)-STEP(50, 70), r3, B
  11. PAINT STEP(-10, -10), r4, r3 '<---r3 255Alpha / r4 230Alpha   THIS WORKS
  12. LOCATE 20, 1: PRINT "box color r3 255 alpha, fill r4 230 alpha"
  13. LINE (100, 100)-(150, 170), r5, BF
  14. LINE (200, 200)-STEP(50, 70), r5, B
  15. PAINT (1, 1), r3, r5 '<-- r5 255Alpha/ r3 255Alpha       THIS WORKS
  16. LOCATE 22, 1: PRINT "box color r5 255 alpha, fill r3 255 alpha"
  17. LINE (300, 100)-(404, 404), r4, B
  18. PAINT (400, 400), r2, r4 ' <-- r4 230Alpha / r2 200Alpha   THIS  DOESN'T WORK
  19. LOCATE 20, 1: PRINT "box color r4 230 alpha, fill r2 200 alpha"
  20. LINE (300, 100)-(404, 404), r2, B
  21. PAINT (400, 400), r4, r2 ' <-- r4 230Alpha / r2 200Alpha THIS DOESN'T WORK
  22. LOCATE 20, 1: PRINT "box color r2 200 alpha, fill r4 230 alpha"
  23. 'LINE (300, 100)-(404, 404), r1, B
  24. CIRCLE (400, 400), 50, r1
  25. PAINT (400, 400), r2, r1 ' <-- r1 255Alpha / r2 200Alpha THIS WORKS
  26. LOCATE 20, 1: PRINT "box color r1 255 alpha, fill r2 200 alpha"
  27.  
  28. CIRCLE (400, 400), 50, r2
  29. PAINT (400, 400), r2, r2 ' <-- r2 200Alpha / r2 200Alpha THIS DOESN'T WORK
  30. LOCATE 20, 1: PRINT "box color r2 200 alpha, fill r2 200 alpha"
  31.  
Title: Re: Paint Image
Post by: TempodiBasic on November 22, 2019, 07:07:47 pm
Hi Bplus
about the idea to use _DONTBLEND
here is a workaround that must be coded in a function that stores and then draws back the frame of the area to be painted.

Code: QB64: [Select]
  1. 'CONST r1 = &HFFBB0000, r2 = &HFF00BB00 'OK paint works right with line box
  2. 'CONST r1 = _RGB32(200, 0, 0), r2 = _RGB32(0, 128, 0) ' <<<<<<<  screws up doesn't even draw box!!!
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4. _SCREENMOVE 300, 40
  5.  
  6.  
  7. ' ok normal paint working
  8. r1 = _RGB32(200, 0, 0)
  9. r2 = _RGB32(0, 128, 0)
  10.  
  11. ' and alpha paint NOT working
  12. 'CLS '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< might work now, nope!
  13.  
  14. r1 = _RGBA32(200, 0, 0, 1) 'try nearly invisible color
  15. r2 = _RGBA32(0, 128, 0, 200)
  16. back = _RGBA(0, 0, 0, 255)
  17. CLS , back
  18. _DONTBLEND '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OK now????  YES   but _DONTBLEND ruins transparency to make border lines invisible.
  19. LINE (103, 103)-STEP(100, 100), r1, B '<- this must be converted in a function that stores the frame of the area to paint
  20. PRINT POINT(103, 103); "  "; POINT(110, 110)
  21. PAINT (109, 109), r2, r1
  22. PRINT POINT(103, 103); "  "; POINT(110, 110)
  23. _BLEND ' reactivate alpha
  24. LINE (103, 103)-STEP(100, 100), back, B '<- here the function that draws  back the frame
  25. PRINT POINT(103, 103); "  "; POINT(110, 110)
  26. LOCATE 15, 1: PRINT r1, r2, back
this can be an alternative idea to Paint method.
Title: Re: Paint Image
Post by: SMcNeill on November 22, 2019, 07:13:50 pm
Non-Recursive PaintFill.  At this point, it's slower than heck, but it works!

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2.  
  3.  
  4. LINE (100, 100)-(300, 300), -1, BF
  5. CIRCLE (300, 300), 100, -1
  6. PAINT (301, 301), -1
  7.  
  8.  
  9. fill 200, 200, &HFFFF0000, 0
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. SUB fill (x, y, kolor AS _UNSIGNED LONG, backkolor AS _UNSIGNED LONG)
  19.     DIM Array(-1 TO _WIDTH, -1 TO _HEIGHT)
  20.     pass = 1
  21.     Array(x, y) = pass
  22.     DO
  23.         finished = -1
  24.         FOR x = 0 TO _WIDTH - 1
  25.             FOR y = 0 TO _HEIGHT - 1
  26.                 IF Array(x, y) = pass THEN
  27.                     IF x - 1 >= 0 THEN
  28.                         IF Array(x - 1, y) = 0 AND POINT(x - 1, y) <> backkolor THEN Array(x - 1, y) = pass + 1: finished = 0
  29.                     END IF
  30.                     IF x + 1 < _WIDTH THEN
  31.                         IF Array(x + 1, y) = 0 AND POINT(x + 1, y) <> backkolor THEN Array(x + 1, y) = pass + 1: finished = 0
  32.                     END IF
  33.                     IF y - 1 >= 0 THEN
  34.                         IF Array(x, y - 1) = 0 AND POINT(x, y - 1) <> backkolor THEN Array(x, y - 1) = pass + 1: finished = 0
  35.                     END IF
  36.                     IF y + 1 <= _HEIGHT THEN
  37.                         IF Array(x, y + 1) = 0 AND POINT(x, y + 1) <> backkolor THEN Array(x, y + 1) = pass + 1: finished = 0
  38.                     END IF
  39.                 END IF
  40.             NEXT
  41.         NEXT
  42.         pass = pass + 1
  43.     LOOP UNTIL finished
  44.  
  45.     FOR x = 0 TO _WIDTH
  46.         FOR y = 0 TO _HEIGHT
  47.             IF Array(x, y) THEN PSET (x, y), kolor
  48.         NEXT
  49.     NEXT

This may not be so impossible to make use of, once it's optimized for _MEM.  As it is now, it's good for a one time "change it and save it" type routine, but I definitely wouldn't rely on it for anything performance heavy.
Title: Re: Paint Image
Post by: TempodiBasic on November 22, 2019, 07:18:23 pm
@Steve
Good Luck with illness of your wife!
I wish you'll come back at home together  soon safe and healthy !

PS I find your idea genial and I think that we must adapt it for any kind of shape!
Title: Re: Paint Image
Post by: bplus on November 22, 2019, 08:18:21 pm
Non-Recursive PaintFill.  At this point, it's slower than heck, but it works!

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2.  
  3.  
  4. LINE (100, 100)-(300, 300), -1, BF
  5. CIRCLE (300, 300), 100, -1
  6. PAINT (301, 301), -1
  7.  
  8.  
  9. fill 200, 200, &HFFFF0000, 0
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. SUB fill (x, y, kolor AS _UNSIGNED LONG, backkolor AS _UNSIGNED LONG)
  19.     DIM Array(-1 TO _WIDTH, -1 TO _HEIGHT)
  20.     pass = 1
  21.     Array(x, y) = pass
  22.     DO
  23.         finished = -1
  24.         FOR x = 0 TO _WIDTH - 1
  25.             FOR y = 0 TO _HEIGHT - 1
  26.                 IF Array(x, y) = pass THEN
  27.                     IF x - 1 >= 0 THEN
  28.                         IF Array(x - 1, y) = 0 AND POINT(x - 1, y) <> backkolor THEN Array(x - 1, y) = pass + 1: finished = 0
  29.                     END IF
  30.                     IF x + 1 < _WIDTH THEN
  31.                         IF Array(x + 1, y) = 0 AND POINT(x + 1, y) <> backkolor THEN Array(x + 1, y) = pass + 1: finished = 0
  32.                     END IF
  33.                     IF y - 1 >= 0 THEN
  34.                         IF Array(x, y - 1) = 0 AND POINT(x, y - 1) <> backkolor THEN Array(x, y - 1) = pass + 1: finished = 0
  35.                     END IF
  36.                     IF y + 1 <= _HEIGHT THEN
  37.                         IF Array(x, y + 1) = 0 AND POINT(x, y + 1) <> backkolor THEN Array(x, y + 1) = pass + 1: finished = 0
  38.                     END IF
  39.                 END IF
  40.             NEXT
  41.         NEXT
  42.         pass = pass + 1
  43.     LOOP UNTIL finished
  44.  
  45.     FOR x = 0 TO _WIDTH
  46.         FOR y = 0 TO _HEIGHT
  47.             IF Array(x, y) THEN PSET (x, y), kolor
  48.         NEXT
  49.     NEXT

This may not be so impossible to make use of, once it's optimized for _MEM.  As it is now, it's good for a one time "change it and save it" type routine, but I definitely wouldn't rely on it for anything performance heavy.

And guess what guys, POINT fails us, try Steve's code with a transparent color for border color.

I just came up with similar non recursive and it fails because POINT fails. I tried border colors with _RGBA32 and with &H and even used the POINT color at the border of a box to be filled, they all fail to stop the fill.
Title: Re: Paint Image
Post by: bplus on November 22, 2019, 08:34:21 pm
Here is my test code:
Code: QB64: [Select]
  1. _TITLE "Fill test Steve" 'mod b+ 2019-11-22
  2.  
  3. CONST xmax = 800, ymax = 600
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5. _SCREENMOVE 300, 40
  6. DIM i, ptGreen AS _UNSIGNED LONG
  7.  
  8.  
  9. 'try each one of these, solids work transparents don't!
  10. ptGreen = _RGBA32(0, 128, 0, 255) 'solid
  11. 'ptGreen = _RGBA32(0, 128, 0, 5) 'transparent
  12. 'ptGreen = &HFF008000 'solid
  13. 'ptGreen = &HF0008000 'transparent
  14.  
  15.  
  16. LINE (510, 510)-(520, 520), ptGreen, B
  17. 'ptGreen = POINT(510, 510)  '<<<<<<<<try with or without comment
  18. sfill 515, 515, &HFFFF0000, ptGreen
  19.  
  20. 'FOR i = 100 TO 100.75 STEP .25
  21. CIRCLE (100, 100), 100, &HFFFFFFFF
  22. 'NEXT
  23. sfill 100, 100, &HFFFF0000, &HFFFFFFFF
  24.  
  25. PRINT "done"
  26.  
  27. SUB sfill (x, y, kolor AS _UNSIGNED LONG, backkolor AS _UNSIGNED LONG)
  28.     DIM Array(-1 TO _WIDTH, -1 TO _HEIGHT)
  29.     DIM pass, finished
  30.     pass = 1
  31.     Array(x, y) = pass
  32.     DO
  33.         finished = -1
  34.         FOR x = 0 TO _WIDTH - 1
  35.             FOR y = 0 TO _HEIGHT - 1
  36.                 IF Array(x, y) = pass THEN
  37.                     IF x - 1 >= 0 THEN
  38.                         IF Array(x - 1, y) = 0 AND POINT(x - 1, y) <> backkolor THEN Array(x - 1, y) = pass + 1: finished = 0
  39.                     END IF
  40.                     IF x + 1 < _WIDTH THEN
  41.                         IF Array(x + 1, y) = 0 AND POINT(x + 1, y) <> backkolor THEN Array(x + 1, y) = pass + 1: finished = 0
  42.                     END IF
  43.                     IF y - 1 >= 0 THEN
  44.                         IF Array(x, y - 1) = 0 AND POINT(x, y - 1) <> backkolor THEN Array(x, y - 1) = pass + 1: finished = 0
  45.                     END IF
  46.                     IF y + 1 <= _HEIGHT THEN
  47.                         IF Array(x, y + 1) = 0 AND POINT(x, y + 1) <> backkolor THEN Array(x, y + 1) = pass + 1: finished = 0
  48.                     END IF
  49.                 END IF
  50.             NEXT
  51.         NEXT
  52.         pass = pass + 1
  53.     LOOP UNTIL finished
  54.  
  55.     FOR x = 0 TO _WIDTH
  56.         FOR y = 0 TO _HEIGHT
  57.             IF Array(x, y) THEN PSET (x, y), kolor
  58.         NEXT
  59.     NEXT
  60.  
  61.  

PS This was same test code I was using with my non recursive Fill but mine was leaking through diagonal neighbors so CIRCLE had to be triple walled or it leaked whereas B option in LINE worked without renenforced walls.
Title: Re: Paint Image
Post by: bplus on November 22, 2019, 08:43:32 pm
This glitch with POINT is most curious as I just got done this morning proving to myself it was healthy???

So our attempts at using an alternate routine for PAINT fill are futile until we get POINT figured out.
Title: Re: Paint Image
Post by: SMcNeill on November 22, 2019, 08:50:35 pm
Point isn’t failing; your bordercolor fails.

PSET (x,y), _RGBA32(255,255,255,128)

Now, PSET that over a white background, a red background, and a black background.  Is the color on your screen going to still be _RGBA32(255,255,255,128), or is it going to be a blended version of that color?  Bright white (barely toned down), Pink, and then dull white/gray are going to be your screen colors.  Using that value as a paint border isn’t going to work as that color doesn’t actually exist on your screen.

One important thing will *always* keep it from existing: the visible display doesn’t allow any alpha less than 255.  At least, it hasn’t in any of my past testing.
Title: Re: Paint Image
Post by: bplus on November 22, 2019, 08:59:20 pm
Point isn’t failing; your bordercolor fails.

PSET (x,y), _RGBA32(255,255,255,128)

Now, PSET that over a white background, a red background, and a black background.  Is the color on your screen going to still be _RGBA32(255,255,255,128), or is it going to be a blended version of that color?  Bright white (barely toned down), Pink, and then dull white/gray are going to be your screen colors.  Using that value as a paint border isn’t going to work as that color doesn’t actually exist on your screen.

One important thing will *always* keep it from existing: the visible display doesn’t allow any alpha less than 255.  At least, it hasn’t in any of my past testing.

Then why are we making something to replace PAINT? I thought it was so we could use transparent border colors.

I was trying to be careful that the border was always over black.
Title: Re: Paint Image
Post by: SMcNeill on November 22, 2019, 09:04:44 pm
Then why are we making something to replace PAINT? I thought it was so we could use transparent border colors.

I was trying to be careful that the border was always over black.

I thought it was so could paint an image/texture over something, which is an ability PAINT doesn’t offer.  (Or was just looking for a speedier alternative?)
Title: Re: Paint Image
Post by: bplus on November 22, 2019, 09:14:26 pm
OK maybe if we could Fill the border along with the fill of the innards, that would do very nicely.

What do you think? possible?
Title: Re: Paint Image
Post by: bplus on November 22, 2019, 09:38:31 pm
New and improved use of paintImage, look ma, no Border lines!!!

Code: QB64: [Select]
  1. _TITLE "Brick Pattern Tile, click a spot to spray paint a brick image."
  2. CONST xmax = 800, ymax = 600
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 40
  5. 'make brick pattern
  6. brickpat& = _NEWIMAGE(16, 16, 32)
  7. _DEST brickpat&
  8. LINE (0, 0)-(_WIDTH(brickpat&) - 1, _HEIGHT(brickpat&) - 1), _RGB32(128, 0, 0), BF
  9. LINE (0, 0)-(_WIDTH(brickpat&) - 1, 0), _RGB32(200, 200, 200), BF
  10. LINE (0, 7)-(_WIDTH(brickpat&) - 1, 8), _RGB32(200, 200, 200), BF
  11. LINE (0, 15)-(_WIDTH(brickpat&) - 1, 15), _RGB32(200, 200, 200), BF
  12. LINE (0, 0)-(1, 8), _RGB32(200, 200, 200), BF
  13. LINE (7, 8)-(8, 15), _RGB32(200, 200, 200), BF
  14.  
  15. BC = _RGB32(119, 17, 2)
  16. WHILE _KEYDOWN(27) = 0
  17.     mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  18.     IF mb THEN
  19.         r = r + 1
  20.         IF r > 20 THEN r = 1
  21.         CIRCLE (mx, my), 50, BC
  22.         paintImage mx, my, BC, 0, brickpat&
  23.     END IF
  24.     _DISPLAY
  25.     _LIMIT 60
  26.  
  27. SUB paintImage (x, y, Border~&, destHandle&, imageHandle&)
  28.     d = _DEST: s = _SOURCE
  29.     _DEST destHandle&
  30.     PAINT (x, y), BC, Border~&
  31.     FOR y = 0 TO _HEIGHT(destHandle&)
  32.         FOR x = 0 TO _WIDTH(destHandle&)
  33.             _SOURCE destHandle&
  34.             IF POINT(x, y) = BC THEN
  35.                 _SOURCE imageHandle&
  36.                 PSET (x, y), POINT(x MOD _WIDTH(imageHandle&), y MOD _HEIGHT(imageHandle&))
  37.             END IF
  38.         NEXT
  39.     NEXT
  40.     _DEST d: _SOURCE s
  41.  
  42.  
  43.  

One of those dah... eureka moments. Spray paint a brickwall pattern:

Title: Re: Paint Image
Post by: TempodiBasic on November 24, 2019, 10:36:27 am
Cool!
Go behind  the limit of BorderColor% !
Yes put away the border and paint in the limit of the area!

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

But what do you think about POINT? what is the point of POINT with alpha channell?
Do POINT read and bring back the fusion of more colors in the same pixel in alphachannel?
It is possible an empowered function _POINT that can distinguish between colors merged into the pixel? (I think no but I'm not expert and I have a poor knowledge of graphic hardware).
Thanks to read
Title: Re: Paint Image
Post by: bplus on November 24, 2019, 11:49:01 am
Hi TempodiBasic,

I am totally confused by POINT, it reports numbers correctly but according to Steve:
Quote
One important thing will *always* keep it from existing: the visible display doesn’t allow any alpha less than 255.  At least, it hasn’t in any of my past testing.

It seems true in my test of using an Alpha (less than 255) for a border control both with PAINT and with fill routines.

So strange, it reports the right number but won't work in display???

Remember I tested it earlier in this thread when you complained about my comment about using POINT and detecting Alpha and the test said it could read alpha (over black) the same if over black, and you did have to CLS first for black background.

I don't know, another Life Mystery!
Title: Re: Paint Image
Post by: Petr on November 24, 2019, 12:26:37 pm
Just a note. Each _NEWIMAGE screen has a RGBA32 background 0,0,0,0, this changes to 0,0,0,255 when CLS is used.
Title: Re: Paint Image
Post by: Petr on November 25, 2019, 10:23:56 am
I didn't find my original fill program, so wrote it again. It's not fast, but he doesn't mind the alpha. I'll keep doing it. I will add padding support. The program does not need to know the color number of the color border, the boundaries of the filled color can be different.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. CIRCLE (400, 400), 150, &HFFFF0000
  3. LINE (300, 450)-(500, 150), &H4AEEC2F7, B
  4. LINE (370, 370)-(430, 430), &HFFFF0000, BF
  5. CIRCLE (400, 300), 460, &H1744F3FF
  6.  
  7. Fill 400, 200, &H4AEEC2F7
  8. Fill 400, 300, &HFFFFFF00
  9. Fill 1, 1, &HFFFFFFFF
  10. Fill 200, 440, &HE0FFFFFF
  11. Fill 400, 500, &HDF00FF00
  12.  
  13.  
  14.  
  15.  
  16.  
  17. SUB Fill (x AS INTEGER, y AS INTEGER, clr AS _UNSIGNED LONG)
  18.     TYPE border
  19.         X AS INTEGER
  20.         Y AS INTEGER
  21.     END TYPE
  22.     'z bodu plneni jede vpravo a udela caru od bodu plneni k okraji. Tyto body zapise do pole.
  23.     'from fill points X, Y go to right and draw line. This points are writed to array B.
  24.  
  25.     REDIM B(0) AS border
  26.     DIM bck AS _UNSIGNED LONG
  27.     bck = POINT(x, y)
  28.     px = x: py = y
  29.  
  30.  
  31.  
  32.     WHILE bck = POINT(px, py)
  33.         REDIM _PRESERVE B(i) AS border
  34.  
  35.         B(i).X = px
  36.         B(i).Y = py
  37.         i = i + 1
  38.         px = px + 1
  39.     WEND
  40.     ' od x do prava
  41.     '-----------------------------------------------------------------------------------------
  42.     'from fill points X, Y go to left, points are writed to array B, draw line.
  43.  
  44.  
  45.     px = x: py = y
  46.     WHILE bck = POINT(px, py)
  47.         REDIM _PRESERVE B(i) AS border
  48.  
  49.         B(i).X = px
  50.         B(i).Y = py
  51.         i = i + 1
  52.         px = px - 1
  53.     WEND
  54.  
  55.     i = 0
  56.     'od X do leva
  57.     'Start in: REDIM (C)....  from all points in array B fill to bottom. Write this points to array C.
  58.  
  59.  
  60.     REDIM C(0) AS border
  61.     'vyplni vechny body od predchozi linie plneni smerem dolu.
  62.     FOR p = 0 TO UBOUND(b)
  63.         Fx = B(i).X
  64.         Fy = B(i).Y
  65.         WHILE bck = POINT(Fx, Fy)
  66.             PSET (Fx, Fy), clr~&
  67.             C(j).X = Fx
  68.             C(j).Y = Fy
  69.             Fy = Fy + 1
  70.             j = j + 1
  71.             REDIM _PRESERVE C(j) AS border
  72.         WEND
  73.         i = i + 1
  74.     NEXT p
  75.  
  76.  
  77.     'vyplni predchozi linie plneni smerem nahoru
  78.     'from all points in array B fill to ceiling. Write this points to array C.
  79.  
  80.     i = 0
  81.     FOR p = 0 TO UBOUND(b)
  82.         Fx = B(i).X
  83.         Fy = B(i).Y - 1
  84.         WHILE bck = POINT(Fx, Fy)
  85.             PSET (Fx, Fy), clr~&
  86.             C(j).X = Fx
  87.             C(j).Y = Fy
  88.             Fy = Fy - 1
  89.             j = j + 1
  90.             REDIM _PRESERVE C(j) AS border
  91.         WEND
  92.         i = i + 1
  93.     NEXT p
  94.  
  95.  
  96.     'nize: z bodu v poli C jet vlevo a vpravo, nahoru a dolu.
  97.     'do this 4x:
  98.     'look if neigthbour point is BCK. Starting points are contained in Array C. Look to left, right, up and down. If this color is BCK, fill it until
  99.     'is color other than BCK. Write this points to array B. After then is S selected and loop go again. After then write values from array B to array C
  100.     'and search again. Total search: 4x.
  101.  
  102.  
  103.     REDIM B(0) AS border
  104.  
  105.     FOR search = 1 TO 4
  106.         i = 0
  107.         FOR p = 0 TO UBOUND(c)-1
  108.             FOR s = 1 TO 4
  109.                 Fx = C(p).X
  110.                 Fy = C(p).Y
  111.  
  112.                 SELECT CASE s
  113.                     CASE 1: Sx = 1: sy = 0
  114.                     CASE 2: Sx = -1: sy = 0
  115.                     CASE 3: sy = 1: Sx = 0
  116.                     CASE 4: sy = -1: Sx = 0
  117.                 END SELECT
  118.  
  119.                 WHILE bck = POINT(Fx + Sx, Fy + sy)
  120.                     PSET (Fx + Sx, Fy + sy), clr
  121.                     Fx = Fx + Sx
  122.                     Fy = Fy + sy
  123.                     B(i).X = Fx
  124.                     B(i).Y = Fy
  125.                     i = i + 1
  126.                     REDIM _PRESERVE B(i) AS border
  127.                 WEND
  128.             NEXT s
  129.         NEXT p
  130.  
  131.  
  132.         REDIM C(i - 1) AS border
  133.         FOR L = 0 TO i - 1
  134.             C(L).X = B(L).X
  135.             C(L).Y = B(L).Y
  136.         NEXT
  137.     NEXT search
  138.     ERASE C
  139.     ERASE B
  140.  

Title: Re: Paint Image
Post by: bplus on November 25, 2019, 10:52:17 am
Hi Petr,

Looks like it just does the color it lands on at x, y, also looks pretty fast compared to my effort:
https://www.qb64.org/forum/index.php?topic=1914.msg111421#msg111421

Did you compare times with Steve's Magic filler?
Title: Re: Paint Image
Post by: Petr on November 25, 2019, 11:41:55 am
BPlus, this example show better, what can you do with my fill program, what PAINT can not do:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. CIRCLE (400, 400), 150, &HFFFF0000
  3. LINE (300, 450)-(500, 150), &H4AEEC2F7, BF
  4. LINE (370, 370)-(430, 430), &HFFFF0000, BF
  5. CIRCLE (400, 300), 460, &H1744F3FF
  6. PRINT "How to fill the black area in a circle now, without damaging the square? - others color borders"
  7. PRINT "Press key..."
  8.  
  9.  
  10.  
  11.  
  12. Fill 400, 530, &HADFFFFFF
  13.  
  14.  
  15.  
  16.  
  17.  
  18. SUB Fill (x AS INTEGER, y AS INTEGER, clr AS _UNSIGNED LONG)
  19.     TYPE border
  20.         X AS INTEGER
  21.         Y AS INTEGER
  22.     END TYPE
  23.     'z bodu plneni jede vpravo a udela caru od bodu plneni k okraji. Tyto body zapise do pole.
  24.     'from fill points X, Y go to right and draw line. This points are writed to array B.
  25.  
  26.     REDIM B(0) AS border
  27.     DIM bck AS _UNSIGNED LONG
  28.     bck = POINT(x, y)
  29.     px = x: py = y
  30.  
  31.  
  32.  
  33.     WHILE bck = POINT(px, py)
  34.         REDIM _PRESERVE B(i) AS border
  35.  
  36.         B(i).X = px
  37.         B(i).Y = py
  38.         i = i + 1
  39.         px = px + 1
  40.     WEND
  41.     ' od x do prava
  42.     '-----------------------------------------------------------------------------------------
  43.     'from fill points X, Y go to left, points are writed to array B, draw line.
  44.  
  45.  
  46.     px = x: py = y
  47.     WHILE bck = POINT(px, py)
  48.         REDIM _PRESERVE B(i) AS border
  49.  
  50.         B(i).X = px
  51.         B(i).Y = py
  52.         i = i + 1
  53.         px = px - 1
  54.     WEND
  55.  
  56.     i = 0
  57.     'od X do leva
  58.     'Start in: REDIM (C)....  from all points in array B fill to bottom. Write this points to array C.
  59.  
  60.  
  61.     REDIM C(0) AS border
  62.     'vyplni vechny body od predchozi linie plneni smerem dolu.
  63.     FOR p = 0 TO UBOUND(b)
  64.         Fx = B(i).X
  65.         Fy = B(i).Y
  66.         WHILE bck = POINT(Fx, Fy)
  67.             PSET (Fx, Fy), clr~&
  68.             C(j).X = Fx
  69.             C(j).Y = Fy
  70.             Fy = Fy + 1
  71.             j = j + 1
  72.             REDIM _PRESERVE C(j) AS border
  73.         WEND
  74.         i = i + 1
  75.     NEXT p
  76.  
  77.  
  78.     'vyplni predchozi linie plneni smerem nahoru
  79.     'from all points in array B fill to ceiling. Write this points to array C.
  80.  
  81.     i = 0
  82.     FOR p = 0 TO UBOUND(b)
  83.         Fx = B(i).X
  84.         Fy = B(i).Y - 1
  85.         WHILE bck = POINT(Fx, Fy)
  86.             PSET (Fx, Fy), clr~&
  87.             C(j).X = Fx
  88.             C(j).Y = Fy
  89.             Fy = Fy - 1
  90.             j = j + 1
  91.             REDIM _PRESERVE C(j) AS border
  92.         WEND
  93.         i = i + 1
  94.     NEXT p
  95.  
  96.  
  97.     'nize: z bodu v poli C jet vlevo a vpravo, nahoru a dolu.
  98.     'do this 4x:
  99.     'look if neigthbour point is BCK. Starting points are contained in Array C. Look to left, right, up and down. If this color is BCK, fill it until
  100.     'is color other than BCK. Write this points to array B. After then is S selected and loop go again. After then write values from array B to array C
  101.     'and search again. Total search: 4x.
  102.  
  103.  
  104.     REDIM B(0) AS border
  105.  
  106.     FOR search = 1 TO 4
  107.         i = 0
  108.         FOR p = 0 TO UBOUND(c)-1
  109.             FOR s = 1 TO 4
  110.                 Fx = C(p).X
  111.                 Fy = C(p).Y
  112.  
  113.                 SELECT CASE s
  114.                     CASE 1: Sx = 1: sy = 0
  115.                     CASE 2: Sx = -1: sy = 0
  116.                     CASE 3: sy = 1: Sx = 0
  117.                     CASE 4: sy = -1: Sx = 0
  118.                 END SELECT
  119.  
  120.                 WHILE bck = POINT(Fx + Sx, Fy + sy)
  121.                     PSET (Fx + Sx, Fy + sy), clr
  122.                     Fx = Fx + Sx
  123.                     Fy = Fy + sy
  124.                     B(i).X = Fx
  125.                     B(i).Y = Fy
  126.                     i = i + 1
  127.                     REDIM _PRESERVE B(i) AS border
  128.                 WEND
  129.             NEXT s
  130.         NEXT p
  131.  
  132.  
  133.         REDIM C(i - 1) AS border
  134.         FOR L = 0 TO i - 1
  135.             C(L).X = B(L).X
  136.             C(L).Y = B(L).Y
  137.         NEXT
  138.     NEXT search
  139.     ERASE C
  140.     ERASE B
  141.  

I didn't compare speed with Steve. There's no point in proving I'm better :)  (THIS IS JOKE!)
Frankly, I will use this function to draw an image, and then I will put the finished image on the screen in a program. Using color filling while running a program is nonsense. This is an unnecessary load on the processor. I will not solve the speed, I will solve the fill - so as in the  QB4.5. I do not share claim, that working with a program below 256 colors is a waste of time. Not for me.
Title: Re: Paint Image
Post by: TempodiBasic on November 25, 2019, 01:29:57 pm
about Petr's affirmation
Quote
Just a note. Each _NEWIMAGE screen has a RGBA32 background 0,0,0,0, this changes to 0,0,0,255 when CLS is used.
i'll go on and I try this study of POINT in SCREEN 32bit

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. PRINT " USING COLORS AS VARIABLE _UNSIGNED LONG"
  3. PRINT "LET'S SEE DIFFERENCE BETWEEN POINT ON NATIVE BACKGROUND "
  4. PRINT "  POINT    POINT+BACKGROUND       KOLOR     BLACK BACKGROUND"
  5. C1 = _RGBA32(0, 127, 127, 10)
  6. C2 = _RGBA32(10, 100, 20, 100)
  7. C3 = _RGBA32(10, 10, 127, 150)
  8. C4 = _RGBA32(127, 10, 10, 200)
  9. C5 = _RGBA32(200, 100, 4, 230)
  10. FOR a = 1 TO 5 STEP 1
  11.     IF a = 1 THEN kolor = C1
  12.     IF a = 2 THEN kolor = C2
  13.     IF a = 3 THEN kolor = C3
  14.     IF a = 4 THEN kolor = C4
  15.     IF a = 5 THEN kolor = C5
  16.     CIRCLE (400, 200), a * 10, kolor
  17.     LOCATE a + 3, 1: PRINT POINT(400, 200 + a * 10), POINT(400, 200 + a * 10) + POINT(400, 200), kolor, POINT(400, 200)
  18.     CIRCLE (200, 200), a * 10, POINT(400, 200 + a * 10)
  19. VIEW PRINT 20 TO 29
  20. VIEW SCREEN(1, 300)-(798, 598), , _RGBA32(1, 127, 127, 255)
  21. PRINT " NOW AFTER CLS WITH BLACK BACKGROUND "
  22. PRINT "  POINT      POINT+BACKGROUND       KOLOR     BLACK BACKGROUND"
  23. FOR a = 1 TO 5 STEP 1
  24.     IF a = 1 THEN kolor = C1
  25.     IF a = 2 THEN kolor = C2
  26.     IF a = 3 THEN kolor = C3
  27.     IF a = 4 THEN kolor = C4
  28.     IF a = 5 THEN kolor = C5
  29.     CIRCLE (400, 500), a * 10, kolor
  30.     LOCATE a + 23, 1: PRINT POINT(400, 500 + a * 10), POINT(400, 500 + a * 10) + POINT(400, 500), kolor, POINT(400, 500)
  31.     CIRCLE (200, 500), a * 10, POINT(400, 500 + a * 10)
  32.  

with this results
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

but tiese results show that in screen 32bit the color are merged to that are yet on the screen so as Petr suggests  before original black background is RGBA 0 0 0 0   while after CLS it becomes 0 0 0 255 getting a different value with POINT!

Good this!
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

and this one !
  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Paint Image
Post by: SMcNeill on November 25, 2019, 02:26:36 pm
Hint:  Use CLS, 0
Title: Re: Paint Image
Post by: TempodiBasic on November 25, 2019, 04:52:50 pm
Steve
Thanks for tip so we can force to use black RGBA 0,0,0,0

result after CLS,0 is the same as in original screen 32bit
  [ This attachment cannot be displayed inline in 'Print Page' view ]