Example #1
0
int main(int argc, char *argv[])
{
    GP_Context *img;

    /* Turn on debug messages */
    GP_SetDebugLevel(10);

    if (argc != 2) {
        fprintf(stderr, "Takes an image as an parameter\n");
        return 1;
    }

    img = GP_LoadImage(argv[1], NULL);

    if (img == NULL) {
        fprintf(stderr, "Failed to load image '%s':%s\n", argv[1],
                strerror(errno));
        return 1;
    }

    if (GP_SavePNG(img, "out.png", NULL)) {
        fprintf(stderr, "Failed to save image %s", strerror(errno));
        return 1;
    }

    return 0;
}
Example #2
0
static int test_save_PNG(GP_PixelType pixel_type)
{
	GP_Context *ctx;
	int ret;

	ctx = GP_ContextAlloc(100, 100, pixel_type);

	if (ctx == NULL) {
		tst_msg("Failed to allocate context");
		return TST_UNTESTED;
	}

	errno = 0;

	ret = GP_SavePNG(ctx, "/dev/null", NULL);

	if (ret == 0) {
		tst_msg("Saved successfully");
		GP_ContextFree(ctx);
		return TST_SUCCESS;
	}

	switch (errno) {
	case ENOSYS:
		tst_msg("Not Implemented");
		GP_ContextFree(ctx);
		return TST_SKIPPED;
	default:
		tst_msg("Failed and errno is not ENOSYS (%i)", errno);
		GP_ContextFree(ctx);
		return TST_FAILED;
	}
}
Example #3
0
int main(int argc, char *argv[])
{
	GP_Context *img;
	struct callback_priv priv;
	GP_ProgressCallback callback = {.callback = progress_callback,
	                                .priv = &priv};

	if (argc != 2) {
		fprintf(stderr, "Takes an image as an parameter\n");
		return 1;
	}

	priv.op   = "Loading";
	priv.name = argv[1];

	img = GP_LoadImage(argv[1], &callback);

	if (img == NULL) {
		fprintf(stderr, "Failed to load image '%s':%s\n", argv[1],
		        strerror(errno));
		return 1;
	}

	printf("\n");

	priv.op   = "Saving";
	priv.name = "tmp.gfx";

	if (GP_SaveTmpFile(img, priv.name, &callback)) {
		fprintf(stderr, "Failed to save temp file %s\n", strerror(errno));
		return 1;
	}

	printf("\n");

	GP_ContextFree(img);

	priv.op   = "Loading";

	img = GP_LoadTmpFile(priv.name, &callback);

	if (img == NULL) {
		fprintf(stderr, "Failed to load temp file %s\n", strerror(errno));
		return 1;
	}

	priv.op   = "Saving";
	priv.name = "out.png";

	printf("\n");

	if (GP_SavePNG(img, "out.png", &callback)) {
		fprintf(stderr, "Failed to save image %s\n", strerror(errno));
		return 1;
	}

	printf("\n");

	return 0;
}
Example #4
0
static int save_img(enum fmt fmt, const GP_Context *img, const char *name)
{
	char buf[256];

	snprintf(buf, sizeof(buf), "%s.%s", name, strfmt(fmt));

	switch (fmt) {
	case PNG:
		return GP_SavePNG(img, buf, NULL);
	case JPG:
		return GP_SaveJPG(img, buf, NULL);
	case BMP:
		return GP_SaveBMP(img, buf, NULL);
	default:
		tst_err("Trying to save %s image", strfmt(fmt));
		exit(TST_UNTESTED);
	}
}
Example #5
0
int main(int argc, char *argv[])
{
	GP_Context *img;
	struct callback_priv priv;
	GP_ProgressCallback callback = {.callback = progress_callback,
	                                .priv = &priv};

	if (argc != 2) {
		fprintf(stderr, "Takes an image as an parameter\n");
		return 1;
	}

	priv.op   = "Loading";
	priv.name = argv[1];

	img = GP_LoadImage(argv[1], &callback);

	if (img == NULL) {
		fprintf(stderr, "Failed to load image '%s': %s\n", argv[1],
		        strerror(errno));
		return 1;
	}

	printf("\n");

	float box_kernel[] = {
		0.0, 0.1, 1.0, 0.1, 0.0,
		0.1, 0.5, 1.0, 0.5, 0.1,
		1.0, 1.0, 1.0, 1.0, 1.0,
		0.1, 0.5, 1.0, 0.5, 0.1,
		0.0, 0.1, 1.0, 0.1, 0.0,
	};

	GP_FilterKernel2D box = {
		.w = 5,
		.h = 5,
		.div = 11.8,
		.kernel = box_kernel,
	};

	priv.op = "Box Linear Convolution";

	/*
	 * Blur in-place, inner rectangle of the image.
	 */
	GP_FilterConvolutionEx(img, img->w/4, img->h/4, img->w/2, img->h/2,
	                       img, img->w/4, img->h/4, &box, &callback);

	printf("\n");

	priv.op   = "Saving";
	priv.name = "out.png";

	if (GP_SavePNG(img, "out.png", &callback)) {
		fprintf(stderr, "Failed to save image: %s", strerror(errno));
		return 1;
	}

	printf("\n");

	return 0;
}