Line data Source code
1 : /******************************************************************************
2 : * $Id$
3 : *
4 : * Project: KmlSuperOverlay
5 : * Purpose: Implements write support for KML superoverlay - KMZ.
6 : * Author: Harsh Govind, harsh.govind@spadac.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2010, SPADAC Inc. <harsh.govind@spadac.com>
10 : * Copyright (c) 2012, Even Rouault <even dot rouault at spatialys.com>
11 : *
12 : * SPDX-License-Identifier: MIT
13 : ****************************************************************************/
14 :
15 : #ifndef KMLSUPEROVERLAYDATASET_H_INCLUDED
16 : #define KMLSUPEROVERLAYDATASET_H_INCLUDED
17 :
18 : #include <array>
19 : #include <map>
20 :
21 : #include "cpl_minixml.h"
22 : #include "gdal_pam.h"
23 : #include "gdal_priv.h"
24 :
25 : /************************************************************************/
26 : /* KmlSuperOverlayReadDataset */
27 : /************************************************************************/
28 : class KmlSuperOverlayRasterBand;
29 : class KmlSuperOverlayReadDataset;
30 :
31 : class LinkedDataset;
32 :
33 : class LinkedDataset
34 : {
35 : public:
36 : KmlSuperOverlayReadDataset *poDS = nullptr;
37 : LinkedDataset *psPrev = nullptr;
38 : LinkedDataset *psNext = nullptr;
39 : CPLString osSubFilename{};
40 :
41 12 : LinkedDataset() = default;
42 :
43 : private:
44 : LinkedDataset(const LinkedDataset &) = delete;
45 : LinkedDataset &operator=(const LinkedDataset &) = delete;
46 : };
47 :
48 : class KmlSuperOverlayReadDataset final : public GDALDataset
49 : {
50 : friend class KmlSuperOverlayRasterBand;
51 :
52 : OGRSpatialReference m_oSRS{};
53 : int nFactor = 1;
54 : CPLString osFilename{};
55 : CPLXMLNode *psRoot = nullptr;
56 : CPLXMLNode *psDocument = nullptr;
57 : std::unique_ptr<GDALDataset> poDSIcon{};
58 : std::array<double, 6> adfGeoTransform = {0, 0, 0, 0, 0, 0};
59 :
60 : std::vector<std::unique_ptr<KmlSuperOverlayReadDataset>> m_apoOverviewDS{};
61 : bool bIsOvr = false;
62 :
63 : KmlSuperOverlayReadDataset *poParent = nullptr;
64 :
65 : std::map<CPLString, LinkedDataset *> oMapChildren{};
66 : LinkedDataset *psFirstLink = nullptr;
67 : LinkedDataset *psLastLink = nullptr;
68 :
69 : KmlSuperOverlayReadDataset(const KmlSuperOverlayReadDataset &) = delete;
70 : KmlSuperOverlayReadDataset &
71 : operator=(const KmlSuperOverlayReadDataset &) = delete;
72 :
73 : protected:
74 : virtual int CloseDependentDatasets() override;
75 :
76 : public:
77 : KmlSuperOverlayReadDataset();
78 : virtual ~KmlSuperOverlayReadDataset();
79 :
80 : static int Identify(GDALOpenInfo *);
81 : static GDALDataset *Open(const char *pszFilename,
82 : KmlSuperOverlayReadDataset *poParent = nullptr,
83 : int nRec = 0);
84 : static GDALDataset *Open(GDALOpenInfo *);
85 :
86 : static const int KMLSO_ContainsOpaquePixels = 0x1;
87 : static const int KMLSO_ContainsTransparentPixels = 0x2;
88 : static const int KMLSO_ContainsPartiallyTransparentPixels = 0x4;
89 :
90 : static int DetectTransparency(int rxsize, int rysize, int rx, int ry,
91 : int dxsize, int dysize, GDALDataset *poSrcDs);
92 :
93 : virtual CPLErr GetGeoTransform(double *) override;
94 : const OGRSpatialReference *GetSpatialRef() const override;
95 :
96 : virtual CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff,
97 : int nXSize, int nYSize, void *pData, int nBufXSize,
98 : int nBufYSize, GDALDataType eBufType,
99 : int nBandCount, BANDMAP_TYPE panBandMap,
100 : GSpacing nPixelSpace, GSpacing nLineSpace,
101 : GSpacing nBandSpace,
102 : GDALRasterIOExtraArg *psExtraArg) override;
103 : };
104 :
105 : /************************************************************************/
106 : /* KmlSuperOverlayRasterBand */
107 : /************************************************************************/
108 :
109 : class KmlSuperOverlayRasterBand final : public GDALRasterBand
110 : {
111 : public:
112 : KmlSuperOverlayRasterBand(KmlSuperOverlayReadDataset *poDS, int nBand);
113 :
114 : protected:
115 : virtual CPLErr IReadBlock(int, int, void *) override;
116 : virtual CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
117 : GDALDataType, GSpacing nPixelSpace,
118 : GSpacing nLineSpace,
119 : GDALRasterIOExtraArg *psExtraArg) override;
120 : virtual GDALColorInterp GetColorInterpretation() override;
121 :
122 : virtual int GetOverviewCount() override;
123 : virtual GDALRasterBand *GetOverview(int) override;
124 : };
125 :
126 : #endif /* ndef KMLSUPEROVERLAYDATASET_H_INCLUDED */
|