Exemplo n.º 1
0
static void sample_tile(texgz_tex_t* src,
                        int month, int x, int y,
                        double latT, int lonL,
                        double latB, int lonR)
{
	assert(src);
	LOGD("debug month=%i, x=%i, y=%i, latT=%lf, lonL=%lf, latB=%lf, lonR=%lf",
	     month, x, y, latT, lonL, latB, lonR);

	char fname[256];
	snprintf(fname, 256, "bluemarble%i/9/%i_%i.pak", month, x, y);
	pak_file_t* pak = pak_file_open(fname, PAK_FLAG_WRITE);
	if(pak == NULL)
	{
		return;
	}

	int i;
	int j;
	for(i = 0; i < NEDGZ_SUBTILE_COUNT; ++i)
	{
		for(j = 0; j < NEDGZ_SUBTILE_COUNT; ++j)
		{
			sample_subtile(src, pak, x, y, i, j, latT, lonL, latB, lonR);
		}
	}

	pak_file_close(&pak);
}
Exemplo n.º 2
0
static int sample_tile(int x, int y, int zoom)
{
	LOGD("debug x=%i, y=%i, zoom=%i", x, y, zoom);

	// create directories if necessary
	char dname[256];
	snprintf(dname, 256, "heightmap/%i", zoom);
	if(mkdir(dname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1)
	{
		if(errno == EEXIST)
		{
			// already exists
		}
		else
		{
			LOGE("mkdir %s failed", dname);
			return 0;
		}
	}

	nedgz_tile_t* tile = nedgz_tile_new(x, y, zoom);
	if(tile == NULL)
	{
		return 0;
	}

	char fname[256];
	snprintf(fname, 256, "heightmap/%i/%i_%i.pak", zoom, x, y);
	pak_file_t* pak = pak_file_open(fname, PAK_FLAG_WRITE);
	if(pak == NULL)
	{
		goto fail_pak;
	}

	// sample subtiles i,j
	int j;
	int i;
	for(i = 0; i < NEDGZ_SUBTILE_COUNT; ++i)
	{
		for(j = 0; j < NEDGZ_SUBTILE_COUNT; ++j)
		{
			if(sample_subtile(tile, i, j, pak) == 0)
			{
				goto fail_sample;
			}
		}
	}

	pak_file_close(&pak);
	nedgz_tile_delete(&tile);

	// success
	return 1;

	// failure
	fail_sample:
		pak_file_close(&pak);
	fail_pak:
		nedgz_tile_delete(&tile);
	return 0;
}
Exemplo n.º 3
0
int main(int argc, char** argv)
{
	const char* arg0 = argv[0];
	if(argc < 3)
	{
		usage(arg0);
		return EXIT_FAILURE;
	}

	pak_file_t* pak;
	const char* cmd   = argv[1];
	const char* fname = argv[2];
	if(strcmp(cmd, "-c") == 0)
	{
		pak = pak_file_open(fname, PAK_FLAG_WRITE);

		int i;
		for(i = 3; i < argc; ++i)
		{
			append(pak, argv[i]);
		}

		pak_file_close(&pak);
	}
	else if(strcmp(cmd, "-a") == 0)
	{
		pak = pak_file_open(fname, PAK_FLAG_APPEND);

		int i;
		for(i = 3; i < argc; ++i)
		{
			append(pak, argv[i]);
		}

		pak_file_close(&pak);
	}
	else if(strcmp(cmd, "-x") == 0)
	{
		pak = pak_file_open(fname, PAK_FLAG_READ);

		int i;
		for(i = 3; i < argc; ++i)
		{
			extract(pak, argv[i]);
		}

		pak_file_close(&pak);
	}
	else if(strcmp(cmd, "-l") == 0)
	{
		pak = pak_file_open(fname, PAK_FLAG_READ);

		pak_item_t* item = pak_file_head(pak);
		while(item)
		{
			LOGI("%i %s", pak_item_size(item), pak_item_key(item));
			item = pak_item_next(item);
		}
	}
	else
	{
		usage(arg0);
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Exemplo n.º 4
0
int main(int argc, char** argv)
{
	// osm.list
	// zoom x y
	if(argc != 2)
	{
		LOGE("usage: %s [osm.list]", argv[0]);
		return EXIT_FAILURE;
	}

	// create directories if necessary
	char dname[256];
	snprintf(dname, 256, "%s", "osm");
	if(mkdir(dname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1)
	{
		if(errno == EEXIST)
		{
			// already exists
		}
		else
		{
			LOGE("mkdir %s failed", dname);
			return EXIT_FAILURE;
		}
	}

	// open the list
	FILE* f = fopen(argv[1], "r");
	if(f == NULL)
	{
		LOGE("failed to open %s", argv[1]);
		return EXIT_FAILURE;
	}

	// iteratively pak osm images
	char* line = NULL;
	size_t n   = 0;
	int index = 0;
	while(getline(&line, &n, f) > 0)
	{
		int x;
		int y;
		int zoom;
		if(sscanf(line, "%i %i %i", &zoom, &x, &y) != 3)
		{
			LOGE("invalid line=%s", line);
			continue;
		}

		LOGI("%i: zoom=%i, x=%i, y=%i", index++, zoom, x, y);

		// create directories if necessary
		char dname[256];
		snprintf(dname, 256, "osm/%i", zoom);
		if(mkdir(dname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1)
		{
			if(errno == EEXIST)
			{
				// already exists
			}
			else
			{
				LOGE("mkdir %s failed", dname);
				continue;
			}
		}

		char fname[256];
		snprintf(fname, 256, "osm/%i/%i_%i.pak", zoom, x, y);
		pak_file_t* pak = pak_file_open(fname, PAK_FLAG_WRITE);
		if(pak == NULL)
		{
			continue;
		}

		int i;
		int j;
		for(i = 0; i < 8; ++i)
		{
			for(j = 0; j < 8; ++j)
			{
				int xj = 8*x + j;
				int yi = 8*y + i;

				snprintf(fname, 256, "localhost/osm/%i/%i/%i.png", zoom, xj, yi);
				texgz_tex_t* tex = texgz_png_import(fname);
				if(tex == NULL)
				{
					continue;
				}

				if(texgz_tex_convert(tex,
				                     TEXGZ_UNSIGNED_SHORT_4_4_4_4,
				                     TEXGZ_RGBA) == 0)
				{
					texgz_tex_delete(&tex);
					continue;
				}

				// j=dx, i=dy
				snprintf(fname, 256, "%i_%i", j, i);
				pak_file_writek(pak, fname);
				texgz_tex_exportf(tex, pak->f);
				texgz_tex_delete(&tex);
			}
		}

		pak_file_close(&pak);
	}
	free(line);

	return EXIT_SUCCESS;
}
Exemplo n.º 5
0
a3d_spriteTex_t* a3d_spriteTex_new(const char* fname,
                                   const char* resource)
{
	assert(fname);
	assert(resource);
	LOGD("debug fname=%s, resource=%s", fname, resource);

	a3d_spriteTex_t* self = (a3d_spriteTex_t*) malloc(sizeof(a3d_spriteTex_t));
	if(self == NULL)
	{
		LOGE("malloc failed");
		return NULL;
	}

	pak_file_t*  pak = NULL;
	texgz_tex_t* tex = NULL;
	if(fname[0] == '$')
	{
		pak = pak_file_open(resource, PAK_FLAG_READ);
		if(pak)
		{
			const char* key = &(fname[1]);
			int size = pak_file_seek(pak, key);
			if(size > 0)
			{
				tex = texgz_tex_importf(pak->f, size);
			}
			else
			{
				LOGE("invalid fname=%s", fname);
			}
			pak_file_close(&pak);
		}
	}
	else
	{
		tex = texgz_tex_import(fname);
	}

	if(tex == NULL)
	{
		goto fail_tex;
	}

	// load tex
	glGenTextures(1, &self->id_tex);
	glBindTexture(GL_TEXTURE_2D, self->id_tex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexImage2D(GL_TEXTURE_2D, 0, tex->format,
	             tex->stride, tex->vstride,
	             0, tex->format, tex->type,
	             tex->pixels);

	// no longer needed
	texgz_tex_delete(&tex);

	strncpy(self->fname, fname, 256);
	self->fname[255] = '\0';
	self->ref_count  = 0;

	// success
	return self;

	// failure
	fail_tex:
		free(self);
	return NULL;
}