Jump to content

Help with how to add RGBA values

Recommended Posts


I'm currently working on a game where I do some simple pixel modifications when loading graphics. What I tried to do was to build a function that could take two RGBA values and add them, but I'm having real trouble with the alpha values. I know how to do it when using only RGB colors but when including alpha everything gets much trickier. Since I use Paint.NET when creating graphics and I know it can blend these colors very well, I'm hoping any developer or pixel color expert can help me how to write a function like this:

u32 blendPixel(u32 baseColor, u32 paintColor) {
   u8 baseRed = getRed(baseColor);
   u8 baseGreen = getGreen(baseColor);
   u8 baseBlue = getBlue(baseColor);
   u8 baseAlpha = getAlpha(baseColor);

   u8 paintRed = getRed(paintColor);
   u8 paintGreen = getGreen(paintColor);
   u8 paintBlue = getBlue(paintColor);
   u8 paintAlpha = getAlpha(paintColor);

   u8 newRed = ???
   u8 newGreen = ???
   u8 newBlue = ???
   u8 newAlpha = ???

   return makecol(newRed, newGreen, newBlue, newAlpha);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...