Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8463411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:26:47+00:00 2026-06-10T14:26:47+00:00

Possible Duplicate: How to do alpha blend fast? What is the fastest way to

  • 0

Possible Duplicate:
How to do alpha blend fast?

What is the fastest way to alpha blend 2 RGBA (Integer) colors?

As a note, the target color where to blend is always opaque, only the second color can have different levels of transparency.

I am trying to find the fastest way in C, taking into account that the final resulting color from the blend must end up with no transparency, fully opaque (alpha = 0xff)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:26:49+00:00Added an answer on June 10, 2026 at 2:26 pm
    int blend(unsigned char result[4], unsigned char fg[4], unsigned char bg[4])
    {
        unsigned int alpha = fg[3] + 1;
        unsigned int inv_alpha = 256 - fg[3];
        result[0] = (unsigned char)((alpha * fg[0] + inv_alpha * bg[0]) >> 8);
        result[1] = (unsigned char)((alpha * fg[1] + inv_alpha * bg[1]) >> 8);
        result[2] = (unsigned char)((alpha * fg[2] + inv_alpha * bg[2]) >> 8);
        result[3] = 0xff;
    }
    

    I don’t know how fast it is, but it’s all integer. It works by turning alpha (and inv_alpha) into 8.8 fixed-point representations. Don’t worry about the fact that alpha’s min value is 1. In that case, fg[3] was 0, meaning the foreground is transparent. The blends will be 1*fg + 256*bg, which means that all the bits of fg will be shifted out of the result.

    You could do it very fast, indeed, if you packed your RGBAs in 64 bit integers. You could then compute all three result colors in parallel with a single expression.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Convert RGBA color to RGB I'm trying to convert a RGBA color,
Possible Duplicate: How do I create a random alpha-numeric string in C++? I need
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: What is the fastest XML parser in PHP? I still need to
Possible Duplicate: How to Set Opacity (Alpha) for View in Android i want to
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: How can I save and load the alpha values of a UIButton
Possible Duplicate: Is there any way to clone a git repository’s sub-directory only? clone
Possible Duplicate: Is there a way to create a SQL Server function to “join”

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.