コード例 #1
0
ファイル: tileset.c プロジェクト: svaarala/minisphere
void
build_tileset(const path_t* path, const image_t* image, int tile_width, int tile_height)
{
	FILE*                  file;
	ptrdiff_t              pitch;
	const uint32_t*        pixelbuf;
	struct rts_header      rts;
	struct rts_tile_header tile;
	int                    x, y;

	int i_y;
	uint16_t i;

	memset(&rts, 0, sizeof(struct rts_header));
	memcpy(&rts.signature, ".rts", 4);
	rts.version = 1;
	rts.num_tiles = (image_get_width(image) / tile_width) * (image_get_height(image) / tile_height);
	rts.has_obstructions = 0;
	rts.tile_width = (uint16_t)tile_width;
	rts.tile_height = (uint16_t)tile_height;
	rts.tile_bpp = 32;

	file = fopen(path_cstr(path), "wb");
	fwrite(&rts, sizeof(struct rts_header), 1, file);
	pitch = image_get_pitch(image);
	x = 0; y = 0;
	for (i = 0; i < rts.num_tiles; ++i) {
		for (i_y = 0; i_y < tile_height; ++i_y) {
			pixelbuf = image_get_pixelbuf(image) + x + (y + i_y) * pitch;
			fwrite(pixelbuf, tile_width * 4, 1, file);
		}
		if ((x += tile_width) + tile_width > image_get_width(image)) {
			x = 0;
			y += tile_height;
		}
	}
	memset(&tile, 0, sizeof(struct rts_tile_header));
	for (i = 0; i < rts.num_tiles; ++i)
		fwrite(&tile, sizeof(struct rts_tile_header), 1, file);
	fclose(file);
}
コード例 #2
0
source source::from_file(StringSlice path) {
	String path_cstr(c_str(path));
	return source(std::unique_ptr<pullable>(file_pullable::open((char const *)path_cstr.begin())));
}