Link to home
Start Free TrialLog in
Avatar of Sol
Sol

asked on

Add two buffers

Hi!!

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:

R,G,B,R,G,B,...

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

      R=R(buf1)(1-A)+R(buf2)
            G=G(buf1)(1-A)+G(buf2)
            B=B(buf1)(1-A)+B(buf2)

(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???



ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

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.
Avatar of Sol

ASKER

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?
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?
Avatar of Sol

ASKER

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...

thanks!!
Avatar of Sol

ASKER

Thank's nietod!!

It works fine!!