1 /********************************************************************************************** 2 Copyright (C) 2006-2007 Oliver Eichler <oliver.eichler@gmx.de> 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 Garmin and MapSource are registered trademarks or trademarks of Garmin Ltd. 18 or one of its subsidiaries. 19 20 This source is based on John Mechalas documentation "Garmin IMG File Format" found 21 at sourceforge. The missing bits and error were rectified by the source code of 22 Konstantin Galichsky (kg@geopainting.com), http://www.geopainting.com 23 24 **********************************************************************************************/ 25 #ifndef CGARMINPOLYGON_H 26 #define CGARMINPOLYGON_H 27 28 #include "gis/proj_x.h" 29 30 #ifdef __MINGW32__ 31 #undef LP 32 #endif 33 #include <QPolygonF> 34 #include <QtCore> 35 36 struct subdiv_desc_t; 37 struct sign_info_t; 38 39 class CGarminPolygon 40 { 41 public: 42 CGarminPolygon() = default; 43 virtual ~CGarminPolygon() = default; 44 45 quint32 decode(qint32 iCenterLon, qint32 iCenterLat, quint32 shift, bool line, const quint8* pData, const quint8* pEnd); 46 quint32 decode2(qint32 iCenterLon, qint32 iCenterLat, quint32 shift, bool line, const quint8* pData, const quint8* pEnd); 47 48 QString getLabelText() const; 49 hasLabel()50 bool hasLabel() const 51 { 52 return !labels.isEmpty(); 53 } 54 55 quint32 type = 0; 56 /// direction of line (polyline, only) 57 bool direction = false; 58 /// the label offset 59 quint32 lbl_info = 0; 60 /// true if label offset has to be used in NET section 61 bool lbl_in_NET = false; 62 /// 63 bool hasV2Label = false; 64 /// delta longitude from subdivision center 65 qint16 dLng = 0; 66 /// delta latitude from subdivision center 67 qint16 dLat = 0; 68 /** @brief the actual polyline points as [pixel] 69 @note After decode() or decode2() the content will be the same as coords. 70 It is up to the render object to convert it into pixel coordinates 71 */ 72 QPolygonF pixel; 73 /// the actual polyline points as longitude / latitude [rad] 74 QPolygonF coords; 75 76 quint32 id = 0; 77 78 QStringList labels; 79 80 static quint32 cnt; 81 static qint32 maxVecSize; 82 private: 83 void bits_per_coord(quint8 base, quint8 bfirst, quint32& bx, quint32& by, sign_info_t& signinfo, bool isVer2); 84 int bits_per_coord(quint8 base, bool is_signed); 85 }; 86 87 class CShiftReg 88 { 89 public: 90 CShiftReg(const quint8* pData, quint32 n, quint32 bx, quint32 by, bool extra_bit, sign_info_t& si); 91 92 bool get(qint32& x, qint32& y); 93 private: 94 void fill(quint32 bits); 95 /// the register to work on 96 quint64 reg; 97 /// the data stream to get data from 98 const quint8* pData; 99 100 quint32 bytes; //< bytes left in stream 101 quint32 xmask; //< bitmask x coord. 102 quint32 ymask; //< bitmask y coord. 103 qint32 xsign; //< sign bit for x value 104 qint32 ysign; //< sign bit for y value 105 qint32 xsign2; //< sign bit * 2 for x value 106 qint32 ysign2; //< sign bit * 2 for y value 107 quint8 bits; //< total bits in register 108 quint8 bits_per_x; //< bits per x coord. 109 quint8 bits_per_y; //< bits per y coord. 110 quint8 bits_per_coord; //< bits per coord. 111 112 sign_info_t& sinfo; 113 114 bool extraBit; 115 }; 116 #endif //CGARMINPOLYGON_H 117