Exemplo n.º 1
0
static bool sprite_file_export(int spriteIndex, const char *outPath)
{
	rct_g1_element *spriteHeader;
	rct_drawpixelinfo dpi;
	uint8 *pixels;
	int pixelBufferSize;

	spriteHeader = &spriteFileEntries[spriteIndex];
	pixelBufferSize = spriteHeader->width * spriteHeader->height;
	pixels = malloc(pixelBufferSize);
	memset(pixels, 0, pixelBufferSize);

	dpi.bits = pixels;
	dpi.x = 0;
	dpi.y = 0;
	dpi.width = spriteHeader->width;
	dpi.height = spriteHeader->height;
	dpi.pitch = 0;
	dpi.zoom_level = 0;

	memcpy(spriteFilePalette, _standardPalette, 256 * 4);
	gfx_rle_sprite_to_buffer(spriteHeader->offset, pixels, (uint8*)spriteFilePalette, &dpi, IMAGE_TYPE_DEFAULT, 0, spriteHeader->height, 0, spriteHeader->width);

	if (image_io_png_write(&dpi, (rct_palette*)spriteFilePalette, outPath)) {
		return true;
	} else {
		fprintf(stderr, "Error writing PNG");
		return false;
	}
}
Exemplo n.º 2
0
bool sprite_file_export(int spriteIndex, const char *outPath)
{
	rct_g1_element *spriteHeader;
	rct_drawpixelinfo dpi;
	uint8 *pixels;
	int pixelBufferSize;

	spriteHeader = &spriteFileEntries[spriteIndex];
	pixelBufferSize = spriteHeader->width * spriteHeader->height;
	pixels = malloc(pixelBufferSize);
	memset(pixels, 0, pixelBufferSize);

	dpi.bits = pixels;
	dpi.x = 0;
	dpi.y = 0;
	dpi.width = spriteHeader->width;
	dpi.height = spriteHeader->height;
	dpi.pitch = 0;
	dpi.zoom_level = 0;

	memcpy(spriteFilePalette, _standardPalette, 256 * 4);
	gfx_rle_sprite_to_buffer(spriteHeader->offset, pixels, (uint8*)spriteFilePalette, &dpi, IMAGE_TYPE_NO_BACKGROUND, 0, spriteHeader->height, 0, spriteHeader->width);

	LodePNGState pngState;
	unsigned int pngError;
	unsigned char* pngData;
	size_t pngSize;

	lodepng_state_init(&pngState);
	pngState.info_raw.colortype = LCT_PALETTE;
	lodepng_palette_add(&pngState.info_raw, 0, 0, 0, 0);
	for (int i = 1; i < 256; i++) {
		lodepng_palette_add(
			&pngState.info_raw,
			spriteFilePalette[i].r,
			spriteFilePalette[i].g,
			spriteFilePalette[i].b,
			255
		);
	}

	pngError = lodepng_encode(&pngData, &pngSize, pixels, spriteHeader->width, spriteHeader->height, &pngState);
	if (pngError != 0) {
		free(pngData);
		fprintf(stderr, "Error creating PNG data, %u: %s", pngError, lodepng_error_text(pngError));
		return false;
	} else {
		lodepng_save_file(pngData, pngSize, outPath);
		free(pngData);
		return true;
	}
}