Skip to content

Commit 49635c0

Browse files
committed
some progress on QCT file compatibility. Not working yet
1 parent 3b03769 commit 49635c0

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

QctMapDB.cpp

+32-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
#define NOT_IMPLEMENTED std::cerr << __PRETTY_FUNCTION__ << ": not implemented yet."
99

1010
QctMapDB::QctMapDB(const QString& name)
11-
: MapDB(name)
11+
: MapDB(name), mQctFile(name.toStdString())
1212
{
1313
if(!QFile(name).exists())
1414
throw std::runtime_error("Specified file " + name.toStdString() + " is not present on disk.");
1515

1616
std::cerr << "Reading Qct file " + name.toStdString() << std::endl;
1717

18-
mQctFile.readFilename(name.toStdString().c_str(),true,nullptr);
19-
2018
double lat_00, lon_00, lat_10, lon_10, lat_01, lon_01, lat_11, lon_11 ;
2119
mQctFile.computeLatLonLimits(lat_00, lon_00, lat_10, lon_10, lat_01, lon_01, lat_11, lon_11 );
2220

@@ -29,13 +27,28 @@ QctMapDB::QctMapDB(const QString& name)
2927
std::cerr << "Area is axis aligned. Good." << std::endl;
3028
else
3129
std::cerr << "Area is not axis aligned. Not good." << std::endl;
30+
31+
mBottomLeft.x = 0;
32+
mBottomLeft.y = 0;
33+
mTopRight.x = mQctFile.QCT_TILE_SIZE * mQctFile.sizeX();
34+
mTopRight.y = mQctFile.QCT_TILE_SIZE * mQctFile.sizeY();
35+
36+
for(int i=0;i<mQctFile.sizeX();++i)
37+
for(int j=0;j<mQctFile.sizeY();++j)
38+
{
39+
MapDB::RegisteredImage registered_img;
40+
registered_img.W = mQctFile.QCT_TILE_SIZE ;
41+
registered_img.H = mQctFile.QCT_TILE_SIZE ;
42+
registered_img.bottom_left_corner.x = mQctFile.QCT_TILE_SIZE * i ;
43+
registered_img.bottom_left_corner.y = mQctFile.QCT_TILE_SIZE * j ;
44+
45+
mImages.insert(std::make_pair(MapDB::ImageHandle(i+mQctFile.sizeX()*j),registered_img));
46+
}
3247
}
3348

3449
const std::map<MapDB::ImageHandle,MapDB::RegisteredImage>& QctMapDB::getFullListOfImages() const
3550
{
36-
NOT_IMPLEMENTED;
37-
38-
return std::map<MapDB::ImageHandle,MapDB::RegisteredImage>();
51+
return mImages;
3952
}
4053
bool QctMapDB::getImageParams(ImageHandle h, MapDB::RegisteredImage& img) const
4154
{
@@ -45,9 +58,9 @@ bool QctMapDB::getImageParams(ImageHandle h, MapDB::RegisteredImage& img) const
4558
}
4659
QImage QctMapDB::getImageData(ImageHandle h) const
4760
{
48-
NOT_IMPLEMENTED;
61+
QImage image(QctFile::QCT_TILE_SIZE,QctFile::QCT_TILE_SIZE,QImage::Format_ARGB32);
62+
4963

50-
return QImage();
5164
}
5265
bool QctMapDB::imageSpaceCoordinatesToGPSCoordinates(const MapDB::ImageSpaceCoord& ic,MapDB::GPSCoord& g) const
5366
{
@@ -62,3 +75,14 @@ const MapDB::ReferencePoint& QctMapDB::getReferencePoint(int i) const
6275
return ReferencePoint();
6376
}
6477
int QctMapDB::numberOfReferencePoints() const { return 2 ; }
78+
79+
std::pair<int,int> QctMapDB::handleToCoordinates(ImageHandle h) const
80+
{
81+
return std::make_pair( int(h)%mQctFile.sizeX(), int(h)/mQctFile.sizeY());
82+
}
83+
84+
MapDB::ImageHandle QctMapDB::coordinatesToHandle(int x,int y) const
85+
{
86+
return ImageHandle(mQctFile.sizeX()*y + x);
87+
}
88+

QctMapDB.h

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class QctMapDB : public MapDB
1919
virtual int numberOfReferencePoints() const override;
2020

2121
private:
22+
std::pair<int,int> handleToCoordinates(ImageHandle h) const;
23+
ImageHandle coordinatesToHandle(int x,int y) const;
24+
std::map<MapDB::ImageHandle,MapDB::RegisteredImage> mImages;
2225

2326
QctFile mQctFile;
2427
};

qct2png.cpp

+14-8
Original file line numberDiff line numberDiff line change
@@ -812,13 +812,13 @@ QCT::readFile(FILE *fp, int headeronly,unsigned char *data)
812812
fgetc(fp);
813813
}
814814

815-
// Don't read and unpack image data if not required
815+
if(size_x == 0) size_x = width ;
816+
if(size_y == 0) size_y = height ;
817+
818+
// Don't read and unpack image data if not required
816819
if (headeronly)
817820
return true;
818821

819-
if(size_x == 0) size_x = width ;
820-
if(size_y == 0) size_y = height ;
821-
822822

823823
{
824824
int xx, yy;
@@ -1173,7 +1173,7 @@ static bool writePNGFile(FILE *fp, const unsigned char *data, const int *palette
11731173

11741174
return true;
11751175
#else
1176-
throwError("cannot write file (PNG not supported)");
1176+
//throwError("cannot write file (PNG not supported)");
11771177
return false;
11781178
#endif
11791179
}
@@ -1341,14 +1341,20 @@ main(int argc, char *argv[])
13411341
// Image index (width * height pointers)
13421342
// Allocate image data once for all
13431343

1344-
unsigned char *image_data = (unsigned char*)calloc(size_tile_y*QCT_TILE_SIZE, size_tile_x*QCT_TILE_SIZE);
13451344

13461345
if (query)
13471346
{
13481347
qct.printMetadata(stdout);
1348+
return 1;
13491349
}
1350-
else if (outputfile)
1351-
writePNGFilename(outputfile,image_data,qct.getPalette(),size_tile_x*QCT_TILE_SIZE,size_tile_y*QCT_TILE_SIZE);
1350+
1351+
unsigned char *image_data = (unsigned char*)calloc(size_tile_y*QCT_TILE_SIZE, size_tile_x*QCT_TILE_SIZE);
1352+
1353+
std::cerr << "Image size: " << size_tile_y*QCT_TILE_SIZE << " x " << size_tile_x*QCT_TILE_SIZE << std::endl;
1354+
if(!qct.readFilename(inputfile,query,image_data))
1355+
return 0;
1356+
1357+
writePNGFilename(outputfile,image_data,qct.getPalette(),size_tile_x*QCT_TILE_SIZE,size_tile_y*QCT_TILE_SIZE);
13521358

13531359
if (outputKMZfile)
13541360
{

0 commit comments

Comments
 (0)