Active Forums => QB64 Discussion => Topic started by: Petr on May 01, 2019, 07:39:12 am
Title: It seems that transparent colors are badly written to memory (explained)
Post by: Petr on May 01, 2019, 07:39:12 am
Hi. Maybe that's just my fault, but this program returns faulty results for _RGBA32 colors. When writing _RGB32 colors, the values return correct. That's why I was sitting at the computer at 3:00 am yesterday and didn't understand what the hell was going on ...
Title: Re: It seems that transparent colors are badly written to memory
Post by: FellippeHeitor on May 01, 2019, 08:49:42 am
The thing is: You place a transparent color onto a black image. Pixels will blend with black. Read those back: they are not the same values anymore - because they blended. That's the purpose of transparency and alpha blending: having colors transform upon being applied.
Title: Re: It seems that transparent colors are badly written to memory
Post by: FellippeHeitor on May 01, 2019, 08:55:01 am
Just as red and blue merge in the example above to form a new color, your transparent colors will merge with black to form a new color after they are put to the image. That's why you don't get the same values of the original color, because it's not the same color anymore after blending.
Title: Re: It seems that transparent colors are badly written to memory
Post by: FellippeHeitor on May 01, 2019, 08:57:35 am
Also:
Quote
PSET write it bad
PSET write is good because it *does* blend. Memory write doesn't blend because it's raw manipulation.
Title: Re: It seems that transparent colors are badly written to memory
Post by: Petr on May 01, 2019, 09:14:14 am
Oh, my God... Now it's clear to me. Thank you. Knowledge + :-D I assumed the background was 0,0,0,0, so it doesn't affect. Basically, a new screen without CLS is transparent. Alpha mixes everything together to create a new color. When I add the mutual transparency between the _SOFTWARE and _HARDWARE layers, that's the power to put this together. I go into the corner and I'll silent sit. :-D
Thank you, Fellippe.
Title: Re: It seems that transparent colors are badly written to memory
Post by: SMcNeill on May 01, 2019, 09:19:03 am
Alpha images blend with the background, by default. If you have a red background, put a 50% transparent green background onto it, you end up with a faded yellow background.
If you want to maintain that 50% transparent green, and completely overwrite the red with it, use _DONTBLEND. (Much like you’re doing with the MEM commands.)
************
Personally, since _DONTBLEND runs much faster than when blending is turned on by default, and since a lot of folks never use alpha images, I’ve always felt that it should be our default setting — but it’s not. QB64 automatically tries to blend all images onto the original canvas, unless _DONTBLEND is invoked manually.
Title: Re: It seems that transparent colors are badly written to memory (explained)
Post by: Petr on May 01, 2019, 09:23:23 am
Thank you Steve. I didn't know that. I'll try it.
Title: Re: It seems that transparent colors are badly written to memory (explained)
Post by: Petr on May 10, 2019, 12:48:17 pm
If someone was wondering how is the alpha channel calculated, when using MEM, it's easy. See this example.
Title: Re: It seems that transparent colors are badly written to memory (explained)
Post by: Petr on May 10, 2019, 01:23:48 pm
Here is sample application with an alpha channel with MEM for a PNG image that has an alpha channel. The purpose of this feature is to rotate the image 90 degrees, no more. It's one of the many subroutines I develop.