Author Topic: Understanding hardware images  (Read 5819 times)

0 Members and 1 Guest are viewing this topic.

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: Understanding hardware images
« Reply #30 on: April 30, 2019, 05:58:15 pm »
I'm not able to see what your example does at the moment, but I started this thread because _SETALPHA does not respect an image's pre-existing partially translucent pixels.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Understanding hardware images
« Reply #31 on: May 01, 2019, 06:19:48 am »
Hi. So ... first I wrote a program that confirms what you say. SETALPHA adds a layer with transparency over the original colors. This shows the first part of the program. Then press Esc, please be patient and press + and - to set the alpha channel to rainbow.png for each pixel. I suppose this will be what you're looking for. Gradually extinguish and light up pixels based on their original values. I used slow commands, it can be speeded up if  MEM functions are used.

After pressing minus, the alpha is increased everywhere, not to the same value, but by the previous value of a particular pixel. Note that the blackness of the background around the circle also increases (the number in the upper left corner disappears). Plus shrinks transparency.

Code: QB64: [Select]
  1. 'create transparent image
  2. om = _NEWIMAGE(400, 300, 32)
  3. FOR D = 100 TO 300 STEP 50
  4.     LINE (D, 100)-(D + 49, 200), _RGBA32(255, 255, 255, D - 50), BF
  5.  
  6.  
  7.  
  8.  
  9. nm = _COPYIMAGE(om, 32)
  10. _SETALPHA 25, _RGBA32(0, 0, 0, 0) TO _RGBA32(255, 255, 255, 255), nm
  11.  
  12. SCREEN _NEWIMAGE(800, 600, 32)
  13. _MOUSEMOVE 505, 104
  14. _PUTIMAGE (1, 1), om
  15. _PUTIMAGE (400, 1), nm
  16.  
  17.     PCOPY 1, _DISPLAY
  18.     _SOURCE 0
  19.     alpha1 = _ALPHA32(POINT(_MOUSEX - 400, _MOUSEY))
  20.     alpha2 = _ALPHA32(POINT(_MOUSEX, _MOUSEY))
  21.  
  22.     LOCATE 1, 1: PRINT "Left is original image. Right is image with applied SETALPHA 25 to original image."
  23.     LOCATE 2, 1: PRINT "Original Alpha: "; alpha1; "New Alpha: "; alpha2
  24.     LOCATE 3, 1: PRINT "Press ESC for quit."
  25.     IF _MOUSEX > 0 AND _MOUSEY > 0 THEN
  26.         IF _MOUSEX < 505 THEN _MOUSEMOVE 505, _MOUSEY
  27.         IF _MOUSEY > 200 THEN _MOUSEMOVE _MOUSEX, 200
  28.  
  29.         IF _MOUSEY < 104 THEN _MOUSEMOVE _MOUSEX, 104
  30.         IF _MOUSEX > 750 THEN _MOUSEMOVE 750, _MOUSEY
  31.     END IF
  32.     PSET (_MOUSEX - 400, _MOUSEY), _RGB32(255, 255, 255) - POINT(_MOUSEX - 400, _MOUSEY)
  33.     _DISPLAY
  34.  
  35.     LINE (0, 0)-(800, 100), _RGB32(0, 0, 0), BF
  36.  
  37. _FREEIMAGE om 'original alpha
  38. _FREEIMAGE nm 'new alpha
  39.  
  40.  
  41. im = _LOADIMAGE("rainbow.png", 32)
  42. W = _WIDTH(im)
  43. H = _HEIGHT(im)
  44. DIM Alpha(W, H) AS _UNSIGNED _BYTE
  45. 'DIM newAlpha AS _UNSIGNED _BYTE 'uncomment it for show how it works with owerflow QB64 solution
  46. FOR y = 0 TO H - 1
  47.     FOR x = 0 TO W - 1
  48.         Alpha(x, y) = _ALPHA32(POINT(x, y))
  49. NEXT x, y
  50. _PUTIMAGE (0, 0), im
  51.  
  52.  
  53. DO UNTIL i$ = CHR$(27)
  54.     CLS
  55.     i$ = INKEY$
  56.     SELECT CASE i$
  57.         CASE "+": A = A + 1
  58.         CASE "-": A = A - 1
  59.  
  60.     END SELECT
  61.     LOCATE 1, 1: PRINT A
  62.  
  63.     FOR y = 0 TO H - 1
  64.         FOR x = 0 TO W - 1
  65.             newAlpha = Alpha(x, y) + A
  66.             _SOURCE im
  67.             CurrentColor~& = POINT(x, y)
  68.             IF newAlpha < 0 THEN newAlpha = 0
  69.             NewColor~& = _RGBA32(_RED32(CurrentColor~&), _GREEN32(CurrentColor~&), _BLUE32(CurrentColor~&), newAlpha)
  70.             PSET (x, y), NewColor~&
  71.     NEXT x, y
  72.     i$ = ""
  73.     _DISPLAY
  74.  
« Last Edit: May 01, 2019, 06:26:08 am by Petr »