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 : * SPDX-License-Identifier: MIT 17 : ****************************************************************************/ 18 : 19 : #include "segment/systiledir.h" 20 : #include "blockdir/asciitiledir.h" 21 : #include "blockdir/binarytiledir.h" 22 : #include "blockdir/blocktilelayer.h" 23 : #include "core/cpcidskblockfile.h" 24 : #include "pcidsk_exception.h" 25 : 26 : using namespace PCIDSK; 27 : 28 : /************************************************************************/ 29 : /* SysTileDir() */ 30 : /************************************************************************/ 31 32 : SysTileDir::SysTileDir(PCIDSKFile * poFile, int nSegment, 32 32 : const char * pbySegmentData) 33 32 : : CPCIDSKSegment(poFile, nSegment, pbySegmentData) 34 : { 35 32 : mpoTileDir = nullptr; 36 32 : } 37 : 38 : /************************************************************************/ 39 : /* ~SysTileDir() */ 40 : /************************************************************************/ 41 64 : SysTileDir::~SysTileDir(void) 42 : { 43 : try 44 : { 45 32 : Synchronize(); 46 : } 47 0 : catch( const PCIDSKException& ) 48 : { 49 : // TODO ? 50 : } 51 32 : delete mpoTileDir; 52 64 : } 53 : 54 : /************************************************************************/ 55 : /* Initialize() */ 56 : /************************************************************************/ 57 8 : void SysTileDir::Initialize(void) 58 : { 59 8 : } 60 : 61 : /************************************************************************/ 62 : /* Synchronize() */ 63 : /************************************************************************/ 64 50 : void SysTileDir::Synchronize(void) 65 : { 66 50 : if (mpoTileDir) 67 50 : mpoTileDir->Sync(); 68 50 : } 69 : 70 : /************************************************************************/ 71 : /* LoadTileDir() */ 72 : /************************************************************************/ 73 44 : void SysTileDir::LoadTileDir(void) 74 : { 75 44 : if (mpoTileDir) 76 20 : return; 77 : 78 24 : CPCIDSKBlockFile * poBlockFile = new CPCIDSKBlockFile(file); 79 : 80 24 : if (segment_name == "SysBMDir") 81 : { 82 11 : mpoTileDir = new AsciiTileDir(poBlockFile, (uint16) segment); 83 : } 84 13 : else if (segment_name == "TileDir") 85 : { 86 13 : mpoTileDir = new BinaryTileDir(poBlockFile, (uint16) segment); 87 : } 88 : else 89 : { 90 0 : delete poBlockFile; 91 0 : return ThrowPCIDSKException("Unknown block tile directory name."); 92 : } 93 : } 94 : 95 : /************************************************************************/ 96 : /* CreateTileDir() */ 97 : /************************************************************************/ 98 8 : void SysTileDir::CreateTileDir(void) 99 : { 100 8 : CPCIDSKBlockFile * poBlockFile = new CPCIDSKBlockFile(file); 101 : 102 8 : if (segment_name == "SysBMDir") 103 : { 104 2 : mpoTileDir = new AsciiTileDir(poBlockFile, (uint16) segment, 8192); 105 : } 106 6 : else if (segment_name == "TileDir") 107 : { 108 6 : uint32 nBlockSize = BinaryTileDir::GetOptimizedBlockSize(poBlockFile); 109 : 110 6 : mpoTileDir = new BinaryTileDir(poBlockFile, (uint16) segment, 111 6 : nBlockSize); 112 : } 113 : else 114 : { 115 0 : delete poBlockFile; 116 0 : return ThrowPCIDSKException("Unknown block tile directory name."); 117 : } 118 : } 119 : 120 : /************************************************************************/ 121 : /* GetTileLayer() */ 122 : /************************************************************************/ 123 36 : BlockTileLayer * SysTileDir::GetTileLayer(uint32 nLayer) 124 : { 125 36 : LoadTileDir(); 126 : 127 36 : return mpoTileDir->GetTileLayer(nLayer); 128 : } 129 : 130 : /************************************************************************/ 131 : /* CreateTileLayer() */ 132 : /************************************************************************/ 133 8 : uint32 SysTileDir::CreateTileLayer(uint32 nWidth, uint32 nHeight, 134 : uint32 nTileWidth, uint32 nTileHeight, 135 : eChanType nDataType, std::string oCompress) 136 : { 137 8 : if (oCompress.empty()) 138 0 : oCompress = "NONE"; 139 : 140 8 : LoadTileDir(); 141 : 142 8 : uint32 nLayer = mpoTileDir->CreateLayer(BLTImage); 143 : 144 8 : BlockTileLayer * poTileLayer = mpoTileDir->GetTileLayer(nLayer); 145 : 146 8 : poTileLayer->SetTileLayerInfo(nWidth, nHeight, nTileWidth, nTileHeight, 147 : DataTypeName(nDataType), oCompress); 148 : 149 8 : return nLayer; 150 : }