-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimlib.c
More file actions
52 lines (44 loc) · 1.03 KB
/
Copy pathimlib.c
File metadata and controls
52 lines (44 loc) · 1.03 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <Imlib2.h>
#include "imlib.h"
Display *dpy = NULL;
Visual *vis = NULL;
Colormap cmap;
Window root = 0;
Screen *scr = NULL;
void
initx(void)
{
int idx;
dpy = XOpenDisplay(NULL);
if (!dpy) {
fprintf(stderr, "capta: cannot open display\n");
exit(1);
}
idx = DefaultScreen(dpy);
scr = ScreenOfDisplay(dpy, idx);
vis = DefaultVisual(dpy, idx);
cmap = DefaultColormap(dpy, idx);
root = RootWindow(dpy, idx);
imlib_context_set_display(dpy);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cmap);
imlib_context_set_drawable(root);
imlib_context_set_color_modifier(NULL);
imlib_context_set_operation(IMLIB_OP_COPY);
}
void
saveimg(Imlib_Image img, const char *path, int qual)
{
Imlib_Load_Error err;
imlib_context_set_image(img);
imlib_image_attach_data_value("quality", NULL, qual, NULL);
imlib_save_image_with_error_return(path, &err);
if (err) {
fprintf(stderr, "capta: failed to save %s\n", path);
exit(1);
}
}