c++ - How to apply overlay transparency to RGBA image -
This is my dilemma: I have RGBA raw images: a master image (first) and a subtitle track (second), and I want to overlay them in a different way depending on the alpha channel of the second image: if it is zero Take the pixels from the second image, if it is 0xFF, then take the pixels from the first image, otherwise create an overlay, first the second image on one here is the code used for it here:
If (frame- & Gt; Bytes [PC + 3] == 0xFF) / * Overlay Image There is no transparency in it, which means: Overlay 100% * / {pFrameRGB- & gt; Data [0] [pc] = frame-> Bytes [pc]; // red pFrameRGB-> Data [0] [pc + 1] = frame-> Bytes [pc + 1]; // Green pFrameRGB-> Data [0] [pc + 2] = frame- & gt; Bytes [pc + 2]; // blue} and if (frame-> bytes [pc + 3]! = 0) / * overlay image it has full transparency, meaning: 100% * / {pFrameRGB -> Data [0] [pc] | = Frame-> Bytes [pc]; // red pFrameRGB-> Data [0] [pc + 1] | = Frame-> Bytes [pc + 1]; // Green pFrameRGB-> Data [0] [pc + 2] | = Frames-> and; Bytes [pc + 2]; // Blue Pfepha RGB- & gt; Data [0] [pc + 3] = frame- & gt; Bytes [pc + 3]; // alpha}
The code given above is the target RGBA image in the code above pFrameRGB, which already has an image, frame-> bytes "overlay / subtitle" image ... and Here's my question: Destination with some color overlay / subtitle pictures is very colorful ... so it's not that the subtitle image is overlapped which I want to get but you can see a full range of colors ( For example: growing with me Red / green overlay image with Lafa and I would like the overlay image to look like a "yellow" red / green overlay with the picture below, even though from the above approach, Pixels). Do you have a better approach to doing this?
Thank you, Freezion
The equation is just a bit of an alpha mix Is more complicated than it is or is considered a linear response model for RGB for a general ammunition:
dst_r = (src_r * src_A + dst_R * (255 - src_A)) / 255 ; Dst_g = (src_G * src_A + dst_G * (255 - src_A)) / 255; Dst_B = (src_B * src_A + dst_B * (255 - src_A)) / 255; Dst_A = Min (src_A + dst_A, 255);