1 /******************************************************************************
2  *
3  * Purpose:  Declaration of the CExternalChannel class.
4  *
5  * This class is used to implement band interleaved channels that are
6  * references to an external image database that is not just a raw file.
7  * It uses the application supplied EDB interface to access non-PCIDSK files.
8  *
9  ******************************************************************************
10  * Copyright (c) 2010
11  * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada.
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included
21  * in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  ****************************************************************************/
31 
32 #ifndef INCLUDE_CHANNEL_CEXTERNALCHANNEL_H
33 #define INCLUDE_CHANNEL_CEXTERNALCHANNEL_H
34 
35 #include "pcidsk_config.h"
36 #include "pcidsk_types.h"
37 #include "pcidsk_buffer.h"
38 #include "channel/cpcidskchannel.h"
39 #include <string>
40 
41 namespace PCIDSK
42 {
43     class CPCIDSKFile;
44 
45 /************************************************************************/
46 /*                           CExternalChannel                           */
47 /************************************************************************/
48 
49     class CExternalChannel : public CPCIDSKChannel
50     {
51     public:
52         CExternalChannel( PCIDSKBuffer &image_header,
53             uint64 ih_offset,
54             PCIDSKBuffer &file_header,
55             std::string filename,
56             int channelnum,
57             CPCIDSKFile *file,
58             eChanType pixel_type );
59         virtual ~CExternalChannel();
60 
61         virtual eChanType GetType() const override;
62         virtual int GetBlockWidth() const override;
63         virtual int GetBlockHeight() const override;
64         virtual int ReadBlock( int block_index, void *buffer,
65             int xoff=-1, int yoff=-1,
66             int xsize=-1, int ysize=-1 ) override;
67         virtual int WriteBlock( int block_index, void *buffer ) override;
68 
69         virtual void GetEChanInfo( std::string &filename, int &echannel,
70                                    int &exoff, int &eyoff,
71                                    int &exsize, int &eysize ) const override;
72         virtual void SetEChanInfo( std::string filename, int echannel,
73                                    int exoff, int eyoff,
74                                    int exsize, int eysize ) override;
75 
GetExternalFilename()76         std::string GetExternalFilename(){return filename;}
GetExternalChanNum()77         int         GetExternalChanNum(){return echannel;}
78 
79     private:
80         int      exoff;
81         int      eyoff;
82         int      exsize;
83         int      eysize;
84 
85         int      echannel;
86 
87         mutable int blocks_per_row;
88 
89         mutable EDBFile  *db;
90         mutable Mutex    *mutex;
91         mutable bool     writable;
92 
93         void     AccessDB() const;
94 
95         mutable std::string filename;
96     };
97 } // end namespace PCIDSK
98 
99 #endif // INCLUDE_CHANNEL_CEXTERNALCHANNEL_H
100