source: subversion/applications/lib/libimg/ImgTre.cpp

Last change on this file was 2092, checked in by enxrah, 13 years ago

Nick didn't write this. I did :-)

File size: 4.4 KB
Line 
1/*
2    Copyright (C) 2007 Robert Hart, rob@bathterror.free-online.co.uk
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 2 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 Lesser 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, write to the Free Software
16    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
17
18 */
19#include "Img.h"
20#include "ImgTre.h"
21
22ImgTreFile::ImgTreFile()
23{
24  Fat.SetFileType("TRE");
25  Fat.SetFileName("TRE00001");
26}
27
28int ImgTreFile::ReadFile(std::ifstream &in)
29{
30  int oLevel, oSub, oCopy, oPolyL, oPolyG, oPOI;
31  int sLevel, sSub, sCopy, sPolyL, sPolyG, sPOI;
32  int rsCopy, rsPolyL, rsPolyG, rsPOI, poiflags;
33
34  int headerlen = ImgSubfile::ReadFile(in);
35  bound_n = DecodeCoord(0x15);
36  bound_e = DecodeCoord(0x18);
37  bound_s = DecodeCoord(0x1B);
38  bound_w = DecodeCoord(0x1E);
39  cout << "Tre BB: (" << bound_s << "," << bound_e << ")-("
40       << bound_n << "," << bound_w << ")" << endl;
41  oLevel = DecodeLong(0x21);
42  sLevel = DecodeLong(0x25);
43  oSub   = DecodeLong(0x29);
44  sSub   = DecodeLong(0x2D);
45  oCopy   = DecodeLong(0x31);
46  sCopy   = DecodeLong(0x35);
47  rsCopy  = DecodeShort(0x39);
48  poiflags= DecodeByte(0x3F);
49  oPolyL   = DecodeLong(0x4A);
50  sPolyL   = DecodeLong(0x4E);
51  rsPolyL  = DecodeShort(0x52);
52  oPolyG   = DecodeLong(0x58);
53  sPolyG   = DecodeLong(0x5C);
54  rsPolyG  = DecodeShort(0x60);
55  oPOI   = DecodeLong(0x66);
56  sPOI   = DecodeLong(0x6A);
57  rsPOI  = DecodeShort(0x6E);
58  cout << "Levels: off = " << oLevel << " len = " << sLevel << endl;
59  ReadLevels(oLevel, sLevel);
60
61  cout << "Subs  : off = " << oSub  << " len = " << sSub << endl;
62  ReadSubs(oSub, sSub);
63
64  cout << "Copy  : off = " << oCopy << " len = " << sCopy << endl;
65  ReadCopy(oCopy, sCopy, rsCopy);
66
67  cout << "PolyL  : off = " << oPolyL << " len = " << sPolyL << " rs = " << rsPolyL << endl;
68  ReadCopy(oPolyL, sPolyL, rsPolyL);
69
70  cout << "PolyG  : off = " << oPolyG << " len = " << sPolyG << " rs = " << rsPolyG << endl;
71  ReadCopy(oPolyG, sPolyG, rsPolyG);
72
73  cout << "POI  : off = " << oPOI << " len = " << sPOI << " rs = " << rsPOI << endl;
74  ReadCopy(oPOI, sPOI, rsPOI);
75  return headerlen;
76}
77
78int ImgTreFile::ReadLevels(int add, int size)
79{
80  int i;
81  int zoom, inherited;
82  for(i=0;i<16;i++){
83    Levels[i].present=FALSE;
84    Levels[i].last=FALSE;
85  }
86  for(i=0;i<(size>>2);i++){
87    zoom = DecodeByte(add+i*4+0);
88    inherited = zoom>>7;
89    zoom &= 0xF;
90    Levels[zoom].present=TRUE;
91    Levels[zoom].bits_per_coord = DecodeByte(add+i*4+1);
92    Levels[zoom].subs = DecodeByte(add+i*4+2);
93    cout << (zoom&0xF) << " = " << Levels[zoom].bits_per_coord << " bits per coord and " << Levels[zoom].subs << " subdivisions" << endl;
94  }
95  Levels[zoom].last=TRUE;
96  return size;
97}
98
99int ImgTreFile::ReadSubs(int add, int size)
100{
101  int i, j, off, c, next;
102  int oRGN, objType, width, height, term;
103  double origin_Lon, origin_Lat;
104  off = add;
105  c = 1; 
106  for(i=MAX_LEVEL-1;i>=0;i--){
107    if(Levels[i].present){
108      cout << "Level: " << i << endl;
109      for(j=0;j<Levels[i].subs;j++){
110        cout << "Sub: " << c; 
111        oRGN = DecodeInt24(off + 0);
112        objType = DecodeByte(off + 3);
113        origin_Lon = DecodeCoord(off + 4);
114        origin_Lat = DecodeCoord(off + 7);
115        width = DecodeShort(off + 10);
116        term = width >> 15;
117        width -= term << 15;
118        height = DecodeShort(off + 12);
119        //width = width << Levels[i].bits_per_coord;
120        //height = height << Levels[i].bits_per_coord;
121        cout << ", " << origin_Lon << ", " << origin_Lat;
122        cout << ", " << MapToCoord(width*2+1);
123        cout << ", " << MapToCoord(height*2+1);
124        if(Levels[i].last){
125          off+=14;
126        } else {
127          next = DecodeShort(off + 14);
128          off+=16;
129          cout << ", " << next;
130        }
131        c++;
132        cout << endl;
133      }
134    }
135  }
136  return size;
137}
138
139int ImgTreFile::ReadCopy(int add, int size, int rec_size)
140{
141  return size;
142}
143int ImgTreFile::ReadPolyL(int add, int size, int rec_size)
144{
145  return size;
146}
147int ImgTreFile::ReadPolyG(int add, int size, int rec_size)
148{
149  return size;
150}
151int ImgTreFile::ReadPOI(int add, int size, int rec_size)
152{
153  return size;
154}
Note: See TracBrowser for help on using the repository browser.