Sophie

Sophie

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

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>rasterio.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>rasterio.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> * $Id: rasterio_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:  Contains default implementation of GDALRasterBand::IRasterIO()</font>
00006 <font class="comment"> *           and supporting functions of broader utility.</font>
00007 <font class="comment"> * Author:   Frank Warmerdam, warmerda@home.com</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> ******************************************************************************</font>
00010 <font class="comment"> * Copyright (c) 1998, Frank Warmerdam</font>
00011 <font class="comment"> *</font>
00012 <font class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</font>
00013 <font class="comment"> * copy of this software and associated documentation files (the "Software"),</font>
00014 <font class="comment"> * to deal in the Software without restriction, including without limitation</font>
00015 <font class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</font>
00016 <font class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</font>
00017 <font class="comment"> * Software is furnished to do so, subject to the following conditions:</font>
00018 <font class="comment"> *</font>
00019 <font class="comment"> * The above copyright notice and this permission notice shall be included</font>
00020 <font class="comment"> * in all copies or substantial portions of the Software.</font>
00021 <font class="comment"> *</font>
00022 <font class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</font>
00023 <font class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</font>
00024 <font class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</font>
00025 <font class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</font>
00026 <font class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</font>
00027 <font class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</font>
00028 <font class="comment"> * DEALINGS IN THE SOFTWARE.</font>
00029 <font class="comment"> ******************************************************************************</font>
00030 <font class="comment"> *</font>
00031 <font class="comment"> * $Log: rasterio_cpp-source.html,v $
00031 <font class="comment"> * Revision 1.10  2002/04/16 13:11:49  warmerda
00031 <font class="comment"> * updated
00031 <font class="comment"> *</font>
00032 <font class="comment"> * Revision 1.14  2001/07/18 04:04:31  warmerda</font>
00033 <font class="comment"> * added CPL_CVSID</font>
00034 <font class="comment"> *</font>
00035 <font class="comment"> * Revision 1.13  2000/08/16 15:50:52  warmerda</font>
00036 <font class="comment"> * fixed some bugs with floating (datasetless) bands</font>
00037 <font class="comment"> *</font>
00038 <font class="comment"> * Revision 1.12  2000/07/13 13:08:53  warmerda</font>
00039 <font class="comment"> * fixed GDALSwapWords with skip value different from word size</font>
00040 <font class="comment"> *</font>
00041 <font class="comment"> * Revision 1.11  2000/06/05 17:24:05  warmerda</font>
00042 <font class="comment"> * added real complex support</font>
00043 <font class="comment"> *</font>
00044 <font class="comment"> * Revision 1.10  2000/05/15 14:33:49  warmerda</font>
00045 <font class="comment"> * don't crash on read failure</font>
00046 <font class="comment"> *</font>
00047 <font class="comment"> * Revision 1.9  2000/04/04 15:25:13  warmerda</font>
00048 <font class="comment"> * Fixed embarrasing bug in GDALCopyWords() for some cases.</font>
00049 <font class="comment"> *</font>
00050 <font class="comment"> * Revision 1.8  2000/03/06 18:57:07  warmerda</font>
00051 <font class="comment"> * Fixed bug in 1:1 special case code.</font>
00052 <font class="comment"> *</font>
00053 <font class="comment"> * Revision 1.7  2000/03/06 02:22:13  warmerda</font>
00054 <font class="comment"> * added overview support</font>
00055 <font class="comment"> *</font>
00056 <font class="comment"> * Revision 1.6  1999/11/23 18:44:10  warmerda</font>
00057 <font class="comment"> * Fixed GDALCopyWords!</font>
00058 <font class="comment"> *</font>
00059 <font class="comment"> * Revision 1.5  1999/07/23 19:36:09  warmerda</font>
00060 <font class="comment"> * added support for data type translation and a swapping function</font>
00061 <font class="comment"> *</font>
00062 <font class="comment"> * Revision 1.4  1999/01/11 15:38:38  warmerda</font>
00063 <font class="comment"> * Added optimized case for simple 1:1 copies.</font>
00064 <font class="comment"> *</font>
00065 <font class="comment"> * Revision 1.3  1999/01/02 21:14:01  warmerda</font>
00066 <font class="comment"> * Added write support</font>
00067 <font class="comment"> *</font>
00068 <font class="comment"> * Revision 1.2  1998/12/31 18:54:25  warmerda</font>
00069 <font class="comment"> * Implement initial GDALRasterBlock support, and block cache</font>
00070 <font class="comment"> *</font>
00071 <font class="comment"> * Revision 1.1  1998/12/06 22:15:42  warmerda</font>
00072 <font class="comment"> * New</font>
00073 <font class="comment"> */</font>
00074 
00075 <font class="preprocessor">#include "gdal_priv.h"</font>
00076 
00077 CPL_CVSID(<font class="stringliteral">"$Id: rasterio_cpp-source.html,v 1.10 2002/04/16 13:11:49 warmerda Exp $"</font>);
00078 
00079 <font class="comment">/************************************************************************/</font>
00080 <font class="comment">/*                             IRasterIO()                              */</font>
00081 <font class="comment">/*                                                                      */</font>
00082 <font class="comment">/*      Default internal implementation of RasterIO() ... utilizes      */</font>
00083 <font class="comment">/*      the Block access methods to satisfy the request.  This would    */</font>
00084 <font class="comment">/*      normally only be overridden by formats with overviews.          */</font>
00085 <font class="comment">/************************************************************************/</font>
00086 
00087 CPLErr GDALRasterBand::IRasterIO( GDALRWFlag eRWFlag,
00088                                   <font class="keywordtype">int</font> nXOff, <font class="keywordtype">int</font> nYOff, <font class="keywordtype">int</font> nXSize, <font class="keywordtype">int</font> nYSize,
00089                                   <font class="keywordtype">void</font> * pData, <font class="keywordtype">int</font> nBufXSize, <font class="keywordtype">int</font> nBufYSize,
00090                                   GDALDataType eBufType,
00091                                   <font class="keywordtype">int</font> nPixelSpace, <font class="keywordtype">int</font> nLineSpace )<font class="keyword"></font>
00092 <font class="keyword"></font>
00093 <font class="keyword"></font>{
00094     <font class="keywordtype">int</font>         nBandDataSize = GDALGetDataTypeSize( eDataType ) / 8;
00095     GByte       *pabySrcBlock = NULL;
00096     <a class="code" href="class_GDALRasterBlock.html">GDALRasterBlock</a> *poBlock;
00097     <font class="keywordtype">int</font>         nLBlockX=-1, nLBlockY=-1, iBufYOff, iBufXOff, iSrcY;
00098 
00099 <font class="comment">/* ==================================================================== */</font>
00100 <font class="comment">/*      A common case is the data requested with it's inherent data     */</font>
00101 <font class="comment">/*      type, the destination is packed, and the block width is the     */</font>
00102 <font class="comment">/*      raster width.                                                   */</font>
00103 <font class="comment">/* ==================================================================== */</font>
00104     <font class="keywordflow">if</font>( eBufType == eDataType
00105         &amp;&amp; nPixelSpace == GDALGetDataTypeSize(eBufType)/8
00106         &amp;&amp; nLineSpace == nPixelSpace * nXSize
00107         &amp;&amp; nBlockXSize == <a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>()
00108         &amp;&amp; nBufXSize == nXSize 
00109         &amp;&amp; nBufYSize == nYSize )
00110     {
00111         <font class="keywordflow">for</font>( iBufYOff = 0; iBufYOff &lt; nBufYSize; iBufYOff++ )
00112         {
00113             <font class="keywordtype">int</font>         nSrcByteOffset;
00114             
00115             iSrcY = iBufYOff + nYOff;
00116             
00117             <font class="keywordflow">if</font>( iSrcY &lt; nLBlockY * nBlockYSize
00118                 || iSrcY &gt;= (nLBlockY+1) * nBlockYSize )
00119             {
00120                 nLBlockY = iSrcY / nBlockYSize;
00121 
00122                 poBlock = <a class="code" href="class_GDALRasterBand.html#a11">GetBlockRef</a>( 0, nLBlockY );
00123                 <font class="keywordflow">if</font>( poBlock == NULL )
00124                 {
00125                     <font class="keywordflow">return</font>( CE_Failure );
00126                 }
00127 
00128                 <font class="keywordflow">if</font>( eRWFlag == GF_Write )
00129                     poBlock-&gt;MarkDirty();
00130                 
00131                 pabySrcBlock = (GByte *) poBlock-&gt;GetDataRef();
00132             }
00133 
00134             nSrcByteOffset = ((iSrcY-nLBlockY*nBlockYSize)*nBlockXSize + nXOff)
00135                 * nPixelSpace;
00136             
00137             <font class="keywordflow">if</font>( eRWFlag == GF_Write )
00138                 memcpy( pabySrcBlock + nSrcByteOffset, 
00139                         ((GByte *) pData) + iBufYOff * nLineSpace,
00140                         nLineSpace );
00141             <font class="keywordflow">else</font>
00142                 memcpy( ((GByte *) pData) + iBufYOff * nLineSpace,
00143                         pabySrcBlock + nSrcByteOffset, 
00144                         nLineSpace );
00145         }
00146 
00147         <font class="keywordflow">return</font> CE_None;
00148     }
00149     
00150 <font class="comment">/* ==================================================================== */</font>
00151 <font class="comment">/*      Do we have overviews that would be appropriate to satisfy       */</font>
00152 <font class="comment">/*      this request?                                                   */</font>
00153 <font class="comment">/* ==================================================================== */</font>
00154     <font class="keywordflow">if</font>( (nBufXSize &lt; nXSize || nBufYSize &lt; nYSize)
00155         &amp;&amp; <a class="code" href="class_GDALRasterBand.html#a28">GetOverviewCount</a>() &gt; 0 &amp;&amp; eRWFlag == GF_Read )
00156     {
00157         <font class="keywordflow">if</font>( OverviewRasterIO( eRWFlag, nXOff, nYOff, nXSize, nYSize, 
00158                               pData, nBufXSize, nBufYSize, 
00159                               eBufType, nPixelSpace, nLineSpace ) == CE_None )
00160             <font class="keywordflow">return</font> CE_None;
00161     }
00162     
00163 <font class="comment">/* ==================================================================== */</font>
00164 <font class="comment">/*      Loop reading required source blocks to satisfy output           */</font>
00165 <font class="comment">/*      request.  This is the most general implementation.              */</font>
00166 <font class="comment">/* ==================================================================== */</font>
00167 
00168 <font class="comment">/* -------------------------------------------------------------------- */</font>
00169 <font class="comment">/*      Compute stepping increment.                                     */</font>
00170 <font class="comment">/* -------------------------------------------------------------------- */</font>
00171     <font class="keywordtype">double</font>      dfSrcX, dfSrcY, dfSrcXInc, dfSrcYInc;
00172     <font class="keywordtype">int</font>         iSrcX;
00173     
00174     dfSrcXInc = nXSize / (<font class="keywordtype">double</font>) nBufXSize;
00175     dfSrcYInc = nYSize / (<font class="keywordtype">double</font>) nBufYSize;
00176 
00177 <font class="comment">/* -------------------------------------------------------------------- */</font>
00178 <font class="comment">/*      Loop over buffer computing source locations.                    */</font>
00179 <font class="comment">/* -------------------------------------------------------------------- */</font>
00180     <font class="keywordflow">for</font>( iBufYOff = 0; iBufYOff &lt; nBufYSize; iBufYOff++ )
00181     {
00182         <font class="keywordtype">int</font>     iBufOffset, iSrcOffset;
00183         
00184         dfSrcY = (iBufYOff+0.5) * dfSrcYInc + nYOff;
00185         iSrcY = (<font class="keywordtype">int</font>) dfSrcY;
00186 
00187         iBufOffset = iBufYOff * nLineSpace;
00188         
00189         <font class="keywordflow">for</font>( iBufXOff = 0; iBufXOff &lt; nBufXSize; iBufXOff++ )
00190         {
00191             dfSrcX = (iBufXOff+0.5) * dfSrcXInc + nXOff;
00192             
00193             iSrcX = (<font class="keywordtype">int</font>) dfSrcX;
00194 
00195 <font class="comment">/* -------------------------------------------------------------------- */</font>
00196 <font class="comment">/*      Ensure we have the appropriate block loaded.                    */</font>
00197 <font class="comment">/* -------------------------------------------------------------------- */</font>
00198             <font class="keywordflow">if</font>( iSrcX &lt; nLBlockX * nBlockXSize
00199                 || iSrcX &gt;= (nLBlockX+1) * nBlockXSize
00200                 || iSrcY &lt; nLBlockY * nBlockYSize
00201                 || iSrcY &gt;= (nLBlockY+1) * nBlockYSize )
00202             {
00203                 nLBlockX = iSrcX / nBlockXSize;
00204                 nLBlockY = iSrcY / nBlockYSize;
00205 
00206                 poBlock = <a class="code" href="class_GDALRasterBand.html#a11">GetBlockRef</a>( nLBlockX, nLBlockY );
00207                 <font class="keywordflow">if</font>( poBlock == NULL )
00208                 {
00209                     <font class="keywordflow">return</font>( CE_Failure );
00210                 }
00211 
00212                 <font class="keywordflow">if</font>( eRWFlag == GF_Write )
00213                     poBlock-&gt;MarkDirty();
00214                 
00215                 pabySrcBlock = (GByte *) poBlock-&gt;GetDataRef();
00216                 <font class="keywordflow">if</font>( pabySrcBlock == NULL )
00217                     <font class="keywordflow">return</font> CE_Failure;
00218             }
00219 
00220 <font class="comment">/* -------------------------------------------------------------------- */</font>
00221 <font class="comment">/*      Copy over this pixel of data.                                   */</font>
00222 <font class="comment">/* -------------------------------------------------------------------- */</font>
00223             iSrcOffset = (iSrcX - nLBlockX*nBlockXSize
00224                 + (iSrcY - nLBlockY*nBlockYSize) * nBlockXSize)*nBandDataSize;
00225 
00226             <font class="keywordflow">if</font>( eDataType == eBufType )
00227             {
00228                 <font class="keywordflow">if</font>( eRWFlag == GF_Read )
00229                     memcpy( ((GByte *) pData) + iBufOffset,
00230                             pabySrcBlock + iSrcOffset, nBandDataSize );
00231                 <font class="keywordflow">else</font>
00232                     memcpy( pabySrcBlock + iSrcOffset, 
00233                             ((GByte *) pData) + iBufOffset, nBandDataSize );
00234             }
00235             <font class="keywordflow">else</font>
00236             {
00237                 <font class="comment">/* type to type conversion ... ouch, this is expensive way</font>
00238 <font class="comment">                   of handling single words */</font>
00239                 
00240                 <font class="keywordflow">if</font>( eRWFlag == GF_Read )
00241                     GDALCopyWords( pabySrcBlock + iSrcOffset, eDataType, 0,
00242                                    ((GByte *) pData) + iBufOffset, eBufType, 0,
00243                                    1 );
00244                 <font class="keywordflow">else</font>
00245                     GDALCopyWords( ((GByte *) pData) + iBufOffset, eBufType, 0,
00246                                    pabySrcBlock + iSrcOffset, eDataType, 0,
00247                                    1 );
00248             }
00249 
00250             iBufOffset += nPixelSpace;
00251         }
00252     }
00253 
00254     <font class="keywordflow">return</font>( CE_None );
00255 }
00256 
00257 <font class="comment">/************************************************************************/</font>
00258 <font class="comment">/*                           GDALSwapWords()                            */</font>
00259 <font class="comment">/************************************************************************/</font>
00260 
00261 <font class="keywordtype">void</font> GDALSwapWords( <font class="keywordtype">void</font> *pData, <font class="keywordtype">int</font> nWordSize, <font class="keywordtype">int</font> nWordCount,
00262                     <font class="keywordtype">int</font> nWordSkip )<font class="keyword"></font>
00263 <font class="keyword"></font>
00264 <font class="keyword"></font>{
00265     <font class="keywordtype">int</font>         i;
00266     GByte       *pabyData = (GByte *) pData;
00267 
00268     <font class="keywordflow">switch</font>( nWordSize )
00269     {
00270       <font class="keywordflow">case</font> 1:
00271         <font class="keywordflow">break</font>;
00272 
00273       <font class="keywordflow">case</font> 2:
00274         CPLAssert( nWordSize &gt;= 2 );
00275         <font class="keywordflow">for</font>( i = 0; i &lt; nWordCount; i++ )
00276         {
00277             GByte       byTemp;
00278 
00279             byTemp = pabyData[0];
00280             pabyData[0] = pabyData[1];
00281             pabyData[1] = byTemp;
00282 
00283             pabyData += nWordSkip;
00284         }
00285         <font class="keywordflow">break</font>;
00286         
00287       <font class="keywordflow">case</font> 4:
00288         CPLAssert( nWordSize &gt;= 4 );
00289         <font class="keywordflow">for</font>( i = 0; i &lt; nWordCount; i++ )
00290         {
00291             GByte       byTemp;
00292 
00293             byTemp = pabyData[0];
00294             pabyData[0] = pabyData[3];
00295             pabyData[3] = byTemp;
00296 
00297             byTemp = pabyData[1];
00298             pabyData[1] = pabyData[2];
00299             pabyData[2] = byTemp;
00300 
00301             pabyData += nWordSkip;
00302         }
00303         <font class="keywordflow">break</font>;
00304 
00305       <font class="keywordflow">case</font> 8:
00306         CPLAssert( nWordSize &gt;= 8 );
00307         <font class="keywordflow">for</font>( i = 0; i &lt; nWordCount; i++ )
00308         {
00309             GByte       byTemp;
00310 
00311             byTemp = pabyData[0];
00312             pabyData[0] = pabyData[7];
00313             pabyData[7] = byTemp;
00314 
00315             byTemp = pabyData[1];
00316             pabyData[1] = pabyData[6];
00317             pabyData[6] = byTemp;
00318 
00319             byTemp = pabyData[2];
00320             pabyData[2] = pabyData[5];
00321             pabyData[5] = byTemp;
00322 
00323             byTemp = pabyData[3];
00324             pabyData[3] = pabyData[4];
00325             pabyData[4] = byTemp;
00326 
00327             pabyData += nWordSkip;
00328         }
00329         <font class="keywordflow">break</font>;
00330 
00331       <font class="keywordflow">default</font>:
00332         CPLAssert( FALSE );
00333     }
00334 }
00335 
00336 <font class="comment">/************************************************************************/</font>
00337 <font class="comment">/*                           GDALCopyWords()                            */</font>
00338 <font class="comment">/************************************************************************/</font>
00339 
00340 <font class="keywordtype">void</font> 
00341 GDALCopyWords( <font class="keywordtype">void</font> * pSrcData, GDALDataType eSrcType, <font class="keywordtype">int</font> nSrcPixelOffset,
00342                <font class="keywordtype">void</font> * pDstData, GDALDataType eDstType, <font class="keywordtype">int</font> nDstPixelOffset,
00343                <font class="keywordtype">int</font> nWordCount )<font class="keyword"></font>
00344 <font class="keyword"></font>
00345 <font class="keyword"></font>{
00346 <font class="comment">/* -------------------------------------------------------------------- */</font>
00347 <font class="comment">/*      Special case when no data type translation is required.         */</font>
00348 <font class="comment">/* -------------------------------------------------------------------- */</font>
00349     <font class="keywordflow">if</font>( eSrcType == eDstType )
00350     {
00351         <font class="keywordtype">int</font>     nWordSize = GDALGetDataTypeSize(eSrcType)/8;
00352         <font class="keywordtype">int</font>     i;
00353 
00354         <font class="comment">// contiguous blocks.</font>
00355         <font class="keywordflow">if</font>( nWordSize == nSrcPixelOffset &amp;&amp; nWordSize == nDstPixelOffset )
00356         {
00357             memcpy( pDstData, pSrcData, nSrcPixelOffset * nWordCount );
00358             <font class="keywordflow">return</font>;
00359         }
00360 
00361         <font class="comment">// source or destination is not contiguous</font>
00362         <font class="keywordflow">for</font>( i = 0; i &lt; nWordCount; i++ )
00363         {
00364             memcpy( ((GByte *)pDstData) + i * nDstPixelOffset,
00365                     ((GByte *)pSrcData) + i * nSrcPixelOffset,
00366                     nWordSize );
00367         }
00368 
00369         <font class="keywordflow">return</font>;
00370     }
00371 
00372 <font class="comment">/* ==================================================================== */</font>
00373 <font class="comment">/*      General translation case                                        */</font>
00374 <font class="comment">/* ==================================================================== */</font>
00375     <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iWord = 0; iWord &lt; nWordCount; iWord++ )
00376     {
00377         GByte   *pabySrcWord, *pabyDstWord;
00378         <font class="keywordtype">double</font>  dfPixelValue, dfPixelValueI=0.0;
00379 
00380         pabySrcWord = ((GByte *) pSrcData) + iWord * nSrcPixelOffset;
00381 
00382 <font class="comment">/* -------------------------------------------------------------------- */</font>
00383 <font class="comment">/*      Fetch source value based on data type.                          */</font>
00384 <font class="comment">/* -------------------------------------------------------------------- */</font>
00385         <font class="keywordflow">switch</font>( eSrcType )
00386         {
00387           <font class="keywordflow">case</font> GDT_Byte:
00388             dfPixelValue = *pabySrcWord;
00389             <font class="keywordflow">break</font>;
00390 
00391           <font class="keywordflow">case</font> GDT_UInt16:
00392           {
00393               GUInt16   nVal;
00394 
00395               memcpy( &amp;nVal, pabySrcWord, 2 );
00396               dfPixelValue = nVal;
00397           }
00398           <font class="keywordflow">break</font>;
00399           
00400           <font class="keywordflow">case</font> GDT_Int16:
00401           {
00402               GInt16    nVal;
00403 
00404               memcpy( &amp;nVal, pabySrcWord, 2 );
00405               dfPixelValue = nVal;
00406           }
00407           <font class="keywordflow">break</font>;
00408           
00409           <font class="keywordflow">case</font> GDT_Int32:
00410           {
00411               GInt32    nVal;
00412 
00413               memcpy( &amp;nVal, pabySrcWord, 4 );
00414               dfPixelValue = nVal;
00415           }
00416           <font class="keywordflow">break</font>;
00417           
00418           <font class="keywordflow">case</font> GDT_UInt32:
00419           {
00420               GUInt32   nVal;
00421 
00422               memcpy( &amp;nVal, pabySrcWord, 4 );
00423               dfPixelValue = nVal;
00424           }
00425           <font class="keywordflow">break</font>;
00426           
00427           <font class="keywordflow">case</font> GDT_Float32:
00428           {
00429               <font class="keywordtype">float</font>     fVal;
00430 
00431               memcpy( &amp;fVal, pabySrcWord, 4 );
00432               dfPixelValue = fVal;
00433           }
00434           <font class="keywordflow">break</font>;
00435           
00436           <font class="keywordflow">case</font> GDT_Float64:
00437           {
00438               memcpy( &amp;dfPixelValue, pabySrcWord, 8 );
00439           }
00440           <font class="keywordflow">break</font>;
00441 
00442           <font class="keywordflow">case</font> GDT_CInt16:
00443           {
00444               GInt16    nVal;
00445 
00446               memcpy( &amp;nVal, pabySrcWord, 2 );
00447               dfPixelValue = nVal;
00448               memcpy( &amp;nVal, pabySrcWord+2, 2 );
00449               dfPixelValueI = nVal;
00450           }
00451           <font class="keywordflow">break</font>;
00452           
00453           <font class="keywordflow">case</font> GDT_CInt32:
00454           {
00455               GInt32    nVal;
00456 
00457               memcpy( &amp;nVal, pabySrcWord, 4 );
00458               dfPixelValue = nVal;
00459               memcpy( &amp;nVal, pabySrcWord+4, 4 );
00460               dfPixelValueI = nVal;
00461           }
00462           <font class="keywordflow">break</font>;
00463           
00464           <font class="keywordflow">case</font> GDT_CFloat32:
00465           {
00466               <font class="keywordtype">float</font>     fVal;
00467 
00468               memcpy( &amp;fVal, pabySrcWord, 4 );
00469               dfPixelValue = fVal;
00470               memcpy( &amp;fVal, pabySrcWord+4, 4 );
00471               dfPixelValueI = fVal;
00472           }
00473           <font class="keywordflow">break</font>;
00474           
00475           <font class="keywordflow">case</font> GDT_CFloat64:
00476           {
00477               memcpy( &amp;dfPixelValue, pabySrcWord, 8 );
00478               memcpy( &amp;dfPixelValueI, pabySrcWord+8, 8 );
00479           }
00480           <font class="keywordflow">break</font>;
00481 
00482           <font class="keywordflow">default</font>:
00483             CPLAssert( FALSE );
00484         }
00485         
00486 <font class="comment">/* -------------------------------------------------------------------- */</font>
00487 <font class="comment">/*      Set the destination pixel, doing range clipping as needed.      */</font>
00488 <font class="comment">/* -------------------------------------------------------------------- */</font>
00489         pabyDstWord = ((GByte *) pDstData) + iWord * nDstPixelOffset;
00490         <font class="keywordflow">switch</font>( eDstType )
00491         {
00492           <font class="keywordflow">case</font> GDT_Byte:
00493           {
00494               <font class="keywordflow">if</font>( dfPixelValue &lt; 0.0 )
00495                   *pabyDstWord = 0;
00496               <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dfPixelValue &gt; 255.0 )
00497                   *pabyDstWord = 255;
00498               <font class="keywordflow">else</font>
00499                   *pabyDstWord = (GByte) dfPixelValue;
00500           }
00501           <font class="keywordflow">break</font>;
00502 
00503           <font class="keywordflow">case</font> GDT_UInt16:
00504           {
00505               GUInt16   nVal;
00506               
00507               <font class="keywordflow">if</font>( dfPixelValue &lt; 0.0 )
00508                   nVal = 0;
00509               <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dfPixelValue &gt; 65535.0 )
00510                   nVal = 65535;
00511               <font class="keywordflow">else</font>
00512                   nVal = (GUInt16) dfPixelValue;
00513 
00514               memcpy( pabyDstWord, &amp;nVal, 2 );
00515           }
00516           <font class="keywordflow">break</font>;
00517 
00518           <font class="keywordflow">case</font> GDT_Int16:
00519           {
00520               GInt16    nVal;
00521               
00522               <font class="keywordflow">if</font>( dfPixelValue &lt; -32768 )
00523                   nVal = -32768;
00524               <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dfPixelValue &gt; 32767 )
00525                   nVal = 32767;
00526               <font class="keywordflow">else</font>
00527                   nVal = (GInt16) dfPixelValue;
00528 
00529               memcpy( pabyDstWord, &amp;nVal, 2 );
00530           }
00531           <font class="keywordflow">break</font>;
00532           
00533           <font class="keywordflow">case</font> GDT_UInt32:
00534           {
00535               GUInt32   nVal;
00536               
00537               <font class="keywordflow">if</font>( dfPixelValue &lt; 0 )
00538                   nVal = 0;
00539               <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dfPixelValue &gt; 4294967295U )
00540                   nVal = 4294967295U;
00541               <font class="keywordflow">else</font>
00542                   nVal = (GInt32) dfPixelValue;
00543 
00544               memcpy( pabyDstWord, &amp;nVal, 4 );
00545           }
00546           <font class="keywordflow">break</font>;
00547           
00548           <font class="keywordflow">case</font> GDT_Int32:
00549           {
00550               GInt32    nVal;
00551               
00552               <font class="keywordflow">if</font>( dfPixelValue &lt; -2147483647.0 )
00553                   nVal = -2147483647;
00554               <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dfPixelValue &gt; 2147483647 )
00555                   nVal = 2147483647;
00556               <font class="keywordflow">else</font>
00557                   nVal = (GInt32) dfPixelValue;
00558 
00559               memcpy( pabyDstWord, &amp;nVal, 4 );
00560           }
00561           <font class="keywordflow">break</font>;
00562 
00563           <font class="keywordflow">case</font> GDT_Float32:
00564           {
00565               <font class="keywordtype">float</font>     fVal;
00566 
00567               fVal = dfPixelValue;
00568 
00569               memcpy( pabyDstWord, &amp;fVal, 4 );
00570           }
00571           <font class="keywordflow">break</font>;
00572 
00573           <font class="keywordflow">case</font> GDT_Float64:
00574               memcpy( pabyDstWord, &amp;dfPixelValue, 8 );
00575               <font class="keywordflow">break</font>;
00576               
00577           <font class="keywordflow">case</font> GDT_CInt16:
00578           {
00579               GInt16    nVal;
00580               
00581               <font class="keywordflow">if</font>( dfPixelValue &lt; -32768 )
00582                   nVal = -32768;
00583               <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dfPixelValue &gt; 32767 )
00584                   nVal = 32767;
00585               <font class="keywordflow">else</font>
00586                   nVal = (GInt16) dfPixelValue;
00587               memcpy( pabyDstWord, &amp;nVal, 2 );
00588 
00589               <font class="keywordflow">if</font>( dfPixelValueI &lt; -32768 )
00590                   nVal = -32768;
00591               <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dfPixelValueI &gt; 32767 )
00592                   nVal = 32767;
00593               <font class="keywordflow">else</font>
00594                   nVal = (GInt16) dfPixelValueI;
00595               memcpy( pabyDstWord+2, &amp;nVal, 2 );
00596           }
00597           <font class="keywordflow">break</font>;
00598           
00599           <font class="keywordflow">case</font> GDT_CInt32:
00600           {
00601               GInt32    nVal;
00602               
00603               <font class="keywordflow">if</font>( dfPixelValue &lt; -2147483647.0 )
00604                   nVal = -2147483647;
00605               <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dfPixelValue &gt; 2147483647 )
00606                   nVal = 2147483647;
00607               <font class="keywordflow">else</font>
00608                   nVal = (GInt32) dfPixelValue;
00609 
00610               memcpy( pabyDstWord, &amp;nVal, 4 );
00611 
00612               <font class="keywordflow">if</font>( dfPixelValueI &lt; -2147483647.0 )
00613                   nVal = -2147483647;
00614               <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dfPixelValueI &gt; 2147483647 )
00615                   nVal = 2147483647;
00616               <font class="keywordflow">else</font>
00617                   nVal = (GInt32) dfPixelValueI;
00618 
00619               memcpy( pabyDstWord+4, &amp;nVal, 4 );
00620           }
00621           <font class="keywordflow">break</font>;
00622 
00623           <font class="keywordflow">case</font> GDT_CFloat32:
00624           {
00625               <font class="keywordtype">float</font>     fVal;
00626 
00627               fVal = dfPixelValue;
00628               memcpy( pabyDstWord, &amp;fVal, 4 );
00629               fVal = dfPixelValueI;
00630               memcpy( pabyDstWord+4, &amp;fVal, 4 );
00631           }
00632           <font class="keywordflow">break</font>;
00633 
00634           <font class="keywordflow">case</font> GDT_CFloat64:
00635               memcpy( pabyDstWord, &amp;dfPixelValue, 8 );
00636               memcpy( pabyDstWord+8, &amp;dfPixelValueI, 8 );
00637               <font class="keywordflow">break</font>;
00638               
00639           <font class="keywordflow">default</font>:
00640             CPLAssert( FALSE );
00641         }
00642     } <font class="comment">/* next iWord */</font>
00643 }
00644 
00645 <font class="comment">/************************************************************************/</font>
00646 <font class="comment">/*                          OverviewRasterIO()                          */</font>
00647 <font class="comment">/*                                                                      */</font>
00648 <font class="comment">/*      Special work function to utilize available overviews to         */</font>
00649 <font class="comment">/*      more efficiently satisfy downsampled requests.  It will         */</font>
00650 <font class="comment">/*      return CE_Failure if there are no appropriate overviews         */</font>
00651 <font class="comment">/*      available but it doesn't emit any error messages.               */</font>
00652 <font class="comment">/************************************************************************/</font>
00653 
00654 CPLErr GDALRasterBand::OverviewRasterIO( GDALRWFlag eRWFlag,
00655                                 <font class="keywordtype">int</font> nXOff, <font class="keywordtype">int</font> nYOff, <font class="keywordtype">int</font> nXSize, <font class="keywordtype">int</font> nYSize,
00656                                 <font class="keywordtype">void</font> * pData, <font class="keywordtype">int</font> nBufXSize, <font class="keywordtype">int</font> nBufYSize,
00657                                 GDALDataType eBufType,
00658                                 <font class="keywordtype">int</font> nPixelSpace, <font class="keywordtype">int</font> nLineSpace )<font class="keyword"></font>
00659 <font class="keyword"></font>
00660 <font class="keyword"></font>
00661 <font class="keyword"></font>{
00662     <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a>      *poBestOverview = NULL;
00663     <font class="keywordtype">int</font>                 nOverviewCount = <a class="code" href="class_GDALRasterBand.html#a28">GetOverviewCount</a>();
00664     <font class="keywordtype">double</font>              dfDesiredResolution, dfBestResolution = 1.0;
00665 
00666 <font class="comment">/* -------------------------------------------------------------------- */</font>
00667 <font class="comment">/*      Find the Compute the desired resolution.  The resolution is     */</font>
00668 <font class="comment">/*      based on the least reduced axis, and represents the number      */</font>
00669 <font class="comment">/*      of source pixels to one destination pixel.                      */</font>
00670 <font class="comment">/* -------------------------------------------------------------------- */</font>
00671     <font class="keywordflow">if</font>( (nXSize / (<font class="keywordtype">double</font>) nBufXSize) &lt; (nYSize / (<font class="keywordtype">double</font>) nBufYSize ) 
00672         || nBufYSize == 1 )
00673         dfDesiredResolution = nXSize / (<font class="keywordtype">double</font>) nBufXSize;
00674     <font class="keywordflow">else</font>
00675         dfDesiredResolution = nYSize / (<font class="keywordtype">double</font>) nBufYSize;
00676 
00677 <font class="comment">/* -------------------------------------------------------------------- */</font>
00678 <font class="comment">/*      Find the overview level that largest resolution value (most     */</font>
00679 <font class="comment">/*      downsampled) that is still less than (or only a little more)    */</font>
00680 <font class="comment">/*      downsampled than the request.                                   */</font>
00681 <font class="comment">/* -------------------------------------------------------------------- */</font>
00682     <font class="keywordflow">for</font>( <font class="keywordtype">int</font> iOverview = 0; iOverview &lt; nOverviewCount; iOverview++ )
00683     {
00684         <a class="code" href="class_GDALRasterBand.html">GDALRasterBand</a>  *poOverview = <a class="code" href="class_GDALRasterBand.html#a29">GetOverview</a>( iOverview );
00685         <font class="keywordtype">double</font>          dfResolution;
00686 
00687         <font class="keywordflow">if</font>( (<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() / (<font class="keywordtype">double</font>) poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>())
00688             &lt; (<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() / (<font class="keywordtype">double</font>) poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>()) )
00689             dfResolution = 
00690                 <a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() / (<font class="keywordtype">double</font>) poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>();
00691         <font class="keywordflow">else</font>
00692             dfResolution = 
00693                 <a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() / (<font class="keywordtype">double</font>) poOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>();
00694 
00695         <font class="keywordflow">if</font>( dfResolution &lt; dfDesiredResolution * 1.2 
00696             &amp;&amp; dfResolution &gt; dfBestResolution )
00697         {
00698             poBestOverview = poOverview;
00699             dfBestResolution = dfResolution;
00700         }
00701     }
00702 
00703 <font class="comment">/* -------------------------------------------------------------------- */</font>
00704 <font class="comment">/*      If we didn't find an overview that helps us, just return        */</font>
00705 <font class="comment">/*      indicating failure and the full resolution image will be used.  */</font>
00706 <font class="comment">/* -------------------------------------------------------------------- */</font>
00707     <font class="keywordflow">if</font>( poBestOverview == NULL )
00708         <font class="keywordflow">return</font> CE_Failure;
00709 
00710 <font class="comment">/* -------------------------------------------------------------------- */</font>
00711 <font class="comment">/*      Recompute the source window in terms of the selected            */</font>
00712 <font class="comment">/*      overview.                                                       */</font>
00713 <font class="comment">/* -------------------------------------------------------------------- */</font>
00714     <font class="keywordtype">int</font>         nOXOff, nOYOff, nOXSize, nOYSize;
00715     <font class="keywordtype">double</font>      dfXRes, dfYRes;
00716     
00717     dfXRes = <a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() / (<font class="keywordtype">double</font>) poBestOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>();
00718     dfYRes = <a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() / (<font class="keywordtype">double</font>) poBestOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>();
00719 
00720     nOXOff = MIN(poBestOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>()-1,(<font class="keywordtype">int</font>) (nXOff/dfXRes+0.5));
00721     nOYOff = MIN(poBestOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>()-1,(<font class="keywordtype">int</font>) (nYOff/dfYRes+0.5));
00722     nOXSize = MAX(1,(<font class="keywordtype">int</font>) (nXSize/dfXRes + 0.5));
00723     nOYSize = MAX(1,(<font class="keywordtype">int</font>) (nYSize/dfYRes + 0.5));
00724     <font class="keywordflow">if</font>( nOXOff + nOXSize &gt; poBestOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() )
00725         nOXSize = poBestOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a2">GetXSize</a>() - nOXOff;
00726     <font class="keywordflow">if</font>( nOYOff + nOYSize &gt; poBestOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() )
00727         nOYSize = poBestOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a3">GetYSize</a>() - nOYOff;
00728 
00729 <font class="comment">/* -------------------------------------------------------------------- */</font>
00730 <font class="comment">/*      Recast the call in terms of the new raster layer.               */</font>
00731 <font class="comment">/* -------------------------------------------------------------------- */</font>
00732     <font class="keywordflow">return</font> poBestOverview-&gt;<a class="code" href="class_GDALRasterBand.html#a8">RasterIO</a>( eRWFlag, nOXOff, nOYOff, nOXSize, nOYSize,
00733                                      pData, nBufXSize, nBufYSize, eBufType,
00734                                      nPixelSpace, nLineSpace );
00735 }
00736 
</div></pre><hr><address><small>Generated at Thu Mar 28 09:47:31 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>