File: buffer.cpp

package info (click to toggle)
vips 8.18.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 53,240 kB
  • sloc: ansic: 172,611; cpp: 12,257; python: 5,077; sh: 773; perl: 40; makefile: 25; javascript: 6
file content (42 lines) | stat: -rw-r--r-- 914 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
/*
 * compile with:
 *
 *      g++ -g -Wall buffer.cpp `pkg-config vips-cpp --cflags --libs`
 *
 */

#define DEBUG

#include <vips/vips8>

using namespace vips;

int
main(int argc, char **argv)
{
	if (VIPS_INIT(argv[0]))
		vips_error_exit(NULL);

	// load an image from a file
	VImage im = VImage::new_from_file(argv[1],
		VImage::option()->set("access", "sequential"));
	printf("loaded %d x %d pixel image from %s\n",
		im.width(), im.height(), argv[1]);

	// write to a formatted memory buffer
	size_t size;
	void *buf;
	im.write_to_buffer(".png", &buf, &size);
	printf("written to memory %p in png format, %zu bytes\n", buf, size);

	// load from the formatted memory area
	im = VImage::new_from_buffer(buf, size, "");
	printf("loaded from memory, %d x %d pixel image\n",
		im.width(), im.height());

	// write back to a file
	im.write_to_file(argv[2]);
	printf("written back to  %s\n", argv[2]);

	return 0;
}