Add two buffers


I've two buffers, named buf1 and buf2.

Buf1 contents a RGB file with this structure: R,G,B,R,G,B,...

Buf2 contents a RGBA file with this structure: R,G,B,A,R,G,B,A,...

I want to add these buffers in buf3, so that the result stored in buf3 will be the following:


Look that each component of buf3 is calculated:

(example for the first pixel addittion, the A range is from 0 to 1 (0 to 255))


(The first A is used to do the fisrt RGB calculation, the second A is used to do the second RGB calculation, .....)

How can i do that???

Who is Participating?
nietodConnect With a Mentor Commented:
answer coming.
typedef unsigned char uByt; // for convenience.

void AddBuffs(uByt *DstPtr,uByt *RGBPtr, uByt *RGBAPtr,int Cnt)
   while (Cnt--)
      uByt RGB_R = *RGBPtr++;
      uByt RGB_G = *RGBPtr++;
      uByt RGB_B = *RGBPtr++;
      uByt RGBA_R = *RGRAPtr++;
      uByt RGBA_G = *RGRAPtr++;
      uByt RGBA_B = *RGRAPtr++;
      uByt RGBA_A = *RGRAPtr++;

     *DstPtr++ = RGB_R*(1 - RGBA_A) + RGBA_R;
     *DstPtr++ = RGB_G*(1 - RGBA_A) + RGBA_G;
     *DstPtr++ = RGB_B*(1 - RGBA_A) + RGBA_B;

You probably can change the "names" to make the more intelligent.

Let me know if you have any questions.
SolAuthor Commented:
Hi nietod!!

I'm going to try your answer... ;-D

¿would you suggest me the most simple or efficient way to visualize the final image (buf3) in screen?
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

I'm not sure I understand that last question.  Do you mean how do you draw the image on the screen?  If so, it sounds like it is device independant bitmap.  (DIB).  Look at StretchDIBits or at CreateDIBitmap.  Those functions will get you started.  (either way will take about 20 lines of code though.)
Did this answer your question?
SolAuthor Commented:
I'm sorry nietod!!

i've been ill for a long time, but now, i'm back again!! ;-D

Let me try the code... You'll have news...

SolAuthor Commented:
Thank's nietod!!

It works fine!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.