Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何将覆盖透明度应用于RGBA图像_C++_Image Processing_Transparency_Overlay_Alpha - Fatal编程技术网

C++ 如何将覆盖透明度应用于RGBA图像

C++ 如何将覆盖透明度应用于RGBA图像,c++,image-processing,transparency,overlay,alpha,C++,Image Processing,Transparency,Overlay,Alpha,这是我的困境:我必须RGBA原始图像:一个主图像(第一个)和一个字幕轨道(第二个),我想以一种基于第二个图像的alpha通道的方式覆盖它们:如果它为零,那么从第二个图像取像素,如果它为0xFF,从第一个图像取像素,否则,在第一个图像上创建第二个图像的覆盖。以下是用于此操作的代码: if(frame->bytes[pc + 3] == 0xFF) /* this is NO transparency in the overlay image, meaning: take over the o

这是我的困境:我必须RGBA原始图像:一个主图像(第一个)和一个字幕轨道(第二个),我想以一种基于第二个图像的alpha通道的方式覆盖它们:如果它为零,那么从第二个图像取像素,如果它为0xFF,从第一个图像取像素,否则,在第一个图像上创建第二个图像的覆盖。以下是用于此操作的代码:

if(frame->bytes[pc + 3] == 0xFF) /* this is NO transparency in the overlay image, meaning: take over the overlay 100% */
{
    pFrameRGB->data[0][pc] = frame->bytes[pc];    // Red
    pFrameRGB->data[0][pc+1] = frame->bytes[pc+1];// Green 
    pFrameRGB->data[0][pc+2] = frame->bytes[pc+2];// Blue 
}
else
if(frame->bytes[pc + 3] != 0) /* this is full transparency in the overlay image, meaning: take over the image 100% */
{
    pFrameRGB->data[0][pc] |= frame->bytes[pc];    // Red
    pFrameRGB->data[0][pc+1] |= frame->bytes[pc+1];// Green 
    pFrameRGB->data[0][pc+2] |= frame->bytes[pc+2];// Blue
    pFrameRGB->data[0][pc+3] = frame->bytes[pc+3]; // Alpha 
}
在上面的代码中,pFrameRGB是目标RGBA图像,已经包含一些图像,frame->bytes是“覆盖/字幕”图像。。。我的问题来了:有了一些色彩鲜艳的叠加/字幕图像,目的地就太鲜艳了。。。因此,这不像我想要得到的字幕图像被覆盖,但你可以看到整个颜色范围(例如:我有一个红色/绿色的覆盖图像,alpha值增加,我希望覆盖图像看起来像“苍白的”红色/绿色叠加,下面有图像,但是通过上面的方法,我在下面的图像上获得了很多彩色像素)。你有更好的方法吗

谢谢,
fritzone

进行阿尔法混合的方程式比按位or更复杂。假设RGB的线性响应模型,相当常见的实现是:

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);

进行alpha混合的方程式比按位or更复杂。假设RGB的线性响应模型,相当常见的实现是:

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);