source: OGRE/trunk/ogrenew/Docs/api/html/OgreImageResampler_8h-source.html @ 657

Revision 657, 38.4 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1<html>
2<head>
3<title>OgreImageResampler.h Source File - OGRE Documentation</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
4<link type="text/css" rel="stylesheet" href="style.css">
5</head>
6
7<body>
8<!-- Generated by Doxygen 1.3.6 -->
9<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
10<h1>OgreImageResampler.h</h1><a href="OgreImageResampler_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>
1100002 <span class="comment">-----------------------------------------------------------------------------</span>
1200003 <span class="comment">This source file is part of OGRE</span>
1300004 <span class="comment">    (Object-oriented Graphics Rendering Engine)</span>
1400005 <span class="comment">For the latest info, see http://www.ogre3d.org/</span>
1500006 <span class="comment"></span>
1600007 <span class="comment">Copyright (c) 2000-2005 The OGRE Team</span>
1700008 <span class="comment">Also see acknowledgements in Readme.html</span>
1800009 <span class="comment"></span>
1900010 <span class="comment">This program is free software; you can redistribute it and/or modify it under</span>
2000011 <span class="comment">the terms of the GNU Lesser General Public License as published by the Free Software</span>
2100012 <span class="comment">Foundation; either version 2 of the License, or (at your option) any later</span>
2200013 <span class="comment">version.</span>
2300014 <span class="comment"></span>
2400015 <span class="comment">This program is distributed in the hope that it will be useful, but WITHOUT</span>
2500016 <span class="comment">ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS</span>
2600017 <span class="comment">FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</span>
2700018 <span class="comment"></span>
2800019 <span class="comment">You should have received a copy of the GNU Lesser General Public License along with</span>
2900020 <span class="comment">this program; if not, write to the Free Software Foundation, Inc., 59 Temple</span>
3000021 <span class="comment">Place - Suite 330, Boston, MA 02111-1307, USA, or go to</span>
3100022 <span class="comment">http://www.gnu.org/copyleft/lesser.txt.</span>
3200023 <span class="comment">-----------------------------------------------------------------------------</span>
3300024 <span class="comment">*/</span>
3400025 <span class="preprocessor">#ifndef OGREIMAGERESAMPLER_H</span>
3500026 <span class="preprocessor"></span><span class="preprocessor">#define OGREIMAGERESAMPLER_H</span>
3600027 <span class="preprocessor"></span>
3700028 <span class="preprocessor">#include &lt;algorithm&gt;</span>
3800029
3900030 <span class="comment">// this file is inlined into OgreImage.cpp!</span>
4000031 <span class="comment">// do not include anywhere else.</span>
4100032 <span class="keyword">namespace </span>Ogre {
4200033
4300034 <span class="comment">// define uint64 type</span>
4400035 <span class="preprocessor">#if OGRE_COMPILER == OGRE_COMPILER_MSVC</span>
45<a name="l00036"></a><a class="code" href="namespaceOgre.html#a553">00036</a> <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> __int64 <a class="code" href="namespaceOgre.html#a553">uint64</a>;
4600037 <span class="preprocessor">#else</span>
4700038 <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">long</span> <a class="code" href="namespaceOgre.html#a553">uint64</a>;
4800039 <span class="preprocessor">#endif</span>
4900040 <span class="preprocessor"></span>
5000041 <span class="comment">// variable name hints:</span>
5100042 <span class="comment">// sx_48 = 16/48-bit fixed-point x-position in source</span>
5200043 <span class="comment">// stepx = difference between adjacent sx_48 values</span>
5300044 <span class="comment">// sx1 = lower-bound integer x-position in source</span>
5400045 <span class="comment">// sx2 = upper-bound integer x-position in source</span>
5500046 <span class="comment">// sxf = fractional weight beween sx1 and sx2</span>
5600047 <span class="comment">// x,y,z = location of output pixel in destination</span>
5700048
5800049 <span class="comment">// nearest-neighbor resampler, does not convert formats.</span>
5900050 <span class="comment">// templated on bytes-per-pixel to allow compiler optimizations, such</span>
6000051 <span class="comment">// as simplifying memcpy() and replacing multiplies with bitshifts</span>
61<a name="l00052"></a><a class="code" href="structOgre_1_1NearestResampler.html">00052</a> <span class="keyword">template</span>&lt;<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> elemsize&gt; <span class="keyword">struct </span><a class="code" href="structOgre_1_1NearestResampler.html">NearestResampler</a> {
62<a name="l00053"></a><a class="code" href="structOgre_1_1NearestResampler.html#Ogre_1_1NearestResamplere0">00053</a>     <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structOgre_1_1NearestResampler.html#Ogre_1_1NearestResamplere0">scale</a>(<span class="keyword">const</span> <a class="code" href="classOgre_1_1PixelBox.html">PixelBox</a>&amp; src, <span class="keyword">const</span> <a class="code" href="classOgre_1_1PixelBox.html">PixelBox</a>&amp; dst) {
6300054         <span class="comment">// assert(src.format == dst.format);</span>
6400055
6500056         <span class="comment">// srcdata stays at beginning, pdst is a moving pointer</span>
6600057         <a class="code" href="namespaceOgre.html#a421">uchar</a>* srcdata = (<a class="code" href="namespaceOgre.html#a421">uchar</a>*)src.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo0">data</a>;
6700058         <a class="code" href="namespaceOgre.html#a421">uchar</a>* pdst = (<a class="code" href="namespaceOgre.html#a421">uchar</a>*)dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo0">data</a>;
6800059
6900060         <span class="comment">// sx_48,sy_48,sz_48 represent current position in source</span>
7000061         <span class="comment">// using 16/48-bit fixed precision, incremented by steps</span>
7100062         <a class="code" href="namespaceOgre.html#a553">uint64</a> stepx = ((<a class="code" href="namespaceOgre.html#a553">uint64</a>)src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa10">getWidth</a>() &lt;&lt; 48) / dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa10">getWidth</a>();
7200063         <a class="code" href="namespaceOgre.html#a553">uint64</a> stepy = ((<a class="code" href="namespaceOgre.html#a553">uint64</a>)src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa11">getHeight</a>() &lt;&lt; 48) / dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa11">getHeight</a>();
7300064         <a class="code" href="namespaceOgre.html#a553">uint64</a> stepz = ((<a class="code" href="namespaceOgre.html#a553">uint64</a>)src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa12">getDepth</a>() &lt;&lt; 48) / dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa12">getDepth</a>();
7400065
7500066         <span class="comment">// note: ((stepz&gt;&gt;1) - 1) is an extra half-step increment to adjust</span>
7600067         <span class="comment">// for the center of the destination pixel, not the top-left corner</span>
7700068         <a class="code" href="namespaceOgre.html#a553">uint64</a> sz_48 = (stepz &gt;&gt; 1) - 1;
7800069         <span class="keywordflow">for</span> (size_t z = dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo8">front</a>; z &lt; dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo9">back</a>; z++, sz_48 += stepz) {
7900070             size_t srczoff = (size_t)(sz_48 &gt;&gt; 48) * src.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo3">slicePitch</a>;
8000071             
8100072             <a class="code" href="namespaceOgre.html#a553">uint64</a> sy_48 = (stepy &gt;&gt; 1) - 1;
8200073             <span class="keywordflow">for</span> (size_t y = dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo5">top</a>; y &lt; dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo7">bottom</a>; y++, sy_48 += stepy) {
8300074                 size_t srcyoff = (size_t)(sy_48 &gt;&gt; 48) * src.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo2">rowPitch</a>;
8400075             
8500076                 <a class="code" href="namespaceOgre.html#a553">uint64</a> sx_48 = (stepx &gt;&gt; 1) - 1;
8600077                 <span class="keywordflow">for</span> (size_t x = dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo4">left</a>; x &lt; dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo6">right</a>; x++, sx_48 += stepx) {
8700078                     <a class="code" href="namespaceOgre.html#a421">uchar</a>* psrc = srcdata +
8800079                         elemsize*((size_t)(sx_48 &gt;&gt; 48) + srcyoff + srczoff);
8900080                     memcpy(pdst, psrc, elemsize);
9000081                     pdst += elemsize;
9100082                 }
9200083                 pdst += elemsize*dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxa4">getRowSkip</a>();
9300084             }
9400085             pdst += elemsize*dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxa5">getSliceSkip</a>();
9500086         }
9600087     }
9700088 };
9800089
9900090
10000091 <span class="comment">// default floating-point linear resampler, does format conversion</span>
101<a name="l00092"></a><a class="code" href="structOgre_1_1LinearResampler.html">00092</a> <span class="keyword">struct </span><a class="code" href="structOgre_1_1LinearResampler.html">LinearResampler</a> {
102<a name="l00093"></a><a class="code" href="structOgre_1_1LinearResampler.html#Ogre_1_1LinearResamplere0">00093</a>     <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structOgre_1_1LinearResampler.html#Ogre_1_1LinearResamplere0">scale</a>(<span class="keyword">const</span> <a class="code" href="classOgre_1_1PixelBox.html">PixelBox</a>&amp; src, <span class="keyword">const</span> <a class="code" href="classOgre_1_1PixelBox.html">PixelBox</a>&amp; dst) {
10300094         size_t srcelemsize = PixelUtil::getNumElemBytes(src.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo1">format</a>);
10400095         size_t dstelemsize = PixelUtil::getNumElemBytes(dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo1">format</a>);
10500096
10600097         <span class="comment">// srcdata stays at beginning, pdst is a moving pointer</span>
10700098         <a class="code" href="namespaceOgre.html#a421">uchar</a>* srcdata = (<a class="code" href="namespaceOgre.html#a421">uchar</a>*)src.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo0">data</a>;
10800099         <a class="code" href="namespaceOgre.html#a421">uchar</a>* pdst = (<a class="code" href="namespaceOgre.html#a421">uchar</a>*)dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo0">data</a>;
10900100         
11000101         <span class="comment">// sx_48,sy_48,sz_48 represent current position in source</span>
11100102         <span class="comment">// using 16/48-bit fixed precision, incremented by steps</span>
11200103         <a class="code" href="namespaceOgre.html#a553">uint64</a> stepx = ((<a class="code" href="namespaceOgre.html#a553">uint64</a>)src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa10">getWidth</a>() &lt;&lt; 48) / dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa10">getWidth</a>();
11300104         <a class="code" href="namespaceOgre.html#a553">uint64</a> stepy = ((<a class="code" href="namespaceOgre.html#a553">uint64</a>)src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa11">getHeight</a>() &lt;&lt; 48) / dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa11">getHeight</a>();
11400105         <a class="code" href="namespaceOgre.html#a553">uint64</a> stepz = ((<a class="code" href="namespaceOgre.html#a553">uint64</a>)src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa12">getDepth</a>() &lt;&lt; 48) / dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa12">getDepth</a>();
11500106         
11600107         <span class="comment">// temp is 16/16 bit fixed precision, used to adjust a source</span>
11700108         <span class="comment">// coordinate (x, y, or z) backwards by half a pixel so that the</span>
11800109         <span class="comment">// integer bits represent the first sample (eg, sx1) and the</span>
11900110         <span class="comment">// fractional bits are the blend weight of the second sample</span>
12000111         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> temp;
12100112
12200113         <span class="comment">// note: ((stepz&gt;&gt;1) - 1) is an extra half-step increment to adjust</span>
12300114         <span class="comment">// for the center of the destination pixel, not the top-left corner</span>
12400115         <a class="code" href="namespaceOgre.html#a553">uint64</a> sz_48 = (stepz &gt;&gt; 1) - 1;
12500116         <span class="keywordflow">for</span> (size_t z = dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo8">front</a>; z &lt; dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo9">back</a>; z++, sz_48+=stepz) {
12600117             temp = sz_48 &gt;&gt; 32;
12700118             temp = (temp &gt; 0x8000)? temp - 0x8000 : 0;
12800119             size_t sz1 = temp &gt;&gt; 16;                 <span class="comment">// src z, sample #1</span>
12900120             size_t sz2 = std::min(sz1+1,src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa12">getDepth</a>()-1);<span class="comment">// src z, sample #2</span>
13000121             <span class="keywordtype">float</span> szf = (temp &amp; 0xFFFF) / 65536.f; <span class="comment">// weight of sample #2</span>
13100122
13200123             <a class="code" href="namespaceOgre.html#a553">uint64</a> sy_48 = (stepy &gt;&gt; 1) - 1;
13300124             <span class="keywordflow">for</span> (size_t y = dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo5">top</a>; y &lt; dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo7">bottom</a>; y++, sy_48+=stepy) {
13400125                 temp = sy_48 &gt;&gt; 32;
13500126                 temp = (temp &gt; 0x8000)? temp - 0x8000 : 0;
13600127                 size_t sy1 = temp &gt;&gt; 16;                    <span class="comment">// src y #1</span>
13700128                 size_t sy2 = std::min(sy1+1,src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa11">getHeight</a>()-1);<span class="comment">// src y #2</span>
13800129                 <span class="keywordtype">float</span> syf = (temp &amp; 0xFFFF) / 65536.f; <span class="comment">// weight of #2</span>
13900130                 
14000131                 <a class="code" href="namespaceOgre.html#a553">uint64</a> sx_48 = (stepx &gt;&gt; 1) - 1;
14100132                 <span class="keywordflow">for</span> (size_t x = dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo4">left</a>; x &lt; dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo6">right</a>; x++, sx_48+=stepx) {
14200133                     temp = sx_48 &gt;&gt; 32;
14300134                     temp = (temp &gt; 0x8000)? temp - 0x8000 : 0;
14400135                     size_t sx1 = temp &gt;&gt; 16;                    <span class="comment">// src x #1</span>
14500136                     size_t sx2 = std::min(sx1+1,src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa10">getWidth</a>()-1);<span class="comment">// src x #2</span>
14600137                     <span class="keywordtype">float</span> sxf = (temp &amp; 0xFFFF) / 65536.f; <span class="comment">// weight of #2</span>
14700138                 
14800139                     <a class="code" href="classOgre_1_1ColourValue.html">ColourValue</a> x1y1z1, x2y1z1, x1y2z1, x2y2z1;
14900140                     <a class="code" href="classOgre_1_1ColourValue.html">ColourValue</a> x1y1z2, x2y1z2, x1y2z2, x2y2z2;
15000141
15100142 <span class="preprocessor">#define UNPACK(dst,x,y,z) PixelUtil::unpackColour(&amp;dst, src.format, \</span>
15200143 <span class="preprocessor">    srcdata + srcelemsize*((x)+(y)*src.rowPitch+(z)*src.slicePitch))</span>
15300144 <span class="preprocessor"></span>
15400145                     <a class="code" href="OgreImageResampler_8h.html#a0">UNPACK</a>(x1y1z1,sx1,sy1,sz1); <a class="code" href="OgreImageResampler_8h.html#a0">UNPACK</a>(x2y1z1,sx2,sy1,sz1);
15500146                     <a class="code" href="OgreImageResampler_8h.html#a0">UNPACK</a>(x1y2z1,sx1,sy2,sz1); <a class="code" href="OgreImageResampler_8h.html#a0">UNPACK</a>(x2y2z1,sx2,sy2,sz1);
15600147                     <a class="code" href="OgreImageResampler_8h.html#a0">UNPACK</a>(x1y1z2,sx1,sy1,sz2); <a class="code" href="OgreImageResampler_8h.html#a0">UNPACK</a>(x2y1z2,sx2,sy1,sz2);
15700148                     <a class="code" href="OgreImageResampler_8h.html#a0">UNPACK</a>(x1y2z2,sx1,sy2,sz2); <a class="code" href="OgreImageResampler_8h.html#a0">UNPACK</a>(x2y2z2,sx2,sy2,sz2);
15800149 <span class="preprocessor">#undef UNPACK</span>
15900150 <span class="preprocessor"></span>
16000151                     <a class="code" href="classOgre_1_1ColourValue.html">ColourValue</a> accum =
16100152                         x1y1z1 * ((1.0f - sxf)*(1.0f - syf)*(1.0f - szf)) +
16200153                         x2y1z1 * (        sxf *(1.0f - syf)*(1.0f - szf)) +
16300154                         x1y2z1 * ((1.0f - sxf)*        syf *(1.0f - szf)) +
16400155                         x2y2z1 * (        sxf *        syf *(1.0f - szf)) +
16500156                         x1y1z2 * ((1.0f - sxf)*(1.0f - syf)*        szf ) +
16600157                         x2y1z2 * (        sxf *(1.0f - syf)*        szf ) +
16700158                         x1y2z2 * ((1.0f - sxf)*        syf *        szf ) +
16800159                         x2y2z2 * (        sxf *        syf *        szf );
16900160
17000161                     PixelUtil::packColour(accum, dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo1">format</a>, pdst);
17100162
17200163                     pdst += dstelemsize;
17300164                 }
17400165                 pdst += dstelemsize*dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxa4">getRowSkip</a>();
17500166             }
17600167             pdst += dstelemsize*dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxa5">getSliceSkip</a>();
17700168         }
17800169     }
17900170 };
18000171
18100172
18200173 <span class="comment">// float32 linear resampler, converts FLOAT32_RGB/FLOAT32_RGBA only.</span>
18300174 <span class="comment">// avoids overhead of pixel unpack/repack function calls</span>
184<a name="l00175"></a><a class="code" href="structOgre_1_1LinearResampler__Float32.html">00175</a> <span class="keyword">struct </span><a class="code" href="structOgre_1_1LinearResampler__Float32.html">LinearResampler_Float32</a> {
185<a name="l00176"></a><a class="code" href="structOgre_1_1LinearResampler__Float32.html#Ogre_1_1LinearResampler__Float32e0">00176</a>     <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structOgre_1_1LinearResampler__Float32.html#Ogre_1_1LinearResampler__Float32e0">scale</a>(<span class="keyword">const</span> <a class="code" href="classOgre_1_1PixelBox.html">PixelBox</a>&amp; src, <span class="keyword">const</span> <a class="code" href="classOgre_1_1PixelBox.html">PixelBox</a>&amp; dst) {
18600177         size_t srcchannels = PixelUtil::getNumElemBytes(src.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo1">format</a>) / <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>);
18700178         size_t dstchannels = PixelUtil::getNumElemBytes(dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo1">format</a>) / <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>);
18800179         <span class="comment">// assert(srcchannels == 3 || srcchannels == 4);</span>
18900180         <span class="comment">// assert(dstchannels == 3 || dstchannels == 4);</span>
19000181
19100182         <span class="comment">// srcdata stays at beginning, pdst is a moving pointer</span>
19200183         <span class="keywordtype">float</span>* srcdata = (<span class="keywordtype">float</span>*)src.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo0">data</a>;
19300184         <span class="keywordtype">float</span>* pdst = (<span class="keywordtype">float</span>*)dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo0">data</a>;
19400185         
19500186         <span class="comment">// sx_48,sy_48,sz_48 represent current position in source</span>
19600187         <span class="comment">// using 16/48-bit fixed precision, incremented by steps</span>
19700188         <a class="code" href="namespaceOgre.html#a553">uint64</a> stepx = ((<a class="code" href="namespaceOgre.html#a553">uint64</a>)src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa10">getWidth</a>() &lt;&lt; 48) / dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa10">getWidth</a>();
19800189         <a class="code" href="namespaceOgre.html#a553">uint64</a> stepy = ((<a class="code" href="namespaceOgre.html#a553">uint64</a>)src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa11">getHeight</a>() &lt;&lt; 48) / dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa11">getHeight</a>();
19900190         <a class="code" href="namespaceOgre.html#a553">uint64</a> stepz = ((<a class="code" href="namespaceOgre.html#a553">uint64</a>)src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa12">getDepth</a>() &lt;&lt; 48) / dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa12">getDepth</a>();
20000191         
20100192         <span class="comment">// temp is 16/16 bit fixed precision, used to adjust a source</span>
20200193         <span class="comment">// coordinate (x, y, or z) backwards by half a pixel so that the</span>
20300194         <span class="comment">// integer bits represent the first sample (eg, sx1) and the</span>
20400195         <span class="comment">// fractional bits are the blend weight of the second sample</span>
20500196         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> temp;
20600197
20700198         <span class="comment">// note: ((stepz&gt;&gt;1) - 1) is an extra half-step increment to adjust</span>
20800199         <span class="comment">// for the center of the destination pixel, not the top-left corner</span>
20900200         <a class="code" href="namespaceOgre.html#a553">uint64</a> sz_48 = (stepz &gt;&gt; 1) - 1;
21000201         <span class="keywordflow">for</span> (size_t z = dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo8">front</a>; z &lt; dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo9">back</a>; z++, sz_48+=stepz) {
21100202             temp = sz_48 &gt;&gt; 32;
21200203             temp = (temp &gt; 0x8000)? temp - 0x8000 : 0;
21300204             size_t sz1 = temp &gt;&gt; 16;                 <span class="comment">// src z, sample #1</span>
21400205             size_t sz2 = std::min(sz1+1,src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa12">getDepth</a>()-1);<span class="comment">// src z, sample #2</span>
21500206             <span class="keywordtype">float</span> szf = (temp &amp; 0xFFFF) / 65536.f; <span class="comment">// weight of sample #2</span>
21600207
21700208             <a class="code" href="namespaceOgre.html#a553">uint64</a> sy_48 = (stepy &gt;&gt; 1) - 1;
21800209             <span class="keywordflow">for</span> (size_t y = dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo5">top</a>; y &lt; dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo7">bottom</a>; y++, sy_48+=stepy) {
21900210                 temp = sy_48 &gt;&gt; 32;
22000211                 temp = (temp &gt; 0x8000)? temp - 0x8000 : 0;
22100212                 size_t sy1 = temp &gt;&gt; 16;                    <span class="comment">// src y #1</span>
22200213                 size_t sy2 = std::min(sy1+1,src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa11">getHeight</a>()-1);<span class="comment">// src y #2</span>
22300214                 <span class="keywordtype">float</span> syf = (temp &amp; 0xFFFF) / 65536.f; <span class="comment">// weight of #2</span>
22400215                 
22500216                 <a class="code" href="namespaceOgre.html#a553">uint64</a> sx_48 = (stepx &gt;&gt; 1) - 1;
22600217                 <span class="keywordflow">for</span> (size_t x = dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo4">left</a>; x &lt; dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo6">right</a>; x++, sx_48+=stepx) {
22700218                     temp = sx_48 &gt;&gt; 32;
22800219                     temp = (temp &gt; 0x8000)? temp - 0x8000 : 0;
22900220                     size_t sx1 = temp &gt;&gt; 16;                    <span class="comment">// src x #1</span>
23000221                     size_t sx2 = std::min(sx1+1,src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa10">getWidth</a>()-1);<span class="comment">// src x #2</span>
23100222                     <span class="keywordtype">float</span> sxf = (temp &amp; 0xFFFF) / 65536.f; <span class="comment">// weight of #2</span>
23200223                     
23300224                     <span class="comment">// process R,G,B,A simultaneously for cache coherence?</span>
23400225                     <span class="keywordtype">float</span> accum[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
23500226
23600227 <span class="preprocessor">#define ACCUM3(x,y,z,factor) \</span>
23700228 <span class="preprocessor">    { float f = factor; \</span>
23800229 <span class="preprocessor">    size_t off = (x+y*src.rowPitch+z*src.slicePitch)*srcchannels; \</span>
23900230 <span class="preprocessor">    accum[0]+=srcdata[off+0]*f; accum[1]+=srcdata[off+1]*f; \</span>
24000231 <span class="preprocessor">    accum[2]+=srcdata[off+2]*f; }</span>
24100232 <span class="preprocessor"></span>
24200233 <span class="preprocessor">#define ACCUM4(x,y,z,factor) \</span>
24300234 <span class="preprocessor">    { float f = factor; \</span>
24400235 <span class="preprocessor">    size_t off = (x+y*src.rowPitch+z*src.slicePitch)*srcchannels; \</span>
24500236 <span class="preprocessor">    accum[0]+=srcdata[off+0]*f; accum[1]+=srcdata[off+1]*f; \</span>
24600237 <span class="preprocessor">    accum[2]+=srcdata[off+2]*f; accum[3]+=srcdata[off+3]*f; }</span>
24700238 <span class="preprocessor"></span>
24800239                     <span class="keywordflow">if</span> (srcchannels == 3 || dstchannels == 3) {
24900240                         <span class="comment">// RGB, no alpha</span>
25000241                         <a class="code" href="OgreImageResampler_8h.html#a1">ACCUM3</a>(sx1,sy1,sz1,(1.0f-sxf)*(1.0f-syf)*(1.0f-szf));
25100242                         <a class="code" href="OgreImageResampler_8h.html#a1">ACCUM3</a>(sx2,sy1,sz1,      sxf *(1.0f-syf)*(1.0f-szf));
25200243                         <a class="code" href="OgreImageResampler_8h.html#a1">ACCUM3</a>(sx1,sy2,sz1,(1.0f-sxf)*      syf *(1.0f-szf));
25300244                         <a class="code" href="OgreImageResampler_8h.html#a1">ACCUM3</a>(sx2,sy2,sz1,      sxf *      syf *(1.0f-szf));
25400245                         <a class="code" href="OgreImageResampler_8h.html#a1">ACCUM3</a>(sx1,sy1,sz2,(1.0f-sxf)*(1.0f-syf)*      szf );
25500246                         <a class="code" href="OgreImageResampler_8h.html#a1">ACCUM3</a>(sx2,sy1,sz2,      sxf *(1.0f-syf)*      szf );
25600247                         <a class="code" href="OgreImageResampler_8h.html#a1">ACCUM3</a>(sx1,sy2,sz2,(1.0f-sxf)*      syf *      szf );
25700248                         <a class="code" href="OgreImageResampler_8h.html#a1">ACCUM3</a>(sx2,sy2,sz2,      sxf *      syf *      szf );
25800249                         accum[3] = 1.0f;
25900250                     } <span class="keywordflow">else</span> {
26000251                         <span class="comment">// RGBA</span>
26100252                         <a class="code" href="OgreImageResampler_8h.html#a2">ACCUM4</a>(sx1,sy1,sz1,(1.0f-sxf)*(1.0f-syf)*(1.0f-szf));
26200253                         <a class="code" href="OgreImageResampler_8h.html#a2">ACCUM4</a>(sx2,sy1,sz1,      sxf *(1.0f-syf)*(1.0f-szf));
26300254                         <a class="code" href="OgreImageResampler_8h.html#a2">ACCUM4</a>(sx1,sy2,sz1,(1.0f-sxf)*      syf *(1.0f-szf));
26400255                         <a class="code" href="OgreImageResampler_8h.html#a2">ACCUM4</a>(sx2,sy2,sz1,      sxf *      syf *(1.0f-szf));
26500256                         <a class="code" href="OgreImageResampler_8h.html#a2">ACCUM4</a>(sx1,sy1,sz2,(1.0f-sxf)*(1.0f-syf)*      szf );
26600257                         <a class="code" href="OgreImageResampler_8h.html#a2">ACCUM4</a>(sx2,sy1,sz2,      sxf *(1.0f-syf)*      szf );
26700258                         <a class="code" href="OgreImageResampler_8h.html#a2">ACCUM4</a>(sx1,sy2,sz2,(1.0f-sxf)*      syf *      szf );
26800259                         <a class="code" href="OgreImageResampler_8h.html#a2">ACCUM4</a>(sx2,sy2,sz2,      sxf *      syf *      szf );
26900260                     }
27000261
27100262                     memcpy(pdst, accum, <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)*dstchannels);
27200263
27300264 <span class="preprocessor">#undef ACCUM3</span>
27400265 <span class="preprocessor"></span><span class="preprocessor">#undef ACCUM4</span>
27500266 <span class="preprocessor"></span>
27600267                     pdst += dstchannels;
27700268                 }
27800269                 pdst += dstchannels*dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxa4">getRowSkip</a>();
27900270             }
28000271             pdst += dstchannels*dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxa5">getSliceSkip</a>();
28100272         }
28200273     }
28300274 };
28400275
28500276
28600277
28700278 <span class="comment">// byte linear resampler, does not do any format conversions.</span>
28800279 <span class="comment">// only handles pixel formats that use 1 byte per color channel.</span>
28900280 <span class="comment">// 2D only; punts 3D pixelboxes to default LinearResampler (slow).</span>
29000281 <span class="comment">// templated on bytes-per-pixel to allow compiler optimizations, such</span>
29100282 <span class="comment">// as unrolling loops and replacing multiplies with bitshifts</span>
292<a name="l00283"></a><a class="code" href="structOgre_1_1LinearResampler__Byte.html">00283</a> <span class="keyword">template</span>&lt;<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> channels&gt; <span class="keyword">struct </span><a class="code" href="structOgre_1_1LinearResampler__Byte.html">LinearResampler_Byte</a> {
293<a name="l00284"></a><a class="code" href="structOgre_1_1LinearResampler__Byte.html#Ogre_1_1LinearResampler__Bytee0">00284</a>     <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structOgre_1_1LinearResampler__Byte.html#Ogre_1_1LinearResampler__Bytee0">scale</a>(<span class="keyword">const</span> <a class="code" href="classOgre_1_1PixelBox.html">PixelBox</a>&amp; src, <span class="keyword">const</span> <a class="code" href="classOgre_1_1PixelBox.html">PixelBox</a>&amp; dst) {
29400285         <span class="comment">// assert(src.format == dst.format);</span>
29500286
29600287         <span class="comment">// only optimized for 2D</span>
29700288         <span class="keywordflow">if</span> (src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa12">getDepth</a>() &gt; 1 || dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa12">getDepth</a>() &gt; 1) {
29800289             LinearResampler::scale(src, dst);
29900290             <span class="keywordflow">return</span>;
30000291         }
30100292
30200293         <span class="comment">// srcdata stays at beginning of slice, pdst is a moving pointer</span>
30300294         <a class="code" href="namespaceOgre.html#a421">uchar</a>* srcdata = (<a class="code" href="namespaceOgre.html#a421">uchar</a>*)src.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo0">data</a>;
30400295         <a class="code" href="namespaceOgre.html#a421">uchar</a>* pdst = (<a class="code" href="namespaceOgre.html#a421">uchar</a>*)dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo0">data</a>;
30500296
30600297         <span class="comment">// sx_48,sy_48 represent current position in source</span>
30700298         <span class="comment">// using 16/48-bit fixed precision, incremented by steps</span>
30800299         <a class="code" href="namespaceOgre.html#a553">uint64</a> stepx = ((<a class="code" href="namespaceOgre.html#a553">uint64</a>)src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa10">getWidth</a>() &lt;&lt; 48) / dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa10">getWidth</a>();
30900300         <a class="code" href="namespaceOgre.html#a553">uint64</a> stepy = ((<a class="code" href="namespaceOgre.html#a553">uint64</a>)src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa11">getHeight</a>() &lt;&lt; 48) / dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxa11">getHeight</a>();
31000301         
31100302         <span class="comment">// bottom 28 bits of temp are 16/12 bit fixed precision, used to</span>
31200303         <span class="comment">// adjust a source coordinate backwards by half a pixel so that the</span>
31300304         <span class="comment">// integer bits represent the first sample (eg, sx1) and the</span>
31400305         <span class="comment">// fractional bits are the blend weight of the second sample</span>
31500306         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> temp;
31600307         
31700308         <a class="code" href="namespaceOgre.html#a553">uint64</a> sy_48 = (stepy &gt;&gt; 1) - 1;
31800309         <span class="keywordflow">for</span> (size_t y = dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo5">top</a>; y &lt; dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo7">bottom</a>; y++, sy_48+=stepy) {
31900310             temp = sy_48 &gt;&gt; 36;
32000311             temp = (temp &gt; 0x800)? temp - 0x800: 0;
32100312             <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> syf = temp &amp; 0xFFF;
32200313             size_t sy1 = temp &gt;&gt; 12;
32300314             size_t sy2 = std::min(sy1+1, src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo7">bottom</a>-src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo5">top</a>-1);
32400315             size_t syoff1 = sy1 * src.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo2">rowPitch</a>;
32500316             size_t syoff2 = sy2 * src.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxo2">rowPitch</a>;
32600317
32700318             <a class="code" href="namespaceOgre.html#a553">uint64</a> sx_48 = (stepx &gt;&gt; 1) - 1;
32800319             <span class="keywordflow">for</span> (size_t x = dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo4">left</a>; x &lt; dst.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo6">right</a>; x++, sx_48+=stepx) {
32900320                 temp = sx_48 &gt;&gt; 36;
33000321                 temp = (temp &gt; 0x800)? temp - 0x800 : 0;
33100322                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> sxf = temp &amp; 0xFFF;
33200323                 size_t sx1 = temp &gt;&gt; 12;
33300324                 size_t sx2 = std::min(sx1+1, src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo6">right</a>-src.<a class="code" href="structOgre_1_1Box.html#Ogre_1_1PixelBoxo4">left</a>-1);
33400325
33500326                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> sxfsyf = sxf*syf;
33600327                 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> k = 0; k &lt; channels; k++) {
33700328                     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> accum =
33800329                         srcdata[(sx1 + syoff1)*channels+k]*(0x1000000-(sxf&lt;&lt;12)-(syf&lt;&lt;12)+sxfsyf) +
33900330                         srcdata[(sx2 + syoff1)*channels+k]*((sxf&lt;&lt;12)-sxfsyf) +
34000331                         srcdata[(sx1 + syoff2)*channels+k]*((syf&lt;&lt;12)-sxfsyf) +
34100332                         srcdata[(sx2 + syoff2)*channels+k]*sxfsyf;
34200333                     <span class="comment">// accum is computed using 8/24-bit fixed-point math</span>
34300334                     <span class="comment">// (maximum is 0xFF000000; rounding will not cause overflow)</span>
34400335                     *pdst++ = (accum + 0x800000) &gt;&gt; 24;
34500336                 }
34600337             }
34700338             pdst += channels*dst.<a class="code" href="classOgre_1_1PixelBox.html#Ogre_1_1PixelBoxa4">getRowSkip</a>();
34800339         }
34900340     }
35000341 };
35100342
35200343 }
35300344
35400345 <span class="preprocessor">#endif</span>
355</pre></div><hr>
356<p>
357Copyright &copy; 2000-2005 by The OGRE Team<br />
358<!--Creative Commons License--><a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/"><img alt="Creative Commons License" border="0" src="http://creativecommons.org/images/public/somerights20.png"/></a><br/>
359This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">Creative Commons Attribution-ShareAlike 2.5 License</a>.<br/>
360                <!--/Creative Commons License--><!-- <rdf:RDF xmlns="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
361                <Work rdf:about="">
362                        <license rdf:resource="http://creativecommons.org/licenses/by-sa/2.5/" />
363        <dc:type rdf:resource="http://purl.org/dc/dcmitype/Text" />
364                </Work>
365                <License rdf:about="http://creativecommons.org/licenses/by-sa/2.5/"><permits rdf:resource="http://web.resource.org/cc/Reproduction"/><permits rdf:resource="http://web.resource.org/cc/Distribution"/><requires rdf:resource="http://web.resource.org/cc/Notice"/><requires rdf:resource="http://web.resource.org/cc/Attribution"/><permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/><requires rdf:resource="http://web.resource.org/cc/ShareAlike"/></License></rdf:RDF> -->
366
367Last modified Sun Feb 12 12:59:46 2006
368</p>
369</body>
370</html>
Note: See TracBrowser for help on using the repository browser.