Solved

Add two buffers

Posted on 1998-11-19
7
230 Views
Last Modified: 2010-04-10
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???



0
Comment
Question by:Sol
  • 4
  • 3
7 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1178212
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178213
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.
0
 

Author Comment

by:Sol
ID: 1178214
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?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 22

Expert Comment

by:nietod
ID: 1178215
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.)
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178216
Did this answer your question?
0
 

Author Comment

by:Sol
ID: 1178217
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!!
0
 

Author Comment

by:Sol
ID: 1178218
Thank's nietod!!

It works fine!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 73
Handle Exceptions during instantiation 28 423
C++ to C# code conversion issue 4 112
Dialogbox API leak? 18 99
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question