示例#1
0
void Renderer::sliceTile(const shared_ptr<MetaTile>& meta, const shared_ptr<Tile>& tile) const
{
	const shared_ptr<MetaIdentifier>& mid = meta->getIdentifier();
	const Cairo::RefPtr<Cairo::Surface>& surface = meta->getData();
	int tx0 = mid->getX();
	int ty0 = mid->getY();

	surface->flush();

	shared_ptr<ImageWriter> writer = getWriter(mid->getImageFormat(), TILE_SIZE, TILE_SIZE);
	Tile::ImageType buffer = boost::make_shared<Tile::ImageType::element_type>();
	// optimized for png images in the default stylesheet
	buffer->reserve(10*1024);
	CairoLayer layer = CairoLayer(writer, buffer);

	const shared_ptr<TileIdentifier>& tid = tile->getIdentifier();
	int dx = (tid->getX() - tx0) * TILE_SIZE;
	int dy = (tid->getY() - ty0) * TILE_SIZE;

	layer.cr->set_source(surface, -dx, -dy);
	layer.cr->paint();

#if DEBUG_BUILD
	printTileId(layer.cr, tile->getIdentifier());
#endif

	writer->write(layer.surface);
	tile->setImage(buffer);
}
示例#2
0
void Renderer::renderEmptyTile(RenderAttributes& map, const shared_ptr<Tile>& tile)
{
	const shared_ptr<TileIdentifier>& id = tile->getIdentifier();
	shared_ptr<ImageWriter> writer = getWriter(id->getImageFormat(), TILE_SIZE, TILE_SIZE);

	Tile::ImageType buffer = boost::make_shared<Tile::ImageType::element_type>();
	// optimized for png images in the default stylesheet
	buffer->reserve(10*1024);

#if OLD_CAIRO
	renderLock.lock();
#endif

	CairoLayer layer(writer, buffer);
	paintBackground(layer, map.getCanvasStyle());

#if DEBUG_BUILD
	printTileId(layer.cr, tile->getIdentifier());
#endif

#if OLD_CAIRO
	renderLock.unlock();
#endif

	writer->write(layer.surface);
	tile->setImage(buffer);
}
示例#3
0
void Cache::readFile(const Tile::ImageType& image, const string& filename) {
	std::ifstream file;
	file.open(filename, std::ios::in | std::ios::binary);
	file.seekg(0, std::ios::end);
	std::streampos length(file.tellg());
	if (length == std::streampos(-1) || !file.is_open()) {
		BOOST_THROW_EXCEPTION(excp::FileNotFoundException() << excp::InfoFileName(filename));
	} else if (length) {
		file.seekg(0, std::ios::beg);

		image->resize(static_cast<std::size_t>(length));
		image->assign(std::istreambuf_iterator<char>(file),
                    std::istreambuf_iterator<char>());
	}
}
示例#4
0
void Cache::writeFile(shared_ptr<Tile> tile, const string& path) {
	std::ofstream out(path, std::ios::out | std::ios::binary);
	if(out.is_open())
	{
		Tile::ImageType png = tile->getImage();
		if (png==0) {
			out.close();
			boost::filesystem::path file(path);
			boost::filesystem::remove(file);
			BOOST_THROW_EXCEPTION(excp::InputFormatException());
		} else {
			auto size = png->size();
			out.write((const char*) png->data(), size);
		}
	} else {
		// e.g. Disk full
		BOOST_THROW_EXCEPTION(excp::FileNotFoundException() << excp::InfoFileName(path));
	}
}
示例#5
0
	/**
	 * \brief Renders a tile to the given path using the test styles.
	 * \param tilePath path to the resulting tile
	 * \param id identifier of the tile that should be rendered
	 */
	void renderTile(const char* tilePath, shared_ptr<TileIdentifier> id)
	{
		BOOST_TEST_MESSAGE("Render: " << tilePath);
		RenderAttributes attr;
		Style* canvas = attr.getCanvasStyle();
		canvas->fill_color = Color(1.0f, 1.0f, 1.0f, 1.0f);

		coord_t x0, x1, y0, y1;
		tileToMercator(id->getX(),     id->getY(),     id->getZoom(), x0, y0);
		tileToMercator(id->getX() + 1, id->getY() + 1, id->getZoom(), x1, y1);
		FixedRect r = FixedRect(FixedPoint(x0, y0), FixedPoint(x1, y1));

		auto nodes = data->getNodeIDs(r);
		auto ways = data->getWayIDs(r);
		auto relations = data->getRelationIDs(r);

		generateStyles();

		BOOST_TEST_MESSAGE(" - ways " << ways->size());
		styleWays(ways, attr);

		BOOST_TEST_MESSAGE(" - nodes " << nodes->size());
		styleNodes(nodes, attr);

		BOOST_TEST_MESSAGE(" - relations " << relations->size());
		styleRelations(relations, attr);

		shared_ptr<MetaIdentifier> mid = MetaIdentifier::Create(id);
		shared_ptr<MetaTile> meta = boost::make_shared<MetaTile>(mid);
		renderer->renderMetaTile(attr, meta);
		shared_ptr<Tile> tile = boost::make_shared<Tile>(id);
		renderer->sliceTile(meta, tile);

		BOOST_TEST_MESSAGE("Writing the tile:");
		std::ofstream out;
		out.open(tilePath);
		BOOST_TEST_MESSAGE("- get data");
        Tile::ImageType png = tile->getImage();
		BOOST_TEST_MESSAGE("- writing (" << png->size() << " Bytes)");
		out.write((const char*) png->data(), png->size());
		out.close();
	}
