HP Forums
PIXON_P Alpha blending - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: PIXON_P Alpha blending (/thread-8311.html)



PIXON_P Alpha blending - Cristian Arezzini - 05-06-2017 05:35 PM

Hello,
I have a doubt on how the alpha blending algorithm works. Basically, I want to draw a black screen, and then I want to draw pixels so that the first time I draw a given pixel, it's just barely visible, then after drawing over it more and more, it gets more and more white.
But I noticed that if I do for example:
PIXON_P(X,Y,#F0FFFFFFh)
(which is a pure white pixel with an alpha channel of #F0h), I don't get what I expect. What I get is that after very few "overlaps" (around 10) the pixel stops getting brighter, and stays at a rather dark grey. If I modify the alpha value, to i.e. #F5h, the pixels still saturate after about 10 overlaps, but to a very dark grey instead.
I was expecting that, since I'm drawing a partially transparent pure white pixel, the "saturated" color would be pure white, and that it would take more or less overlaps to get there depending on the transparency level...
What am I doing wrong? How can I get the result I need? Ideally, I'd like to have the pixels get a (1,1,1) color after the first drawing, and get to (255,255,255) after n overlaps, with n variable but ideally 255...

Thank you,
Cristian


RE: PIXON_P Alpha blending - Carlos295pz - 05-07-2017 11:22 AM

You do not have use error, it is normal that the color does not arrive completely to the color supuerpuesto, not even has much presicion by the definition of 16 bits by color.

What you can do is to swap, if you want the final color to be white, then paint white and it is the black who will change alpha, an inverse process. Or just after finishing with the overlay loop, intentionally painting white with the pixon, saves problems in this way.


RE: PIXON_P Alpha blending - Cristian Arezzini - 05-07-2017 01:28 PM

Thank you for your reply. Unfortunately, I don't think I can use your method, because I don't know in advance what pixels need to be turned on, and with what color. Basically I want to make a 2D graph of a chaotic formula, so I calculate the orbits (where the result falls for every iteration) and I want to display where it falls, and also how many times it fell there; so I keep iterating, and I wanted to see, for every pixel of the display, if (and how often) the formula landed there.

If the alpha is unusable for this (but why? How does Alpha work exactly?) the only other solution I can think of, is to create a matrix of integers, as big as the display, and then add 1 to a cell every time the orbit falls there. And then, at the end, I can draw every pixel with a color proportional to the value of the corresponding matrix cell. But this means creating a very large matrix (which I don't know how to use); and furthermore, I can not see the progress until the end of the iterating loop. And... it will be slower. Sad

Cristian


RE: PIXON_P Alpha blending - Han - 05-07-2017 02:27 PM

Why not just use a color gradient instead of alpha blending?


RE: PIXON_P Alpha blending - Cristian Arezzini - 05-07-2017 03:41 PM

You mean simply reading the color of the pixel, increasing the value, and writing it back? That works (sort of), but it gets MUCH slower, because for every single iteration I have to run a read command on the screen, and a write command. And I run many thousands of iterations. The rendering time almost doubles, with respect to the alpha blending (where I only have one graphic command per iteration)...

Cristian


RE: PIXON_P Alpha blending - cyrille de brébisson - 05-08-2017 05:21 AM

Hello,

Han is correct in saying that doing repeat alpha will "max out" following the sequence Un+1=((256-a)*Un+a*c2)/256, which has an asymptotic value which is not 255...

Depending on the number of drawn pixels, it might be better to create a matrix of numbers that you increment "off screen", and that you then display.
The fastest, assuming that you do not get over 65536 iterations per points might be to use a string...
Create a string of size 320*240, fill it with 0s str(i):=0; and then inc the item of interest on each iteration str(y*320+x+1):= str(y*320+x+1)+1;
then display the content of the string.

Cyrille


RE: PIXON_P Alpha blending - webmasterpdx - 09-12-2017 09:33 AM

Also having done a lot of work with video in the past, be aware that our brains don't view alpha with the same linear gradient that the values we put in the argb values. i.e. 50% alpha might appear visually to be 50% mixed colors, but then 70% numerically might appear visually (to our eye-brain connection) to be 95%!
Just be aware of that.