Author Topic: Paint Image  (Read 11929 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Paint Image
« Reply #30 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.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Paint Image
« Reply #31 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.  
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Paint Image
« Reply #32 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.
« Last Edit: November 24, 2019, 10:02:55 am by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Paint Image
« Reply #33 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Paint Image
« Reply #34 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!
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Image
« Reply #35 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.
« Last Edit: November 22, 2019, 08:22:46 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Image
« Reply #36 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.
« Last Edit: November 22, 2019, 08:46:49 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Image
« Reply #37 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.
« Last Edit: November 22, 2019, 08:49:09 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Paint Image
« Reply #38 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Image
« Reply #39 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.
« Last Edit: November 22, 2019, 09:00:41 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Paint Image
« Reply #40 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?)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Image
« Reply #41 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?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Image
« Reply #42 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:

New Improved PAINT IMAGE.PNG
* New Improved PAINT IMAGE.PNG (Filesize: 18.29 KB, Dimensions: 806x630, Views: 186)
« Last Edit: November 22, 2019, 09:44:40 pm by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Paint Image
« Reply #43 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!

 
paintImapge Bplus.jpg


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
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Image
« Reply #44 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!