示例#6
0
	void test_get_tile() {
		char* argv[] = {(char*)"ala.carte", (char*)"ala.carte", (char*)"--server.cache-size", (char*)"10"};
		ConfigMockup* mock = new ConfigMockup();
		shared_ptr<Configuration> config = mock->Config(argv, 4);
		shared_ptr<Cache> cache = shared_ptr<Cache>(new Cache(config));
		// tileIdentifier is not in valid range, so it wont be prerendered.
		shared_ptr<TileIdentifier> ti1 = boost::make_shared<TileIdentifier>(200, 1, 1, "default", TileIdentifier::Format::PNG);
		Tile::ImageType image = boost::make_shared<Tile::ImageType::element_type>();
		// tries to read file that doesn't exist.
		if (boost::filesystem::exists(config->get<string>(opt::server::cache_path) + "/default/1-200-1.png")) {
			boost::filesystem::remove(config->get<string>(opt::server::cache_path) + "/default/1-200-1.png");
		}
		shared_ptr<Tile> tile;
		BOOST_CHECK_NO_THROW(tile = cache->getTile(ti1));
		// Check it has not loaded an image.
		BOOST_CHECK(tile->getImage() == 0);
		// Access cache already there and Tile already there.
		BOOST_CHECK_NO_THROW(cache->getTile(ti1));
		// Access a lot of tiles to bring tile ^ to evict.
		for(int i = 1; i < 20; i++) {
			shared_ptr<TileIdentifier> ti2 = boost::make_shared<TileIdentifier>(1, i, 15, "default", TileIdentifier::Format::PNG);
			BOOST_CHECK_NO_THROW(cache->getTile(ti2));
		}
		// Main tile should not be evicted, because its not rendered yet.So check if theres no image on harddisk
		BOOST_CHECK(!boost::filesystem::exists(config->get<string>(opt::server::cache_path) + "/default/1-200-1.png"));
		image->push_back('a');
		tile->setImage(image);
		// One more time access many tile to evict main tile.
		for(int i = 1; i < 20; i++) {
			shared_ptr<TileIdentifier> ti2 = boost::make_shared<TileIdentifier>(1, i, 15, "default", TileIdentifier::Format::PNG);
			BOOST_CHECK_NO_THROW(cache->getTile(ti2));
		}
		// Check if main tile has been written to harddrive.
		BOOST_CHECK(boost::filesystem::exists(config->get<string>(opt::server::cache_path) + "/default/1-200-1.png"));
		// Access a tile formerly evicted to hard drive. 
		BOOST_CHECK_NO_THROW(cache->getTile(ti1));
		// Change access rights on hdd
	}
示例#7
0
	virtual void write(const Cairo::RefPtr<Cairo::Surface>& surface)
	{
		surface->flush();
		//surface->write_to_png_stream(sigc::mem_fun(*this, &Renderer::PNGWriter::cairoWriter));
		cairo_surface_write_to_png_stream(surface->cobj(), cairoWriter, (void*) buffer.get());
	}
示例#8
0
	Cairo::ErrorStatus cairoWriter(const unsigned char* data,
								   unsigned int length)
	{
		buffer->insert(buffer->end(), data, data+length);
		return CAIRO_STATUS_SUCCESS;
	}