<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Crystal Space 1.2.1: csplugincommon/canvas/draw_common.h Source File (Crystal Space 1.2.1 Public API Reference)</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="head"> <tr height="59"> <td class="head" width="202" valign="bottom" style="padding-left:0;"><a href="http://www.crystalspace3d.org/"><img src="csblur.png" width="236" height="59" alt="CrystalSpace" border="0"></a></td> <td class="head"><h2>Public API Reference</h2></td> </tr> <tr height="11"> <td colspan="2" class="headshadow" valign="top" style="padding-left:0;"><img src="csblurb.png" width="236" height="11" alt="" border="0"></td> </tr> </table> <div class="content"> <!-- Generated by Doxygen 1.5.3 --> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul> </div> <h1>csplugincommon/canvas/draw_common.h</h1><a href="draw__common_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> Copyright (C) 2004 by Jorrit Tyberghein</span> <a name="l00003"></a>00003 <span class="comment"> (C) 2004 by Frank Richter</span> <a name="l00004"></a>00004 <span class="comment"></span> <a name="l00005"></a>00005 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00006"></a>00006 <span class="comment"> modify it under the terms of the GNU Library General Public</span> <a name="l00007"></a>00007 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00008"></a>00008 <span class="comment"> version 2 of the License, or (at your option) any later version.</span> <a name="l00009"></a>00009 <span class="comment"></span> <a name="l00010"></a>00010 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00011"></a>00011 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00012"></a>00012 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00013"></a>00013 <span class="comment"> Library General Public License for more details.</span> <a name="l00014"></a>00014 <span class="comment"></span> <a name="l00015"></a>00015 <span class="comment"> You should have received a copy of the GNU Library General Public</span> <a name="l00016"></a>00016 <span class="comment"> License along with this library; if not, write to the Free</span> <a name="l00017"></a>00017 <span class="comment"> Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</span> <a name="l00018"></a>00018 <span class="comment">*/</span> <a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="preprocessor">#ifndef __CS_CSPLUGINCOMMON_CANVAS_DRAW_COMMON_H__</span> <a name="l00021"></a>00021 <span class="preprocessor"></span><span class="preprocessor">#define __CS_CSPLUGINCOMMON_CANVAS_DRAW_COMMON_H__</span> <a name="l00022"></a>00022 <span class="preprocessor"></span> <a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="csplugincommon_2canvas_2graph2d_8h.html" title="Base class for 2D canvases.">csplugincommon/canvas/graph2d.h</a>"</span> <a name="l00028"></a>00028 <a name="l00033"></a>00033 <a name="l00034"></a>00034 <span class="keyword">template</span><<span class="keyword">class</span> Tpixel> <a name="l00035"></a><a class="code" href="group__plugincommon.html#g40ff3488d7cc871d2646a3039cab5929">00035</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__plugincommon.html#g40ff3488d7cc871d2646a3039cab5929" title="Split a g2d color into the color and alpha part.">SplitAlpha</a> (<span class="keyword">const</span> <span class="keywordtype">int</span> color, Tpixel& colorPart, <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a>& alphaPart) <a name="l00036"></a>00036 { <a name="l00037"></a>00037 colorPart = color ^ 0xff000000; <a name="l00038"></a>00038 alphaPart = 255 - (color >> 24); <a name="l00039"></a>00039 } <a name="l00040"></a>00040 <a name="l00042"></a>00042 <span class="keyword">template</span><<span class="keyword">class</span> Tpixel> <a name="l00043"></a><a class="code" href="classcsPixMixerCopy.html">00043</a> <span class="keyword">class </span><a class="code" href="classcsPixMixerCopy.html" title="PixMixer that ignores alpha.">csPixMixerCopy</a> <a name="l00044"></a>00044 { <a name="l00045"></a>00045 Tpixel color; <a name="l00046"></a>00046 <span class="keyword">public</span>: <a name="l00047"></a><a class="code" href="classcsPixMixerCopy.html#f3f92f5fa37bd4e8c4cc93d54d1fc158">00047</a> <a class="code" href="classcsPixMixerCopy.html#f3f92f5fa37bd4e8c4cc93d54d1fc158">csPixMixerCopy</a> (<a class="code" href="classcsGraphics2D.html" title="This is the base class for 2D canvases.">csGraphics2D</a>* <span class="comment">/*G2D*/</span>, Tpixel color, <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> <span class="comment">/*alpha*/</span>) <a name="l00048"></a>00048 { <a name="l00049"></a>00049 csPixMixerCopy::color = color; <a name="l00050"></a>00050 } <a name="l00051"></a><a class="code" href="classcsPixMixerCopy.html#c21bdce6f55356aff2b5a0201e60481d">00051</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classcsPixMixerCopy.html#c21bdce6f55356aff2b5a0201e60481d">Mix</a> (Tpixel& dest) <a name="l00052"></a>00052 { <a name="l00053"></a>00053 dest = color; <a name="l00054"></a>00054 } <a name="l00055"></a>00055 }; <a name="l00056"></a>00056 <a name="l00058"></a>00058 <span class="keyword">template</span><<span class="keyword">class</span> Tpixel> <a name="l00059"></a><a class="code" href="classcsPixMixerRGBA.html">00059</a> <span class="keyword">class </span><a class="code" href="classcsPixMixerRGBA.html" title="PixMixer that mixes the pixel into the background with alpha.">csPixMixerRGBA</a> <a name="l00060"></a>00060 { <a name="l00061"></a>00061 <a class="code" href="group__util.html#g1134b580f8da4de94ca6b1de4d37975e" title="unsigned 32-bit integer (0..4 294 967 295)">uint32</a> rbMask, gaMask; <a name="l00062"></a>00062 <span class="keywordtype">int</span> intAlphaInv; <a name="l00063"></a>00063 <a class="code" href="group__util.html#g1134b580f8da4de94ca6b1de4d37975e" title="unsigned 32-bit integer (0..4 294 967 295)">uint32</a> intRB, intGA; <a name="l00064"></a>00064 <span class="keywordtype">int</span> gShift, gShift2; <a name="l00065"></a>00065 <span class="keywordtype">int</span> alphaPrec; <a name="l00066"></a>00066 <span class="keyword">public</span>: <a name="l00067"></a><a class="code" href="classcsPixMixerRGBA.html#8be8df1c2a19b7ccae58904301a2781f">00067</a> <a class="code" href="classcsPixMixerRGBA.html#8be8df1c2a19b7ccae58904301a2781f">csPixMixerRGBA</a> (<a class="code" href="classcsGraphics2D.html" title="This is the base class for 2D canvases.">csGraphics2D</a>* G2D, Tpixel color, <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> alpha) <a name="l00068"></a>00068 { <a name="l00069"></a>00069 alphaPrec = G2D-><a class="code" href="classcsGraphics2D.html#118dd580babe3a8416c1e7b89f6dfdfe" title="The pixel format.">pfmt</a>.<a class="code" href="structcsPixelFormat.html#4ac98dd68e5529a831a85e0af15f2202">GreenBits</a>; <a name="l00070"></a>00070 <span class="keyword">const</span> <span class="keywordtype">int</span> alphaShift = 8 - alphaPrec; <a name="l00071"></a>00071 <span class="keyword">const</span> <span class="keywordtype">int</span> intAlpha = (alpha + 1) >> alphaShift; <a name="l00072"></a>00072 intAlphaInv = (255 - alpha + 1) >> alphaShift; <a name="l00073"></a>00073 gShift = G2D-><a class="code" href="classcsGraphics2D.html#118dd580babe3a8416c1e7b89f6dfdfe" title="The pixel format.">pfmt</a>.<a class="code" href="structcsPixelFormat.html#38b92fd903f6010730e88a36fd60c0da">GreenShift</a>; <a name="l00074"></a>00074 gShift2 = alphaPrec - gShift; <a name="l00075"></a>00075 <span class="comment">// Makes the assumption that colors are laid out ARGB ...</span> <a name="l00076"></a>00076 rbMask = G2D-><a class="code" href="classcsGraphics2D.html#118dd580babe3a8416c1e7b89f6dfdfe" title="The pixel format.">pfmt</a>.<a class="code" href="structcsPixelFormat.html#604edca9430a5d5b4e812baa49e7fbf1" title="The masks to extract the color information from a pixel (truecolor mode only).">RedMask</a> | G2D-><a class="code" href="classcsGraphics2D.html#118dd580babe3a8416c1e7b89f6dfdfe" title="The pixel format.">pfmt</a>.<a class="code" href="structcsPixelFormat.html#344c300262e89a13626c644d2ddb5865">BlueMask</a>; <a name="l00077"></a>00077 intRB = ((color & rbMask) * intAlpha) >> alphaPrec; <a name="l00078"></a>00078 gaMask = G2D-><a class="code" href="classcsGraphics2D.html#118dd580babe3a8416c1e7b89f6dfdfe" title="The pixel format.">pfmt</a>.<a class="code" href="structcsPixelFormat.html#f15b67458e85bdf86cf2c2aa6a2c298c">GreenMask</a> | G2D-><a class="code" href="classcsGraphics2D.html#118dd580babe3a8416c1e7b89f6dfdfe" title="The pixel format.">pfmt</a>.<a class="code" href="structcsPixelFormat.html#7bc610c1f073b232fe4ae22f6696baa2">AlphaMask</a>; <a name="l00079"></a>00079 intGA = (((color & gaMask) >> gShift) * intAlpha) >> gShift2; <a name="l00080"></a>00080 } <a name="l00081"></a><a class="code" href="classcsPixMixerRGBA.html#eb2e69b4c72efb0f87624a42515f297c">00081</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classcsPixMixerRGBA.html#eb2e69b4c72efb0f87624a42515f297c">Mix</a> (Tpixel& dest)<span class="keyword"> const</span> <a name="l00082"></a>00082 <span class="keyword"> </span>{ <a name="l00083"></a>00083 <span class="keyword">const</span> Tpixel destCol = dest; <a name="l00084"></a>00084 <span class="keyword">const</span> Tpixel newRB = <a name="l00085"></a>00085 ((intRB + (((destCol & rbMask) * intAlphaInv) >> alphaPrec)) & rbMask); <a name="l00086"></a>00086 <span class="keyword">const</span> Tpixel newGA = <a name="l00087"></a>00087 ((intGA + (((((destCol & gaMask) >> gShift) * intAlphaInv)) >> gShift2)) <a name="l00088"></a>00088 & gaMask); <a name="l00089"></a>00089 dest = newRB | newGA; <a name="l00090"></a>00090 } <a name="l00091"></a>00091 }; <a name="l00092"></a>00092 <a name="l00094"></a>00094 <span class="keyword">template</span><<span class="keyword">class</span> Tpixel> <a name="l00095"></a><a class="code" href="classcsPixMixerNoop.html">00095</a> <span class="keyword">class </span><a class="code" href="classcsPixMixerNoop.html" title="PixMixer that doesn&#39;t do anything.">csPixMixerNoop</a> <a name="l00096"></a>00096 { <a name="l00097"></a>00097 <span class="keyword">public</span>: <a name="l00098"></a><a class="code" href="classcsPixMixerNoop.html#7318d7318418ce3204571d7debbf5ceb">00098</a> <a class="code" href="classcsPixMixerNoop.html#7318d7318418ce3204571d7debbf5ceb">csPixMixerNoop</a> (<a class="code" href="classcsGraphics2D.html" title="This is the base class for 2D canvases.">csGraphics2D</a>* <span class="comment">/*G2D*/</span>, Tpixel <span class="comment">/*color*/</span>, <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> <span class="comment">/*alpha*/</span>) <a name="l00099"></a>00099 { } <a name="l00100"></a><a class="code" href="classcsPixMixerNoop.html#91b848c447a155423c16e3d00ef39e0f">00100</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classcsPixMixerNoop.html#91b848c447a155423c16e3d00ef39e0f">Mix</a> (Tpixel& <span class="comment">/*dest*/</span>) <a name="l00101"></a>00101 { } <a name="l00102"></a>00102 }; <a name="l00103"></a>00103 <a name="l00106"></a>00106 <span class="preprocessor">#endif // __CS_CSPLUGINCOMMON_CANVAS_DRAW_COMMON_H__</span> </pre></div><hr size="1"><address><small>Generated for Crystal Space 1.2.1 by <a href="http://www.doxygen.org/index.html">doxygen</a> 1.5.3 </small></address> </div></body> </html>