-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGEGLclass.cpp
96 lines (84 loc) · 2.84 KB
/
GEGLclass.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "GEGLclass.h"
#include <stdio.h>
GEGLclass::GEGLclass(int argc, char **argv) {
gegl_init(&argc, &argv);
graph = gegl_node_new();
src = gegl_node_new_child(graph, "operation", "gegl:load",
"path", argv[1],
NULL);
sink = gegl_node_new_child(graph, "operation", "gegl:buffer-sink",
"buffer", &buffer,
NULL);
gegl_node_link_many(src, sink, NULL);
gegl_node_process(sink);
g_object_unref(graph);
save_path = argv[2];
x = gegl_buffer_get_x(buffer);
y = gegl_buffer_get_y(buffer);
width = gegl_buffer_get_width(buffer);
height = gegl_buffer_get_height(buffer);
pixelcount = gegl_buffer_get_pixel_count(buffer);
GeglRectangle rect = { x, y, width, height };
src_rect = rect;
}
GEGLclass::~GEGLclass() {
graph = gegl_node_new();
src = gegl_node_new_child(graph, "operation", "gegl:buffer-source",
"buffer", buffer,
NULL);
sink = gegl_node_new_child(graph, "operation", "gegl:save",
"path", save_path,
NULL);
gegl_node_link_many(src, sink, NULL);
gegl_node_process(sink);
g_object_unref(graph);
g_object_unref(buffer);
g_free(in_buf);
g_free(out_buf);
gegl_exit();
}
void GEGLclass::get_in_out(float **input, float **output) {
in_buf = g_new(float, src_rect.width * src_rect.height * 4);
out_buf = g_new0(float, src_rect.width * src_rect.height * 4);
gegl_buffer_get(buffer, &src_rect, 1.0, format, in_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
*input = in_buf;
*output = out_buf;
}
GeglBuffer* GEGLclass::get_buffer() {
return buffer;
}
int GEGLclass::get_x() {
return x;
}
int GEGLclass::get_y() {
return y;
}
int GEGLclass::get_width() {
return width;
}
int GEGLclass::get_height() {
return height;
}
int GEGLclass::get_pixelcount() {
return pixelcount;
}
void GEGLclass::set_colorformat(const char* string) {
format = babl_format(string);
}
void GEGLclass::do_operation(const char* string) {
graph = gegl_node_new();
src = gegl_node_new_child(graph, "operation", "gegl:buffer-source",
"buffer", buffer,
NULL);
oper = gegl_node_new_child(graph, "operation", string,
NULL);
sink = gegl_node_new_child(graph, "operation", "gegl:write-buffer",
"buffer", buffer,
NULL);
gegl_node_link_many(src, oper, sink, NULL);
gegl_node_process(sink);
g_object_unref(graph);
}
void GEGLclass::set_output() {
gegl_buffer_set(buffer, &src_rect, 0, format, out_buf, GEGL_AUTO_ROWSTRIDE);
}