代码之家  ›  专栏  ›  技术社区  ›  Ferenc Deak

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

  •  0
  • Ferenc Deak  · 技术社区  · 15 年前

    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 
    }
    

    熔块

    1 回复  |  直到 15 年前
        1
  •  6
  •   6502    15 年前

    进行alpha混合的公式比按位或更复杂。假设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);
    
    推荐文章