Sophie

Sophie

distrib > Mandriva > 9.0 > i586 > by-pkgid > d67485fb8ce60f8952179bbde3b5d022 > files > 114

libgdal0-devel-1.1.7-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta name="robots" content="noindex">
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>overview.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.3-20001105 on Thu Mar 28 09:47:30 2002 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; </center>
<hr><h1>overview.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> * $Id: overview_cpp-source.html,v 1.10 2002/04/16 13:11:49 warmerda Exp $</font>
00003 <font class="comment"> *</font>
00004 <font class="comment"> * Project:  GDAL Core</font>
00005 <font class="comment"> * Purpose:  Helper code to implement overview support in different drivers.</font>
00006 <font class="comment"> * Author:   Frank Warmerdam, warmerda@home.com</font>
00007 <font class="comment"> *</font>
00008 <font class="comment"> ******************************************************************************</font>
00009 <font class="comment"> * Copyright (c) 2000, Frank Warmerdam</font>
00010 <font class="comment"> *</font>
00011 <font class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</font>
00012 <font class="comment"> * copy of this software and associated documentation files (the "Software"),</font>
00013 <font class="comment"> * to deal in the Software without restriction, including without limitation</font>
00014 <font class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</font>
00015 <font class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</font>
00016 <font class="comment"> * Software is furnished to do so, subject to the following conditions:</font>
00017 <font class="comment"> *</font>
00018 <font class="comment"> * The above copyright notice and this permission notice shall be included</font>
00019 <font class="comment"> * in all copies or substantial portions of the Software.</font>
00020 <font class="comment"> *</font>
00021 <font class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</font>
00022 <font class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</font>
00023 <font class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</font>
00024 <font class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</font>
00025 <font class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</font>
00026 <font class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</font>
00027 <font class="comment"> * DEALINGS IN THE SOFTWARE.</font>
00028 <font class="comment"> ******************************************************************************</font>
00029 <font class="comment"> *</font>
00030 <font class="comment"> * $Log: overview_cpp-source.html,v $
00030 <font class="comment"> * Revision 1.10  2002/04/16 13:11:49  warmerda
00030 <font class="comment"> * updated
00030 <font class="comment"> *</font>
00031 <font class="comment"> * Revision 1.8  2001/07/18 04:04:30  warmerda</font>
00032 <font class="comment"> * added CPL_CVSID</font>
00033 <font class="comment"> *</font>
00034 <font class="comment"> * Revision 1.7  2001/07/16 15:21:46  warmerda</font>
00035 <font class="comment"> * added AVERAGE_MAGPHASE option for complex images</font>
00036 <font class="comment"> *</font>
00037 <font class="comment"> * Revision 1.6  2001/01/30 22:32:42  warmerda</font>
00038 <font class="comment"> * added AVERAGE_MP (magnitude preserving averaging) overview resampling type</font>
00039 <font class="comment"> *</font>
00040 <font class="comment"> * Revision 1.5  2000/11/22 18:41:45  warmerda</font>
00041 <font class="comment"> * fixed bug in complex overview generation</font>
00042 <font class="comment"> *</font>
00043 <font class="comment"> * Revision 1.4  2000/08/18 15:25:06  warmerda</font>
00044 <font class="comment"> * added cascading overview regeneration to speed up averaged overviews</font>
00045 <font class="comment"> *</font>
00046 <font class="comment"> * Revision 1.3  2000/07/17 17:08:45  warmerda</font>
00047 <font class="comment"> * added support for complex data</font>
00048 <font class="comment"> *</font>
00049 <font class="comment"> * Revision 1.2  2000/06/26 22:17:58  warmerda</font>
00050 <font class="comment"> * added scaled progress support</font>
00051 <font class="comment"> *</font>
00052 <font class="comment"> * Revision 1.1  2000/04/21 21:54:05  warmerda</font>
00053 <font class="comment"> * New</font>
00054 <font class="comment"> *</font>
00055 <font class="comment"> */</font>
00056 
00057 <font class="preprocessor">#include "gdal_priv.h"</font>
00058 
00059 CPL_CVSID(<font class="stringliteral">"$Id: overview_cpp-source.html,v 1.10 2002/04/16 13:11:49 warmerda Exp $"</font>);
00060 
00061 <font class="comment">/************************************************************************/</font>
00062 <font class="comment">/*                       GDALDownsampleChunk32R()                       */</font>
00063 <font class="comment">/************************************************************************/</font>
00064 
00065 <font class="keyword">static</font> CPLErr
00066 GDALDownsampleChunk32R( <font class="keywordtype">int</font> nSrcWidth, <font class="keywordtype">int</font> nSrcHeight, 
00067                         <font class="keywordtype">float</font> * pafChunk, <font class="keywordtype">int</font> nChunkYOff, <font class="keywordtype">int</font> nChunkYSize,
00068                         <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> * poOverview,
00069                         <font class="keyword">const</font> <font class="keywordtype">char</font> * pszResampling )<font class="keyword"></font>
00070 <font class="keyword"></font>
00071 <font class="keyword"></font>{
00072     <font class="keywordtype">int</font>      nDstYOff, nDstYOff2, nOXSize, nOYSize;
00073     <font class="keywordtype">float</font>    *pafDstScanline;
00074 
00075     nOXSize = poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>();
00076     nOYSize = poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>();
00077 
00078     pafDstScanline = (<font class="keywordtype">float</font> *) <a class="code" href="cpl_conv_h.html#a3">CPLMalloc</a>(nOXSize * <font class="keyword">sizeof</font>(<font class="keywordtype">float</font>));
00079 
00080 <font class="comment">/* -------------------------------------------------------------------- */</font>
00081 <font class="comment">/*      Figure out the line to start writing to, and the first line     */</font>
00082 <font class="comment">/*      to not write to.  In theory this approach should ensure that    */</font>
00083 <font class="comment">/*      every output line will be written if all input chunks are       */</font>
00084 <font class="comment">/*      processed.                                                      */</font>
00085 <font class="comment">/* -------------------------------------------------------------------- */</font>
00086     nDstYOff = (<font class="keywordtype">int</font>) (0.5 + (nChunkYOff/(<font class="keywordtype">double</font>)nSrcHeight) * nOYSize);
00087     nDstYOff2 = (<font class="keywordtype">int</font>) 
00088         (0.5 + ((nChunkYOff+nChunkYSize)/(<font class="keywordtype">double</font>)nSrcHeight) * nOYSize);
00089 
00090     <font class="keywordflow">if</font>( nChunkYOff + nChunkYSize == nSrcHeight )
00091         nDstYOff2 = nOYSize;
00092     
00093 <font class="comment">/* ==================================================================== */</font>
00094 <font class="comment">/*      Loop over destination scanlines.                                */</font>
00095 <font class="comment">/* ==================================================================== */</font>
00096     <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iDstLine = nDstYOff; iDstLine &lt; nDstYOff2; iDstLine++ )
00097     {
00098         <font class="keywordtype">float</font> *pafSrcScanline;
00099         <font class="keywordtype">int</font>   nSrcYOff, nSrcYOff2, iDstPixel;
00100 
00101         nSrcYOff = (<font class="keywordtype">int</font>) (0.5 + (iDstLine/(<font class="keywordtype">double</font>)nOYSize) * nSrcHeight);
00102         <font class="keywordflow">if</font>( nSrcYOff &lt; nChunkYOff )
00103             nSrcYOff = nChunkYOff;
00104         
00105         nSrcYOff2 = (<font class="keywordtype">int</font>) (0.5 + ((iDstLine+1)/(<font class="keywordtype">double</font>)nOYSize) * nSrcHeight);
00106         <font class="keywordflow">if</font>( nSrcYOff2 &gt; nSrcHeight || iDstLine == nOYSize-1 )
00107             nSrcYOff2 = nSrcHeight;
00108         <font class="keywordflow">if</font>( nSrcYOff2 &gt; nChunkYOff + nChunkYSize )
00109             nSrcYOff2 = nChunkYOff + nChunkYSize;
00110 
00111         pafSrcScanline = pafChunk + ((nSrcYOff-nChunkYOff) * nSrcWidth);
00112 
00113 <font class="comment">/* -------------------------------------------------------------------- */</font>
00114 <font class="comment">/*      Loop over destination pixels                                    */</font>
00115 <font class="comment">/* -------------------------------------------------------------------- */</font>
00116         <font class="keywordflow">for</font>( iDstPixel = 0; iDstPixel &lt; nOXSize; iDstPixel++ )
00117         {
00118             <font class="keywordtype">int</font>   nSrcXOff, nSrcXOff2;
00119 
00120             nSrcXOff = (<font class="keywordtype">int</font>) (0.5 + (iDstPixel/(<font class="keywordtype">double</font>)nOXSize) * nSrcWidth);
00121             nSrcXOff2 = (<font class="keywordtype">int</font>) 
00122                 (0.5 + ((iDstPixel+1)/(<font class="keywordtype">double</font>)nOXSize) * nSrcWidth);
00123             <font class="keywordflow">if</font>( nSrcXOff2 &gt; nSrcWidth )
00124                 nSrcXOff2 = nSrcWidth;
00125             
00126             <font class="keywordflow">if</font>( EQUALN(pszResampling,<font class="stringliteral">"NEAR"</font>,4) )
00127             {
00128                 pafDstScanline[iDstPixel] = pafSrcScanline[nSrcXOff];
00129             }
00130             <font class="keywordflow">else</font> <font class="keywordflow">if</font>( EQUALN(pszResampling,<font class="stringliteral">"AVER"</font>,4) )
00131             {
00132                 <font class="keywordtype">double</font> dfTotal = 0.0;
00133                 <font class="keywordtype">int</font>    nCount = 0, iX, iY;
00134 
00135                 <font class="keywordflow">for</font>( iY = nSrcYOff; iY &lt; nSrcYOff2; iY++ )
00136                  {
00137                     <font class="keywordflow">for</font>( iX = nSrcXOff; iX &lt; nSrcXOff2; iX++ )
00138                     {
00139                         dfTotal += pafSrcScanline[iX+(iY-nSrcYOff)*nSrcWidth];
00140                         nCount++;
00141                     }
00142                 }
00143                 
00144                 CPLAssert( nCount &gt; 0 );
00145                 <font class="keywordflow">if</font>( nCount == 0 )
00146                 {
00147                     pafDstScanline[iDstPixel] = 0.0;
00148                 }
00149                 <font class="keywordflow">else</font>
00150                     pafDstScanline[iDstPixel] = dfTotal / nCount;
00151             }
00152         }
00153 
00154         poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a8">RasterIO</a>( GF_Write, 0, iDstLine, nOXSize, 1, 
00155                               pafDstScanline, nOXSize, 1, GDT_Float32, 
00156                               0, 0 );
00157     }
00158 
00159     CPLFree( pafDstScanline );
00160 
00161     <font class="keywordflow">return</font> CE_None;
00162 }
00163 
00164 <font class="comment">/************************************************************************/</font>
00165 <font class="comment">/*                       GDALDownsampleChunkC32R()                      */</font>
00166 <font class="comment">/************************************************************************/</font>
00167 
00168 <font class="keyword">static</font> CPLErr
00169 GDALDownsampleChunkC32R( <font class="keywordtype">int</font> nSrcWidth, <font class="keywordtype">int</font> nSrcHeight, 
00170                          <font class="keywordtype">float</font> * pafChunk, <font class="keywordtype">int</font> nChunkYOff, <font class="keywordtype">int</font> nChunkYSize,
00171                          <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> * poOverview,
00172                          <font class="keyword">const</font> <font class="keywordtype">char</font> * pszResampling )<font class="keyword"></font>
00173 <font class="keyword">    </font>
00174 <font class="keyword"></font>{
00175     <font class="keywordtype">int</font>      nDstYOff, nDstYOff2, nOXSize, nOYSize;
00176     <font class="keywordtype">float</font>    *pafDstScanline;
00177 
00178     nOXSize = poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>();
00179     nOYSize = poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>();
00180 
00181     pafDstScanline = (<font class="keywordtype">float</font> *) <a class="code" href="cpl_conv_h.html#a3">CPLMalloc</a>(nOXSize * <font class="keyword">sizeof</font>(<font class="keywordtype">float</font>) * 2);
00182 
00183 <font class="comment">/* -------------------------------------------------------------------- */</font>
00184 <font class="comment">/*      Figure out the line to start writing to, and the first line     */</font>
00185 <font class="comment">/*      to not write to.  In theory this approach should ensure that    */</font>
00186 <font class="comment">/*      every output line will be written if all input chunks are       */</font>
00187 <font class="comment">/*      processed.                                                      */</font>
00188 <font class="comment">/* -------------------------------------------------------------------- */</font>
00189     nDstYOff = (<font class="keywordtype">int</font>) (0.5 + (nChunkYOff/(<font class="keywordtype">double</font>)nSrcHeight) * nOYSize);
00190     nDstYOff2 = (<font class="keywordtype">int</font>) 
00191         (0.5 + ((nChunkYOff+nChunkYSize)/(<font class="keywordtype">double</font>)nSrcHeight) * nOYSize);
00192 
00193     <font class="keywordflow">if</font>( nChunkYOff + nChunkYSize == nSrcHeight )
00194         nDstYOff2 = nOYSize;
00195     
00196 <font class="comment">/* ==================================================================== */</font>
00197 <font class="comment">/*      Loop over destination scanlines.                                */</font>
00198 <font class="comment">/* ==================================================================== */</font>
00199     <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iDstLine = nDstYOff; iDstLine &lt; nDstYOff2; iDstLine++ )
00200     {
00201         <font class="keywordtype">float</font> *pafSrcScanline;
00202         <font class="keywordtype">int</font>   nSrcYOff, nSrcYOff2, iDstPixel;
00203 
00204         nSrcYOff = (<font class="keywordtype">int</font>) (0.5 + (iDstLine/(<font class="keywordtype">double</font>)nOYSize) * nSrcHeight);
00205         <font class="keywordflow">if</font>( nSrcYOff &lt; nChunkYOff )
00206             nSrcYOff = nChunkYOff;
00207         
00208         nSrcYOff2 = (<font class="keywordtype">int</font>) (0.5 + ((iDstLine+1)/(<font class="keywordtype">double</font>)nOYSize) * nSrcHeight);
00209         <font class="keywordflow">if</font>( nSrcYOff2 &gt; nSrcHeight || iDstLine == nOYSize-1 )
00210             nSrcYOff2 = nSrcHeight;
00211         <font class="keywordflow">if</font>( nSrcYOff2 &gt; nChunkYOff + nChunkYSize )
00212             nSrcYOff2 = nChunkYOff + nChunkYSize;
00213 
00214         pafSrcScanline = pafChunk + ((nSrcYOff-nChunkYOff) * nSrcWidth) * 2;
00215 
00216 <font class="comment">/* -------------------------------------------------------------------- */</font>
00217 <font class="comment">/*      Loop over destination pixels                                    */</font>
00218 <font class="comment">/* -------------------------------------------------------------------- */</font>
00219         <font class="keywordflow">for</font>( iDstPixel = 0; iDstPixel &lt; nOXSize; iDstPixel++ )
00220         {
00221             <font class="keywordtype">int</font>   nSrcXOff, nSrcXOff2;
00222 
00223             nSrcXOff = (<font class="keywordtype">int</font>) (0.5 + (iDstPixel/(<font class="keywordtype">double</font>)nOXSize) * nSrcWidth);
00224             nSrcXOff2 = (<font class="keywordtype">int</font>) 
00225                 (0.5 + ((iDstPixel+1)/(<font class="keywordtype">double</font>)nOXSize) * nSrcWidth);
00226             <font class="keywordflow">if</font>( nSrcXOff2 &gt; nSrcWidth )
00227                 nSrcXOff2 = nSrcWidth;
00228             
00229             <font class="keywordflow">if</font>( EQUALN(pszResampling,<font class="stringliteral">"NEAR"</font>,4) )
00230             {
00231                 pafDstScanline[iDstPixel*2] = pafSrcScanline[nSrcXOff*2];
00232                 pafDstScanline[iDstPixel*2+1] = pafSrcScanline[nSrcXOff*2+1];
00233             }
00234             <font class="keywordflow">else</font> <font class="keywordflow">if</font>( EQUAL(pszResampling,<font class="stringliteral">"AVERAGE_MAGPHASE"</font>) )
00235             {
00236                 <font class="keywordtype">double</font> dfTotalR = 0.0, dfTotalI = 0.0, dfTotalM = 0.0;
00237                 <font class="keywordtype">int</font>    nCount = 0, iX, iY;
00238 
00239                 <font class="keywordflow">for</font>( iY = nSrcYOff; iY &lt; nSrcYOff2; iY++ )
00240                 {
00241                     <font class="keywordflow">for</font>( iX = nSrcXOff; iX &lt; nSrcXOff2; iX++ )
00242                     {
00243                         <font class="keywordtype">double</font>  dfR, dfI;
00244 
00245                         dfR = pafSrcScanline[iX*2+(iY-nSrcYOff)*nSrcWidth*2];
00246                         dfI = pafSrcScanline[iX*2+(iY-nSrcYOff)*nSrcWidth*2+1];
00247                         dfTotalR += dfR;
00248                         dfTotalI += dfI;
00249                         dfTotalM += sqrt( dfR*dfR + dfI*dfI );
00250                         nCount++;
00251                     }
00252                 }
00253                 
00254                 CPLAssert( nCount &gt; 0 );
00255                 <font class="keywordflow">if</font>( nCount == 0 )
00256                 {
00257                     pafDstScanline[iDstPixel*2] = 0.0;
00258                     pafDstScanline[iDstPixel*2+1] = 0.0;
00259                 }
00260                 <font class="keywordflow">else</font>
00261                 {
00262                     <font class="keywordtype">double</font>      dfM, dfDesiredM, dfRatio;
00263 
00264                     pafDstScanline[iDstPixel*2  ] = dfTotalR / nCount;
00265                     pafDstScanline[iDstPixel*2+1] = dfTotalI / nCount;
00266                     
00267                     dfM = sqrt(pafDstScanline[iDstPixel*2  ]*pafDstScanline[iDstPixel*2  ]
00268                              + pafDstScanline[iDstPixel*2+1]*pafDstScanline[iDstPixel*2+1]);
00269                     dfDesiredM = dfTotalM / nCount;
00270                     <font class="keywordflow">if</font>( dfM != 0.0 )
00271                         dfRatio = dfDesiredM / dfM;
00272 
00273                     pafDstScanline[iDstPixel*2  ] *= dfRatio;
00274                     pafDstScanline[iDstPixel*2+1] *= dfRatio;
00275                 }
00276             }
00277             <font class="keywordflow">else</font> <font class="keywordflow">if</font>( EQUALN(pszResampling,<font class="stringliteral">"AVER"</font>,4) )
00278             {
00279                 <font class="keywordtype">double</font> dfTotalR = 0.0, dfTotalI = 0.0;
00280                 <font class="keywordtype">int</font>    nCount = 0, iX, iY;
00281 
00282                 <font class="keywordflow">for</font>( iY = nSrcYOff; iY &lt; nSrcYOff2; iY++ )
00283                 {
00284                     <font class="keywordflow">for</font>( iX = nSrcXOff; iX &lt; nSrcXOff2; iX++ )
00285                     {
00286                         dfTotalR += pafSrcScanline[iX*2+(iY-nSrcYOff)*nSrcWidth*2];
00287                         dfTotalI += pafSrcScanline[iX*2+(iY-nSrcYOff)*nSrcWidth*2+1];
00288                         nCount++;
00289                     }
00290                 }
00291                 
00292                 CPLAssert( nCount &gt; 0 );
00293                 <font class="keywordflow">if</font>( nCount == 0 )
00294                 {
00295                     pafDstScanline[iDstPixel*2] = 0.0;
00296                     pafDstScanline[iDstPixel*2+1] = 0.0;
00297                 }
00298                 <font class="keywordflow">else</font>
00299                 {
00300                     pafDstScanline[iDstPixel*2  ] = dfTotalR / nCount;
00301                     pafDstScanline[iDstPixel*2+1] = dfTotalI / nCount;
00302                 }
00303             }
00304         }
00305 
00306         poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a8">RasterIO</a>( GF_Write, 0, iDstLine, nOXSize, 1, 
00307                               pafDstScanline, nOXSize, 1, GDT_CFloat32, 
00308                               0, 0 );
00309     }
00310 
00311     CPLFree( pafDstScanline );
00312 
00313     <font class="keywordflow">return</font> CE_None;
00314 }
00315 
00316 <font class="comment">/************************************************************************/</font>
00317 <font class="comment">/*                  GDALRegenerateCascadingOverviews()                  */</font>
00318 <font class="comment">/*                                                                      */</font>
00319 <font class="comment">/*      Generate a list of overviews in order from largest to           */</font>
00320 <font class="comment">/*      smallest, computing each from the next larger.                  */</font>
00321 <font class="comment">/************************************************************************/</font>
00322 
00323 <font class="keyword">static</font> CPLErr
00324 GDALRegenerateCascadingOverviews( 
00325     <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *poSrcBand, <font class="keywordtype">int</font> nOverviews, <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> **papoOvrBands, 
00326     <font class="keyword">const</font> <font class="keywordtype">char</font> * pszResampling, 
00327     GDALProgressFunc pfnProgress, <font class="keywordtype">void</font> * pProgressData )<font class="keyword"></font>
00328 <font class="keyword"></font>
00329 <font class="keyword"></font>{
00330 <font class="comment">/* -------------------------------------------------------------------- */</font>
00331 <font class="comment">/*      First, we must put the overviews in order from largest to       */</font>
00332 <font class="comment">/*      smallest.                                                       */</font>
00333 <font class="comment">/* -------------------------------------------------------------------- */</font>
00334     <font class="keywordtype">int</font>   i, j;
00335 
00336     <font class="keywordflow">for</font>( i = 0; i &lt; nOverviews-1; i++ )
00337     {
00338         <font class="keywordflow">for</font>( j = 0; j &lt; nOverviews - i - 1; j++ )
00339         {
00340 
00341             <font class="keywordflow">if</font>( papoOvrBands[j]-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() 
00342                 * (<font class="keywordtype">float</font>) papoOvrBands[j]-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() &lt;
00343                 papoOvrBands[j+1]-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>()
00344                 * (<font class="keywordtype">float</font>) papoOvrBands[j+1]-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() )
00345             {
00346                 <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> * poTempBand;
00347 
00348                 poTempBand = papoOvrBands[j];
00349                 papoOvrBands[j] = papoOvrBands[j+1];
00350                 papoOvrBands[j+1] = poTempBand;
00351             }
00352         }
00353     }
00354 
00355 <font class="comment">/* -------------------------------------------------------------------- */</font>
00356 <font class="comment">/*      Count total pixels so we can prepare appropriate scaled         */</font>
00357 <font class="comment">/*      progress functions.                                             */</font>
00358 <font class="comment">/* -------------------------------------------------------------------- */</font>
00359     <font class="keywordtype">double</font>       dfTotalPixels = 0.0;
00360 
00361     <font class="keywordflow">for</font>( i = 0; i &lt; nOverviews; i++ )
00362     {
00363         dfTotalPixels += papoOvrBands[i]-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>()
00364             * (<font class="keywordtype">double</font>) papoOvrBands[i]-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>();
00365     }
00366 
00367 <font class="comment">/* -------------------------------------------------------------------- */</font>
00368 <font class="comment">/*      Generate all the bands.                                         */</font>
00369 <font class="comment">/* -------------------------------------------------------------------- */</font>
00370     <font class="keywordtype">double</font>      dfPixelsProcessed = 0.0;
00371 
00372     <font class="keywordflow">for</font>( i = 0; i &lt; nOverviews; i++ )
00373     {
00374         <font class="keywordtype">void</font>    *pScaledProgressData;
00375         <font class="keywordtype">double</font>  dfPixels;
00376         <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *poBaseBand;
00377         CPLErr  eErr;
00378 
00379         <font class="keywordflow">if</font>( i == 0 )
00380             poBaseBand = poSrcBand;
00381         <font class="keywordflow">else</font>
00382             poBaseBand = papoOvrBands[i-1];
00383 
00384         dfPixels = papoOvrBands[i]-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() 
00385             * (<font class="keywordtype">double</font>) papoOvrBands[i]-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>();
00386 
00387         pScaledProgressData = GDALCreateScaledProgress( 
00388             dfPixelsProcessed / dfTotalPixels,
00389             (dfPixelsProcessed + dfPixels) / dfTotalPixels, 
00390             pfnProgress, pProgressData );
00391 
00392         eErr = GDALRegenerateOverviews( poBaseBand, 1, papoOvrBands + i, 
00393                                         pszResampling, 
00394                                         GDALScaledProgress, 
00395                                         pScaledProgressData );
00396         GDALDestroyScaledProgress( pScaledProgressData );
00397 
00398         <font class="keywordflow">if</font>( eErr != CE_None )
00399             <font class="keywordflow">return</font> eErr;
00400 
00401         dfPixelsProcessed += dfPixels;
00402     }
00403 
00404     <font class="keywordflow">return</font> CE_None;
00405 }
00406 
00407 <font class="comment">/************************************************************************/</font>
00408 <font class="comment">/*                      GDALRegenerateOverviews()                       */</font>
00409 <font class="comment">/************************************************************************/</font>
00410 CPLErr 
00411 GDALRegenerateOverviews( <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *poSrcBand,
00412                          <font class="keywordtype">int</font> nOverviews, <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> **papoOvrBands, 
00413                          <font class="keyword">const</font> <font class="keywordtype">char</font> * pszResampling, 
00414                          GDALProgressFunc pfnProgress, <font class="keywordtype">void</font> * pProgressData )<font class="keyword"></font>
00415 <font class="keyword"></font>
00416 <font class="keyword"></font>{
00417     <font class="keywordtype">int</font>    nFullResYChunk, nWidth;
00418     <font class="keywordtype">int</font>    nFRXBlockSize, nFRYBlockSize;
00419     GDALDataType eType;
00420 
00421 <font class="comment">/* -------------------------------------------------------------------- */</font>
00422 <font class="comment">/*      If we are operating on multiple overviews, and using            */</font>
00423 <font class="comment">/*      averaging, lets do them in cascading order to reduce the        */</font>
00424 <font class="comment">/*      amount of computation.                                          */</font>
00425 <font class="comment">/* -------------------------------------------------------------------- */</font>
00426     <font class="keywordflow">if</font>( EQUALN(pszResampling,<font class="stringliteral">"AVER"</font>,4) &amp;&amp; nOverviews &gt; 1 )
00427         <font class="keywordflow">return</font> GDALRegenerateCascadingOverviews( poSrcBand, 
00428                                                  nOverviews, papoOvrBands,
00429                                                  pszResampling, 
00430                                                  pfnProgress,
00431                                                  pProgressData );
00432 
00433 <font class="comment">/* -------------------------------------------------------------------- */</font>
00434 <font class="comment">/*      Setup one horizontal swath to read from the raw buffer.         */</font>
00435 <font class="comment">/* -------------------------------------------------------------------- */</font>
00436     <font class="keywordtype">float</font> *pafChunk;
00437 
00438     poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a6">GetBlockSize</a>( &amp;nFRXBlockSize, &amp;nFRYBlockSize );
00439     
00440     <font class="keywordflow">if</font>( nFRYBlockSize &lt; 4 || nFRYBlockSize &gt; 256 )
00441         nFullResYChunk = 32;
00442     <font class="keywordflow">else</font>
00443         nFullResYChunk = nFRYBlockSize;
00444 
00445     <font class="keywordflow">if</font>( GDALDataTypeIsComplex( poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a5">GetRasterDataType</a>() ) )
00446         eType = GDT_CFloat32;
00447     <font class="keywordflow">else</font>
00448         eType = GDT_Float32;
00449 
00450     nWidth = poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>();
00451     pafChunk = (<font class="keywordtype">float</font> *) 
00452         VSIMalloc((GDALGetDataTypeSize(eType)/8) * nFullResYChunk * nWidth );
00453 
00454     <font class="keywordflow">if</font>( pafChunk == NULL )
00455     {
00456         <a class="code" href="cpl_error_h.html#a17">CPLError</a>( CE_Failure, CPLE_OutOfMemory, 
00457                   <font class="stringliteral">"Out of memory in GDALRegenerateOverviews()."</font> );
00458 
00459         <font class="keywordflow">return</font> CE_Failure;
00460     }
00461     
00462 <font class="comment">/* -------------------------------------------------------------------- */</font>
00463 <font class="comment">/*      Loop over image operating on chunks.                            */</font>
00464 <font class="comment">/* -------------------------------------------------------------------- */</font>
00465     <font class="keywordtype">int</font>  nChunkYOff = 0;
00466 
00467     <font class="keywordflow">for</font>( nChunkYOff = 0; 
00468          nChunkYOff &lt; poSrcBand-&gt;GetYSize(); 
00469          nChunkYOff += nFullResYChunk )
00470     {
00471         <font class="keywordflow">if</font>( !pfnProgress( nChunkYOff / (<font class="keywordtype">double</font>) poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>(), 
00472                           NULL, pProgressData ) )
00473         {
00474             <a class="code" href="cpl_error_h.html#a17">CPLError</a>( CE_Failure, CPLE_UserInterrupt, <font class="stringliteral">"User terminated"</font> );
00475             <font class="keywordflow">return</font> CE_Failure;
00476         }
00477 
00478         <font class="keywordflow">if</font>( nFullResYChunk + nChunkYOff &gt; poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() )
00479             nFullResYChunk = poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() - nChunkYOff;
00480         
00481         <font class="comment">/* read chunk */</font>
00482         poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a8">RasterIO</a>( GF_Read, 0, nChunkYOff, nWidth, nFullResYChunk, 
00483                              pafChunk, nWidth, nFullResYChunk, eType,
00484                              0, 0 );
00485         
00486         <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iOverview = 0; iOverview &lt; nOverviews; iOverview++ )
00487         {
00488             <font class="keywordflow">if</font>( eType == GDT_Float32 )
00489                 GDALDownsampleChunk32R(nWidth, poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>(), 
00490                                        pafChunk, nChunkYOff, nFullResYChunk,
00491                                        papoOvrBands[iOverview], pszResampling);
00492             <font class="keywordflow">else</font>
00493                 GDALDownsampleChunkC32R(nWidth, poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>(), 
00494                                        pafChunk, nChunkYOff, nFullResYChunk,
00495                                        papoOvrBands[iOverview], pszResampling);
00496         }
00497     }
00498 
00499     VSIFree( pafChunk );
00500     
00501 <font class="comment">/* -------------------------------------------------------------------- */</font>
00502 <font class="comment">/*      Renormalized overview mean / stddev if needed.                  */</font>
00503 <font class="comment">/* -------------------------------------------------------------------- */</font>
00504     <font class="keywordflow">if</font>( EQUAL(pszResampling,<font class="stringliteral">"AVERAGE_MP"</font>) )
00505     {
00506         GDALOverviewMagnitudeCorrection( (GDALRasterBandH) poSrcBand, 
00507                                          nOverviews, 
00508                                          (GDALRasterBandH *) papoOvrBands,
00509                                          GDALDummyProgress, NULL );
00510     }
00511 
00512 <font class="comment">/* -------------------------------------------------------------------- */</font>
00513 <font class="comment">/*      It can be important to flush out data to overviews.             */</font>
00514 <font class="comment">/* -------------------------------------------------------------------- */</font>
00515     <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iOverview = 0; iOverview &lt; nOverviews; iOverview++ )
00516         papoOvrBands[iOverview]-&gt;<a class="code" href="class_GDALRasterBand.html#a12">FlushCache</a>();
00517 
00518     pfnProgress( 1.0, NULL, pProgressData );
00519 
00520     <font class="keywordflow">return</font> CE_None;
00521 }
00522 
00523 <font class="comment">/************************************************************************/</font>
00524 <font class="comment">/*                        GDALComputeBandStats()                        */</font>
00525 <font class="comment">/************************************************************************/</font>
00526 
00527 CPLErr
00528 GDALComputeBandStats( GDALRasterBandH hSrcBand,
00529                       <font class="keywordtype">int</font> nSampleStep,
00530                       <font class="keywordtype">double</font> *pdfMean, <font class="keywordtype">double</font> *pdfStdDev, 
00531                       GDALProgressFunc pfnProgress, 
00532                       <font class="keywordtype">void</font> *pProgressData )<font class="keyword"></font>
00533 <font class="keyword"></font>
00534 <font class="keyword"></font>{
00535     <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *poSrcBand = (<a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *) hSrcBand;
00536     <font class="keywordtype">int</font>         iLine, nWidth, nHeight;
00537     GDALDataType eType = poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a5">GetRasterDataType</a>();
00538     GDALDataType eWrkType;
00539     <font class="keywordtype">int</font>         bComplex;
00540     <font class="keywordtype">float</font>       *pafData;
00541     <font class="keywordtype">double</font>      dfSum=0.0, dfSum2=0.0;
00542     <font class="keywordtype">int</font>         nSamples = 0;
00543 
00544     nWidth = poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>();
00545     nHeight = poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>();
00546 
00547     <font class="keywordflow">if</font>( nSampleStep &gt;= nHeight )
00548         nSampleStep = 1;
00549 
00550     bComplex = GDALDataTypeIsComplex(eType);
00551     <font class="keywordflow">if</font>( bComplex )
00552     {
00553         pafData = (<font class="keywordtype">float</font> *) <a class="code" href="cpl_conv_h.html#a3">CPLMalloc</a>(nWidth * 2 * <font class="keyword">sizeof</font>(<font class="keywordtype">float</font>));
00554         eWrkType = GDT_CFloat32;
00555     }
00556     <font class="keywordflow">else</font>
00557     {
00558         pafData = (<font class="keywordtype">float</font> *) <a class="code" href="cpl_conv_h.html#a3">CPLMalloc</a>(nWidth * <font class="keyword">sizeof</font>(<font class="keywordtype">float</font>));
00559         eWrkType = GDT_Float32;
00560     }
00561 
00562 <font class="comment">/* -------------------------------------------------------------------- */</font>
00563 <font class="comment">/*      Loop over all sample lines.                                     */</font>
00564 <font class="comment">/* -------------------------------------------------------------------- */</font>
00565     <font class="keywordflow">for</font>( iLine = 0; iLine &lt; nHeight; iLine += nSampleStep )
00566     {
00567         <font class="keywordtype">int</font>     iPixel;
00568 
00569         <font class="keywordflow">if</font>( !pfnProgress( iLine / (<font class="keywordtype">double</font>) nHeight,
00570                           NULL, pProgressData ) )
00571         {
00572             <a class="code" href="cpl_error_h.html#a17">CPLError</a>( CE_Failure, CPLE_UserInterrupt, <font class="stringliteral">"User terminated"</font> );
00573             CPLFree( pafData );
00574             <font class="keywordflow">return</font> CE_Failure;
00575         }
00576 
00577         poSrcBand-&gt;<a class="code" href="class_GDALRasterBand.html#a8">RasterIO</a>( GF_Read, 0, iLine, nWidth, 1,
00578                              pafData, nWidth, 1, eWrkType,
00579                              0, 0 );
00580 
00581         <font class="keywordflow">for</font>( iPixel = 0; iPixel &lt; nWidth; iPixel++ )
00582         {
00583             <font class="keywordtype">float</font>       fValue;
00584 
00585             <font class="keywordflow">if</font>( bComplex )
00586             {
00587                 <font class="comment">// Compute the magnitude of the complex value.</font>
00588 
00589                 fValue = sqrt(pafData[iPixel*2  ] * pafData[iPixel*2  ]
00590                             + pafData[iPixel*2+1] * pafData[iPixel*2+1]);
00591             }
00592             <font class="keywordflow">else</font>
00593             {
00594                 fValue = pafData[iPixel];
00595             }
00596 
00597             dfSum  += fValue;
00598             dfSum2 += fValue * fValue;
00599         }
00600 
00601         nSamples += nWidth;
00602     }
00603 
00604     <font class="keywordflow">if</font>( !pfnProgress( 1.0, NULL, pProgressData ) )
00605     {
00606         <a class="code" href="cpl_error_h.html#a17">CPLError</a>( CE_Failure, CPLE_UserInterrupt, <font class="stringliteral">"User terminated"</font> );
00607         CPLFree( pafData );
00608         <font class="keywordflow">return</font> CE_Failure;
00609     }
00610 
00611 <font class="comment">/* -------------------------------------------------------------------- */</font>
00612 <font class="comment">/*      Produce the result values.                                      */</font>
00613 <font class="comment">/* -------------------------------------------------------------------- */</font>
00614     <font class="keywordflow">if</font>( pdfMean != NULL )
00615         *pdfMean = dfSum / nSamples;
00616 
00617     <font class="keywordflow">if</font>( pdfStdDev != NULL )
00618     {
00619         <font class="keywordtype">double</font>  dfMean = dfSum / nSamples;
00620 
00621         *pdfStdDev = sqrt((dfSum2 / nSamples) - (dfMean * dfMean));
00622     }
00623 
00624     CPLFree( pafData );
00625 
00626     <font class="keywordflow">return</font> CE_None;
00627 }
00628 
00629 <font class="comment">/************************************************************************/</font>
00630 <font class="comment">/*                  GDALOverviewMagnitudeCorrection()                   */</font>
00631 <font class="comment">/*                                                                      */</font>
00632 <font class="comment">/*      Correct the mean and standard deviation of the overviews of     */</font>
00633 <font class="comment">/*      the given band to match the base layer approximately.           */</font>
00634 <font class="comment">/************************************************************************/</font>
00635 
00636 CPLErr
00637 GDALOverviewMagnitudeCorrection( GDALRasterBandH hBaseBand, 
00638                                  <font class="keywordtype">int</font> nOverviewCount,
00639                                  GDALRasterBandH *pahOverviews,
00640                                  GDALProgressFunc pfnProgress, 
00641                                  <font class="keywordtype">void</font> *pProgressData )<font class="keyword"></font>
00642 <font class="keyword"></font>
00643 <font class="keyword"></font>{
00644     CPLErr      eErr;
00645     <font class="keywordtype">double</font>      dfOrigMean, dfOrigStdDev;
00646 
00647 <font class="comment">/* -------------------------------------------------------------------- */</font>
00648 <font class="comment">/*      Compute mean/stddev for source raster.                          */</font>
00649 <font class="comment">/* -------------------------------------------------------------------- */</font>
00650     eErr = GDALComputeBandStats( hBaseBand, 2, &amp;dfOrigMean, &amp;dfOrigStdDev, 
00651                                  pfnProgress, pProgressData );
00652 
00653     <font class="keywordflow">if</font>( eErr != CE_None )
00654         <font class="keywordflow">return</font> eErr;
00655     
00656 <font class="comment">/* -------------------------------------------------------------------- */</font>
00657 <font class="comment">/*      Loop on overview bands.                                         */</font>
00658 <font class="comment">/* -------------------------------------------------------------------- */</font>
00659     <font class="keywordtype">int</font>         iOverview;
00660 
00661     <font class="keywordflow">for</font>( iOverview = 0; iOverview &lt; nOverviewCount; iOverview++ )
00662     {
00663         <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *poOverview = (<a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a> *)pahOverviews[iOverview];
00664         <font class="keywordtype">double</font>  dfOverviewMean, dfOverviewStdDev;
00665         <font class="keywordtype">double</font>  dfGain;
00666 
00667         eErr = GDALComputeBandStats( pahOverviews[iOverview], 1, 
00668                                      &amp;dfOverviewMean, &amp;dfOverviewStdDev, 
00669                                      pfnProgress, pProgressData );
00670 
00671         <font class="keywordflow">if</font>( eErr != CE_None )
00672             <font class="keywordflow">return</font> eErr;
00673 
00674         <font class="keywordflow">if</font>( dfOrigStdDev &lt; 0.0001 )
00675             dfGain = 1.0;
00676         <font class="keywordflow">else</font>
00677             dfGain = dfOrigStdDev / dfOverviewStdDev;
00678 
00679 <font class="comment">/* -------------------------------------------------------------------- */</font>
00680 <font class="comment">/*      Apply gain and offset.                                          */</font>
00681 <font class="comment">/* -------------------------------------------------------------------- */</font>
00682         GDALDataType    eWrkType, eType = poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a5">GetRasterDataType</a>();
00683         <font class="keywordtype">int</font>             iLine, nWidth, nHeight, bComplex;
00684         <font class="keywordtype">float</font>           *pafData;
00685 
00686         nWidth = poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>();
00687         nHeight = poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>();
00688 
00689         bComplex = GDALDataTypeIsComplex(eType);
00690         <font class="keywordflow">if</font>( bComplex )
00691         {
00692             pafData = (<font class="keywordtype">float</font> *) <a class="code" href="cpl_conv_h.html#a3">CPLMalloc</a>(nWidth * 2 * <font class="keyword">sizeof</font>(<font class="keywordtype">float</font>));
00693             eWrkType = GDT_CFloat32;
00694         }
00695         <font class="keywordflow">else</font>
00696         {
00697             pafData = (<font class="keywordtype">float</font> *) <a class="code" href="cpl_conv_h.html#a3">CPLMalloc</a>(nWidth * <font class="keyword">sizeof</font>(<font class="keywordtype">float</font>));
00698             eWrkType = GDT_Float32;
00699         }
00700 
00701         <font class="keywordflow">for</font>( iLine = 0; iLine &lt; nHeight; iLine++ )
00702         {
00703             <font class="keywordtype">int</font> iPixel;
00704             
00705             <font class="keywordflow">if</font>( !pfnProgress( iLine / (<font class="keywordtype">double</font>) nHeight,
00706                               NULL, pProgressData ) )
00707             {
00708                 <a class="code" href="cpl_error_h.html#a17">CPLError</a>( CE_Failure, CPLE_UserInterrupt, <font class="stringliteral">"User terminated"</font> );
00709                 CPLFree( pafData );
00710                 <font class="keywordflow">return</font> CE_Failure;
00711             }
00712 
00713             poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a8">RasterIO</a>( GF_Read, 0, iLine, nWidth, 1,
00714                                   pafData, nWidth, 1, eWrkType,
00715                                   0, 0 );
00716             
00717             <font class="keywordflow">for</font>( iPixel = 0; iPixel &lt; nWidth; iPixel++ )
00718             {
00719                 <font class="keywordflow">if</font>( bComplex )
00720                 {
00721                     pafData[iPixel*2] *= dfGain;
00722                     pafData[iPixel*2+1] *= dfGain;
00723                 }
00724                 <font class="keywordflow">else</font>
00725                 {
00726                     pafData[iPixel] = (pafData[iPixel]-dfOverviewMean)*dfGain 
00727                         + dfOrigMean;
00728 
00729                 }
00730             }
00731 
00732             poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a8">RasterIO</a>( GF_Write, 0, iLine, nWidth, 1,
00733                                   pafData, nWidth, 1, eWrkType,
00734                                   0, 0 );
00735         }
00736 
00737         <font class="keywordflow">if</font>( !pfnProgress( 1.0, NULL, pProgressData ) )
00738         {
00739             <a class="code" href="cpl_error_h.html#a17">CPLError</a>( CE_Failure, CPLE_UserInterrupt, <font class="stringliteral">"User terminated"</font> );
00740             CPLFree( pafData );
00741             <font class="keywordflow">return</font> CE_Failure;
00742         }
00743         
00744         CPLFree( pafData );
00745     }
00746 
00747     <font class="keywordflow">return</font> CE_None;
00748 }
</div></pre><hr><address><small>Generated at Thu Mar 28 09:47:30 2002 for GDAL by
<a href="http://www.stack.nl/~dimitri/doxygen/index.html">
<img src="doxygen.gif" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.3-20001105 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,
 &copy;&nbsp;1997-2000</small></address>
</body>
</html>