void QGeoMapReplyOsm::networkReplyFinished() { if (!m_reply) return; if (m_reply->error() != QNetworkReply::NoError) return; QByteArray a = m_reply->readAll(); setMapImageData(a); switch (tileSpec().mapId()) { case 1: setMapImageFormat("png"); break; case 2: setMapImageFormat("png"); break; default: qWarning("Unknown map id %d", tileSpec().mapId()); } setFinished(true); m_reply->deleteLater(); m_reply = 0; }
void QGeoMapReplyQGC::networkReplyFinished() { if (!m_reply) { return; } if (m_reply->error() != QNetworkReply::NoError) { return; } QByteArray a = m_reply->readAll(); setMapImageData(a); if(a.size() > 2) { if((char)a[0] == (char)0xff && (char)a[1] == (char)0xd8) setMapImageFormat("jpg"); else if((char)a[0] == (char)0x89 && (char)a[1] == (char)0x50) setMapImageFormat("png"); else { switch ((OpenPilot::MapType)tileSpec().mapId()) { case OpenPilot::GoogleMap: case OpenPilot::GoogleLabels: case OpenPilot::GoogleTerrain: case OpenPilot::GoogleHybrid: case OpenPilot::BingMap: case OpenPilot::OpenStreetMap: setMapImageFormat("png"); break; case OpenPilot::GoogleSatellite: case OpenPilot::BingSatellite: case OpenPilot::BingHybrid: setMapImageFormat("jpg"); break; default: qWarning("Unknown map id %d", tileSpec().mapId()); break; } } } setFinished(true); m_reply->deleteLater(); m_reply = 0; }
//----------------------------------------------------------------------------- void QGeoTiledMapReplyQGC::networkReplyFinished() { if (!_reply) { return; } if (_reply->error() != QNetworkReply::NoError) { return; } QByteArray a = _reply->readAll(); setMapImageData(a); QString format = getQGCMapEngine()->urlFactory()->getImageFormat((UrlFactory::MapType)tileSpec().mapId(), a); if(!format.isEmpty()) { setMapImageFormat(format); getQGCMapEngine()->cacheTile((UrlFactory::MapType)tileSpec().mapId(), tileSpec().x(), tileSpec().y(), tileSpec().zoom(), a, format); } setFinished(true); _reply->deleteLater(); _reply = 0; }
bool SMT::save() { // Make sure we have some source images before continuing if( sourceFiles.size() == 0) { if( !quiet )cout << "ERROR: No source images to convert" << endl; return true; } // Build SMT Header // ////////////////////// char filename[256]; sprintf(filename, "%s.smt", outPrefix.c_str()); if( verbose ) printf("\nINFO: Creating %s\n", filename ); fstream smt( filename, ios::binary | ios::out ); if( !smt.good() ) { cout << "ERROR: fstream error." << endl; return true; } SMTHeader header; header.tileRes = tileRes; header.tileType = tileType; if( verbose ) { cout << " Version: " << header.version << endl; cout << " nTiles: n/a\n"; printf( " tileRes: (%i,%i)%i.\n", tileRes, tileRes, 4); cout << " tileType: "; if( tileType == DXT1 ) cout << "DXT1" << endl; cout << " tileSize: " << tileSize << " bytes" << endl; } smt.write( (char *)&header, sizeof(SMTHeader) ); smt.close(); // setup size for index dimensions int tcx = width * 16; // tile count x int tcz = length * 16; // tile count z unsigned int *indexPixels = new unsigned int[tcx * tcz]; // Load source image if( verbose )cout << "INFO: Loading Source Image(s)\n"; ImageBuf *bigBuf = buildBig(); ImageSpec bigSpec = bigBuf->spec(); // Process decals if( !decalFile.empty() ) { if( verbose )cout << "INFO: Processing decals\n"; pasteDecals( bigBuf ); } // Swizzle channels if( verbose )cout << "INFO: Swizzling channels\n"; ImageBuf fixBuf; int map[] = { 2, 1, 0, 3 }; ImageBufAlgo::channels( fixBuf, *bigBuf, 4, map ); bigBuf->copy( fixBuf ); fixBuf.clear(); // Process Tiles if( verbose )cout << "INFO: Processing tiles\n"; // Time reporting vars timeval t1, t2; double elapsedTime; deque<double> readings; double averageTime = 0; double intervalTime = 0; // Loop vars int totalTiles = tcx * tcz; int currentTile; // Tile Vars ROI roi; ImageSpec tileSpec(tileRes, tileRes, 4, TypeDesc::UINT8 ); // Comparison vars bool match; bool yee = false; unsigned int i; string hash; vector<string> hashTable; TileBufListEntry *listEntry; deque<TileBufListEntry *> tileList; // Open smt file for writing tiles smt.open(filename, ios::binary | ios::out | ios::app ); // loop through tile columns for ( int z = 0; z < tcz; z++) { // loop through tile rows for ( int x = 0; x < tcx; x++) { currentTile = z * tcx + x + 1; gettimeofday(&t1, NULL); // pull a region of the big image to use as a tile. roi.xbegin = x * tileRes; roi.xend = x * tileRes + tileRes; roi.ybegin = z * tileRes; roi.yend = z * tileRes + tileRes; roi.zbegin = 0; roi.zend = 1; roi.chbegin = 0; roi.chend = 4; ImageBuf tempBuf; ImageBufAlgo::crop( tempBuf, *bigBuf, roi ); ImageBuf *tileBuf = new ImageBuf( filename, tileSpec, tempBuf.localpixels() ); // reset match variables match = false; i = nTiles; if( cnum < 0) { // no attempt at reducing tile sizes i = nTiles; } else if( cnum == 0) { // only exact matches will be referenced. hash = ImageBufAlgo::computePixelHashSHA1( *tileBuf ); for( i = 0; i < hashTable.size(); ++i ) { if( !hashTable[i].compare( hash ) ) { match = true; break; } } if( !match ) hashTable.push_back( hash ); } else if( !yee ) { //Comparison based on numerical differences of pixels listEntry = new TileBufListEntry; listEntry->image.copy(*tileBuf); listEntry->tileNum = nTiles; ImageBufAlgo::CompareResults result; deque< TileBufListEntry * >::iterator it; for(it = tileList.begin(); it != tileList.end(); it++ ) { TileBufListEntry *listEntry2 = *it; ImageBufAlgo::compare( *tileBuf, listEntry2->image, cpet, 1.0f, result); //TODO give control on tweaking matching if((int)result.nfail < cnet) { match = true; i = listEntry2->tileNum; delete listEntry; break; } } if( !match ) { tileList.push_back(listEntry); if((int)tileList.size() > cnum) { delete tileList[0]; tileList.pop_front(); } } } else { //FIXME uncomment when OpenImageIO gets upgraded to v3 /* listEntry = new TileBufListEntry; listEntry->image.copy(*tileBuf); listEntry->tileNum = nTiles; ImageBufAlgo::CompareResults result; deque< TileBufListEntry * >::iterator it; for(it = tileList.begin(); it != tileList.end(); it++ ) { TileBufListEntry *listEntry2 = *it; ImageBufAlgo::compare_yee( *tileBuf, listEntry2->image, result, 1.0f, 1.0f ); if(result.nfail == 0) { match = true; i = listEntry2->tileNum; break; } } if( !match ) { tileList.push_back(listEntry); if((int)tileList.size() > 32) tileList.pop_front(); }*/ } // write tile to file. if( !match ) { unsigned char *std = (unsigned char *)tileBuf->localpixels(); // process into dds NVTTOutputHandler *nvttHandler = new NVTTOutputHandler(tileSize); nvtt::InputOptions inputOptions; inputOptions.setTextureLayout( nvtt::TextureType_2D, tileRes, tileRes ); inputOptions.setMipmapData( std, tileRes, tileRes ); nvtt::CompressionOptions compressionOptions; compressionOptions.setFormat(nvtt::Format_DXT1a); nvtt::OutputOptions outputOptions; outputOptions.setOutputHeader(false); outputOptions.setOutputHandler( nvttHandler ); nvtt::Compressor compressor; if( slow_dxt1 ) compressionOptions.setQuality(nvtt::Quality_Normal); else compressionOptions.setQuality(nvtt::Quality_Fastest); compressor.process(inputOptions, compressionOptions, outputOptions); smt.write( nvttHandler->buffer, tileSize ); delete nvttHandler; nTiles +=1; } delete tileBuf; // Write index to tilemap indexPixels[currentTile-1] = i; gettimeofday(&t2, NULL); // compute and print the elapsed time in millisec elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms readings.push_back(elapsedTime); if(readings.size() > 1000)readings.pop_front(); intervalTime += elapsedTime; if( verbose && intervalTime > 1 ) { for(unsigned int i = 0; i < readings.size(); ++i) averageTime+= readings[i]; averageTime /= readings.size(); intervalTime = 0; printf("\033[0G %i of %i %%%0.1f complete | %%%0.1f savings | %0.1fs remaining.", currentTile, totalTiles, (float)currentTile / totalTiles * 100, (float)(1 - (float)nTiles / (float)currentTile) * 100, averageTime * (totalTiles - currentTile) / 1000); } } } hashTable.clear(); if( verbose ) cout << endl; smt.close(); // retroactively fix up the tile count. smt.open(filename, ios::binary | ios::in | ios::out ); smt.seekp( 20); smt.write( (char *)&nTiles, 4); smt.close(); // Save tileindex ImageOutput *imageOutput; sprintf( filename, "%s_tilemap.exr", outPrefix.c_str() ); imageOutput = ImageOutput::create(filename); if( !imageOutput ) { delete [] indexPixels; return true; } ImageSpec tilemapSpec( tcx, tcz, 1, TypeDesc::UINT); imageOutput->open( filename, tilemapSpec ); imageOutput->write_image( TypeDesc::UINT, indexPixels ); imageOutput->close(); delete imageOutput; delete [] indexPixels; return false; }