int main(int argc, char *argv[])
{
	char *input_image;
	char whynot[256];
	int i, width, height, has_alpha;

	if (argc < 2)
		usage();

	for (i = 0; i < 6; i++) {
		char inputfilename[PATH_MAX], outputfilename[PATH_MAX];
		if (strlen(argv[1]) > PATH_MAX - 20) {
			fprintf(stderr, "Length of argv[1] is too long, buster.\n");
			return 1;
		}
		sprintf(inputfilename, "%s%d.png", argv[1], i);
		sprintf(outputfilename, "%s-masked%d.png", argv[1], i);
		printf("Processing %s -> %s\n", inputfilename, outputfilename);
		input_image = png_utils_read_png_image(inputfilename, 0, 0, 0,
						&width, &height, &has_alpha, whynot, sizeof(whynot));
		if (!input_image) {
			fprintf(stderr, "png_utils_read_png_image: %s: %s -- skipping.\n", inputfilename, whynot);
			continue;
		}
		if (!has_alpha) {
			fprintf(stderr, "%s does not have an alpha channel, skipping\n", inputfilename);
			continue;
		}
		level_to_alpha(input_image, width, height);
		if (png_utils_write_png_image(outputfilename, (unsigned char *) input_image, width, height, 1, 0) != 0)
			fprintf(stderr, "Failed to save image %s\n", outputfilename);
		free(input_image);
	}
	return 0;
}
static void save_images(const char *prefix, unsigned char *image[])
{
	int i;
	char fname[PATH_MAX];

	for (i = 0; i < 6; i++) {
		sprintf(fname, "%s%d.png", prefix, i);
		if (png_utils_write_png_image(fname, image[i], DIM, DIM, 1, 0))
			fprintf(stderr, "Failed to write %s\n", fname);
	}
}
int main(int argc, char *argv[])
{
	unsigned char *image;
	float crater_r;
	const char *filename = "test_crater_output.png";

	image = malloc(3 * 1024 * 1024);
	memset(image, 127, 3 * 1024 * 1024);
	crater_r = 75.0;
	create_crater_heightmap((unsigned char *) image, 1024, 1024, 512, 512, (int) crater_r, 3);

	if (png_utils_write_png_image(filename, image, 1024, 1024, 0, 0)) {
		fprintf(stderr, "Failed to write png image %s: %s\n", filename, strerror(errno));
		exit(1);
	}
	printf("Wrote png image to %s\n", filename);
	return 0;
}