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
|
#define _POSIX_C_SOURCE 200809L
#include "kd_image.h"
#include <stdio.h>
#include <X11/Xutil.h>
typedef struct KDTestImageHandle {
XImage *ximage;
GC clip_mask_gc;
Pixmap clip_mask;
} KDTestImageHandle;
int main(int argc, char **argv)
{
Display *display;
struct nk_image image;
KDTestImageHandle *handle;
Visual *visual;
unsigned long first_pixel;
unsigned long second_pixel;
if (argc != 3) {
(void)fprintf(stderr, "Usage: %s red-green-p3.ppm red-green-p6.ppm\n", argv[0]);
return 2;
}
display = XOpenDisplay(NULL);
if (display == NULL) {
(void)fprintf(stderr, "Could not open DISPLAY.\n");
return 2;
}
image = kd_ppm_load(display, DefaultScreen(display), argv[1], 20U, 20U);
if (image.handle.ptr == NULL || image.w != 2U || image.h != 1U) {
(void)fprintf(stderr, "P3 image failed to load.\n");
XCloseDisplay(display);
return 1;
}
handle = (KDTestImageHandle *)image.handle.ptr;
visual = DefaultVisual(display, DefaultScreen(display));
first_pixel = XGetPixel(handle->ximage, 0, 0);
second_pixel = XGetPixel(handle->ximage, 1, 0);
if ((first_pixel & visual->red_mask) == 0UL ||
(first_pixel & visual->green_mask) != 0UL ||
(second_pixel & visual->green_mask) == 0UL ||
(second_pixel & visual->red_mask) != 0UL) {
(void)fprintf(stderr, "P3 pixel colors were incorrect.\n");
kd_ppm_free(&image);
XCloseDisplay(display);
return 1;
}
kd_ppm_free(&image);
image = kd_ppm_load(display, DefaultScreen(display), argv[2], 20U, 20U);
if (image.handle.ptr == NULL || image.w != 2U || image.h != 1U) {
(void)fprintf(stderr, "P6 image failed to load.\n");
XCloseDisplay(display);
return 1;
}
kd_ppm_free(&image);
XCloseDisplay(display);
(void)puts("PASS: P3/P6 PPM decoding and XImage pixels");
return 0;
}
|