LCOV - code coverage report
Current view: top level - frmts/pcidsk/sdk/segment - systiledir.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 41 47 87.2 %
Date: 2024-04-27 17:22:41 Functions: 9 11 81.8 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Purpose:  Declaration of the SysTileDir class.
       4             :  *
       5             :  * This class is used to manage access to the system block tile directory.
       6             :  * This segment is used to keep track of one or more tile layers stored in
       7             :  * system block data segments. These tile layers are used to hold tiled images
       8             :  * for primary bands or overviews.
       9             :  *
      10             :  * This class is closely partnered with the CTiledChannel class.
      11             :  *
      12             :  ******************************************************************************
      13             :  * Copyright (c) 2009
      14             :  * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada.
      15             :  *
      16             :  * Permission is hereby granted, free of charge, to any person obtaining a
      17             :  * copy of this software and associated documentation files (the "Software"),
      18             :  * to deal in the Software without restriction, including without limitation
      19             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      20             :  * and/or sell copies of the Software, and to permit persons to whom the
      21             :  * Software is furnished to do so, subject to the following conditions:
      22             :  *
      23             :  * The above copyright notice and this permission notice shall be included
      24             :  * in all copies or substantial portions of the Software.
      25             :  *
      26             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      27             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      28             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      29             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      30             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      31             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      32             :  * DEALINGS IN THE SOFTWARE.
      33             :  ****************************************************************************/
      34             : 
      35             : #include "segment/systiledir.h"
      36             : #include "blockdir/asciitiledir.h"
      37             : #include "blockdir/binarytiledir.h"
      38             : #include "blockdir/blocktilelayer.h"
      39             : #include "core/cpcidskblockfile.h"
      40             : #include "pcidsk_exception.h"
      41             : 
      42             : using namespace PCIDSK;
      43             : 
      44             : /************************************************************************/
      45             : /*                               SysTileDir()                           */
      46             : /************************************************************************/
      47          32 : SysTileDir::SysTileDir(PCIDSKFile * poFile, int nSegment,
      48          32 :                        const char * pbySegmentData)
      49          32 :     : CPCIDSKSegment(poFile, nSegment, pbySegmentData)
      50             : {
      51          32 :     mpoTileDir = nullptr;
      52          32 : }
      53             : 
      54             : /************************************************************************/
      55             : /*                              ~SysTileDir()                           */
      56             : /************************************************************************/
      57          64 : SysTileDir::~SysTileDir(void)
      58             : {
      59             :     try
      60             :     {
      61          32 :         Synchronize();
      62             :     }
      63           0 :     catch( const PCIDSKException& )
      64             :     {
      65             :         // TODO ?
      66             :     }
      67          32 :     delete mpoTileDir;
      68          64 : }
      69             : 
      70             : /************************************************************************/
      71             : /*                               Initialize()                           */
      72             : /************************************************************************/
      73           8 : void SysTileDir::Initialize(void)
      74             : {
      75           8 : }
      76             : 
      77             : /************************************************************************/
      78             : /*                            Synchronize()                             */
      79             : /************************************************************************/
      80          50 : void SysTileDir::Synchronize(void)
      81             : {
      82          50 :     if (mpoTileDir)
      83          50 :         mpoTileDir->Sync();
      84          50 : }
      85             : 
      86             : /************************************************************************/
      87             : /*                              LoadTileDir()                           */
      88             : /************************************************************************/
      89          44 : void SysTileDir::LoadTileDir(void)
      90             : {
      91          44 :     if (mpoTileDir)
      92          20 :         return;
      93             : 
      94          24 :     CPCIDSKBlockFile * poBlockFile = new CPCIDSKBlockFile(file);
      95             : 
      96          24 :     if (segment_name == "SysBMDir")
      97             :     {
      98          11 :         mpoTileDir = new AsciiTileDir(poBlockFile, (uint16) segment);
      99             :     }
     100          13 :     else if (segment_name == "TileDir")
     101             :     {
     102          13 :         mpoTileDir = new BinaryTileDir(poBlockFile, (uint16) segment);
     103             :     }
     104             :     else
     105             :     {
     106           0 :         delete poBlockFile;
     107           0 :         return ThrowPCIDSKException("Unknown block tile directory name.");
     108             :     }
     109             : }
     110             : 
     111             : /************************************************************************/
     112             : /*                             CreateTileDir()                          */
     113             : /************************************************************************/
     114           8 : void SysTileDir::CreateTileDir(void)
     115             : {
     116           8 :     CPCIDSKBlockFile * poBlockFile = new CPCIDSKBlockFile(file);
     117             : 
     118           8 :     if (segment_name == "SysBMDir")
     119             :     {
     120           2 :         mpoTileDir = new AsciiTileDir(poBlockFile, (uint16) segment, 8192);
     121             :     }
     122           6 :     else if (segment_name == "TileDir")
     123             :     {
     124           6 :         uint32 nBlockSize = BinaryTileDir::GetOptimizedBlockSize(poBlockFile);
     125             : 
     126           6 :         mpoTileDir = new BinaryTileDir(poBlockFile, (uint16) segment,
     127           6 :                                        nBlockSize);
     128             :     }
     129             :     else
     130             :     {
     131           0 :         delete poBlockFile;
     132           0 :         return ThrowPCIDSKException("Unknown block tile directory name.");
     133             :     }
     134             : }
     135             : 
     136             : /************************************************************************/
     137             : /*                              GetTileLayer()                          */
     138             : /************************************************************************/
     139          36 : BlockTileLayer * SysTileDir::GetTileLayer(uint32 nLayer)
     140             : {
     141          36 :     LoadTileDir();
     142             : 
     143          36 :     return mpoTileDir->GetTileLayer(nLayer);
     144             : }
     145             : 
     146             : /************************************************************************/
     147             : /*                            CreateTileLayer()                         */
     148             : /************************************************************************/
     149           8 : uint32 SysTileDir::CreateTileLayer(uint32 nWidth, uint32 nHeight,
     150             :                                    uint32 nTileWidth, uint32 nTileHeight,
     151             :                                    eChanType nDataType, std::string oCompress)
     152             : {
     153           8 :     if (oCompress.empty())
     154           0 :         oCompress = "NONE";
     155             : 
     156           8 :     LoadTileDir();
     157             : 
     158           8 :     uint32 nLayer = mpoTileDir->CreateLayer(BLTImage);
     159             : 
     160           8 :     BlockTileLayer * poTileLayer = mpoTileDir->GetTileLayer(nLayer);
     161             : 
     162           8 :     poTileLayer->SetTileLayerInfo(nWidth, nHeight, nTileWidth, nTileHeight,
     163             :                                   DataTypeName(nDataType), oCompress);
     164             : 
     165           8 :     return nLayer;
     166             : }

Generated by: LCOV version 1.14