File: new-from-buffer.c

package info (click to toggle)
vips 8.17.3-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 52,228 kB
  • sloc: ansic: 169,684; cpp: 12,156; python: 4,887; sh: 733; perl: 40; makefile: 25; javascript: 6
file content (54 lines) | stat: -rw-r--r-- 907 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* Read and write formatted images to memory.
 *
 * Compile with:
 *
 * 	gcc -g -Wall new-from-buffer.c `pkg-config vips --cflags --libs`
 *
 */

#include <vips/vips.h>

int
main(int argc, char **argv)
{
	gchar *buf;
	gsize len;
	int i;

	if (VIPS_INIT(argv[0]))
		vips_error_exit(NULL);

	if (argc != 2)
		vips_error_exit("usage: %s FILENAME", argv[0]);

	if (!g_file_get_contents(argv[1], &buf, &len, NULL))
		vips_error_exit(NULL);

	for (i = 0; i < 10; i++) {
		VipsImage *image;
		void *new_buf;
		size_t new_len;

		printf("loop %d ...\n", i);

		if (!(image = vips_image_new_from_buffer(buf, len, "",
				  "access", VIPS_ACCESS_SEQUENTIAL,
				  NULL)))
			vips_error_exit(NULL);

		if (vips_image_write_to_buffer(image,
				".jpg", &new_buf, &new_len,
				"Q", 95,
				NULL))
			vips_error_exit(NULL);

		g_object_unref(image);
		g_free(new_buf);
	}

	g_free(buf);

	vips_shutdown();

	return 0;
}