1 : /******************************************************************************
2 : *
3 : * Purpose: Declaration of the CPCIDSKFile class.
4 : *
5 : ******************************************************************************
6 : * Copyright (c) 2009
7 : * PCI Geomatics, 50 West Wilmot Street, Richmond Hill, Ont, Canada
8 : *
9 : * Permission is hereby granted, free of charge, to any person obtaining a
10 : * copy of this software and associated documentation files (the "Software"),
11 : * to deal in the Software without restriction, including without limitation
12 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 : * and/or sell copies of the Software, and to permit persons to whom the
14 : * Software is furnished to do so, subject to the following conditions:
15 : *
16 : * The above copyright notice and this permission notice shall be included
17 : * in all copies or substantial portions of the Software.
18 : *
19 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 : * DEALINGS IN THE SOFTWARE.
26 : ****************************************************************************/
27 : #ifndef __INCLUDE_PRIV_CPCIDSKFILE_H
28 : #define __INCLUDE_PRIV_CPCIDSKFILE_H
29 :
30 : #include "pcidsk_config.h"
31 : #include "pcidsk_types.h"
32 : #include "pcidsk_buffer.h"
33 : #include "pcidsk_file.h"
34 : #include "pcidsk_mutex.h"
35 : #include "pcidsk_interfaces.h"
36 : #include "core/metadataset.h"
37 : #include "core/protectedfile.h"
38 :
39 : #include <string>
40 : #include <vector>
41 :
42 : namespace PCIDSK
43 : {
44 : class PCIDSKChannel;
45 : class PCIDSKSegment;
46 : class PCIDSKInterfaces;
47 : /************************************************************************/
48 : /* CPCIDSKFile */
49 : /************************************************************************/
50 : class CPCIDSKFile : public PCIDSKFile
51 : {
52 : friend PCIDSKFile PCIDSK_DLL *Open( std::string filename,
53 : std::string access, const PCIDSKInterfaces *interfaces );
54 : public:
55 :
56 : CPCIDSKFile();
57 : virtual ~CPCIDSKFile();
58 :
59 398 : virtual PCIDSKInterfaces *GetInterfaces() { return &interfaces; }
60 :
61 : PCIDSKChannel *GetChannel( int band );
62 : PCIDSKSegment *GetSegment( int segment );
63 : std::vector<PCIDSKSegment *> GetSegments();
64 :
65 : PCIDSKSegment *GetSegment( int type, std::string name,
66 : int previous = 0 );
67 : int CreateSegment( std::string name, std::string description,
68 : eSegType seg_type, int data_blocks );
69 : void DeleteSegment( int segment );
70 : void CreateOverviews( int chan_count, int *chan_list,
71 : int factor, std::string resampling );
72 :
73 171 : int GetWidth() const { return width; }
74 171 : int GetHeight() const { return height; }
75 113 : int GetChannels() const { return channel_count; }
76 212 : std::string GetInterleaving() const { return interleaving; }
77 680 : bool GetUpdatable() const { return updatable; }
78 69 : uint64 GetFileSize() const { return file_size; }
79 :
80 : // the following are only for pixel interleaved IO
81 0 : int GetPixelGroupSize() const { return pixel_group_size; }
82 : void *ReadAndLockBlock( int block_index, int xoff=-1, int xsize=-1 );
83 : void UnlockBlock( bool mark_dirty = false );
84 : void WriteBlock( int block_index, void *buffer );
85 : void FlushBlock();
86 :
87 : void WriteToFile( const void *buffer, uint64 offset, uint64 size );
88 : void ReadFromFile( void *buffer, uint64 offset, uint64 size );
89 :
90 : void GetIODetails( void ***io_handle_pp, Mutex ***io_mutex_pp,
91 : std::string filename = "" );
92 :
93 5 : std::string GetMetadataValue( const std::string& key )
94 5 : { return metadata.GetMetadataValue(key); }
95 19 : void SetMetadataValue( const std::string& key, const std::string& value )
96 19 : { metadata.SetMetadataValue(key,value); }
97 2 : std::vector<std::string> GetMetadataKeys()
98 2 : { return metadata.GetMetadataKeys(); }
99 :
100 : // not exposed to applications.
101 : void ExtendFile( uint64 blocks_requested, bool prezero = false );
102 : void ExtendSegment( int segment, uint64 blocks_to_add,
103 : bool prezero = false );
104 : void MoveSegmentToEOF( int segment );
105 :
106 : private:
107 : PCIDSKInterfaces interfaces;
108 :
109 : void InitializeFromHeader();
110 :
111 : int width;
112 : int height;
113 : int channel_count;
114 : std::string interleaving;
115 :
116 : std::vector<PCIDSKChannel*> channels;
117 :
118 : int segment_count;
119 : uint64 segment_pointers_offset;
120 : PCIDSKBuffer segment_pointers;
121 :
122 : std::vector<PCIDSKSegment*> segments;
123 :
124 : // pixel interleaved info.
125 : uint64 block_size; // pixel interleaved scanline size.
126 : int pixel_group_size; // pixel interleaved pixel_offset value.
127 : uint64 first_line_offset;
128 :
129 : int last_block_index;
130 : bool last_block_dirty;
131 : int last_block_xoff;
132 : int last_block_xsize;
133 : void *last_block_data;
134 : Mutex *last_block_mutex;
135 :
136 : void *io_handle;
137 : Mutex *io_mutex;
138 : bool updatable;
139 :
140 : uint64 file_size; // in blocks.
141 :
142 : // register of open external raw files.
143 : std::vector<ProtectedFile> file_list;
144 :
145 : MetadataSet metadata;
146 : };
147 : } // end namespace PCIDSK
148 :
149 : #endif // __INCLUDE_PRIV_CPCIDSKFILE_H
|