Article View: rec.games.programmer
Article #2338Re: Alpha Blending Techniques - PLEASE HELP!
From: Nicolas Rudaz
Date: Fri, 24 Jul 1998 00:00
Date: Fri, 24 Jul 1998 00:00
43 lines
1902 bytes
1902 bytes
In article <6omgsn$kgk$1@nnrp1.dejanews.com>, eduardo@fnn.net wrote: >I'm a newbie programmer... and I need to find some algorithms to >perform Alpha Blending... Take a look at the book "High Performance Computer Imaging", by Ihtisham Kabir, Manning Publications Co. 1996, pp. 150-153 It contains a C the algorithm you want, along with a lot of other useful stuff. You'll find below an example I wrote in C for performing alpha blending with two input RGB pixels (in1 and in2) into an output RGB pixel (out). Do not use this example "as is", it has been written in order to provide a good clarity at the expense of performance. Hope this helps, Nicolas Rudaz -- #define R 0 #define G 1 #define B 2 long tmp[3]; /* 0 <= alpha, in1[i], in2[i], out[i] <= 255 */ unsigned char alpha, in1[3], in2[3], out[3]; tmp[R] = alpha * (in1[R] - in2[R]); tmp[G] = alpha * (in1[G] - in2[G]); tmp[B] = alpha * (in1[B] - in2[B]); tmp[R] += in2[R] << 8; tmp[G] += in2[G] << 8; tmp[B] += in2[B] << 8; out[R] = (unsigned char) (tmp[R] >> 8); out[G] = (unsigned char) (tmp[G] >> 8); out[B] = (unsigned char) (tmp[B] >> 8);
Technical Details
Message-ID:
<Nicolas.Rudaz-2407981332090001@lspmac22.epfl.ch>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6omgsn$kgk$1@nnrp1.dejanews.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fe306,b4b32c53bf9eb33b X-Google-Attributes: gidfe306,public X-Google-Thread: 10a296,b4b32c53bf9eb33b X-Google-Attributes: gid10a296,public X-Google-Thread: fdc2a,b4b32c53bf9eb33b X-Google-Attributes: gidfdc2a,public X-Google-Thread: 108717,b4b32c53bf9eb33b X-Google-Attributes: gid108717,public From: Nicolas.Rudaz@epfl.ch (Nicolas Rudaz) Subject: Re: Alpha Blending Techniques - PLEASE HELP! Date: 1998/07/24 Message-ID: <Nicolas.Rudaz-2407981332090001@lspmac22.epfl.ch> X-Deja-AN: 374482041 References: <6omgsn$kgk$1@nnrp1.dejanews.com> Organization: EPFL Newsgroups: rec.games.programmer,comp.graphics.algorithms,comp.programming,borland.public.delphi.graphics