Merge remote branch 'origin/7.8'
[mesa.git] / progs / egl / openvg / trivial / readpixels.c
1 #include "eglcommon.h"
2
3 #include <VG/openvg.h>
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <assert.h>
9
10 float red_color[4] = {1.0, 0.0, 0.0, 1.0};
11 float blue_color[4] = {0.0, 0.0, 1.0, 1.0};
12 VGint *data;
13
14 static void
15 init(void)
16 {
17 data = malloc(sizeof(VGint)*2048*2048);
18 }
19
20 /* new window size or exposure */
21 static void
22 reshape(int w, int h)
23 {
24 vgLoadIdentity();
25 }
26
27 static void
28 draw(void)
29 {
30 static const VGint red_pixel = 255 << 24 | 255 << 16 | 0 << 8 | 0;
31 static const VGint blue_pixel = 255 << 24 | 0 << 16 | 0 << 8 | 255;
32 VGint i;
33
34 vgSetfv(VG_CLEAR_COLOR, 4, red_color);
35 vgClear(0, 0, window_width(), window_height());
36 vgFlush();
37
38 memset(data, 0, window_width() * window_height() * sizeof(VGint));
39
40 vgReadPixels(data, window_width() * sizeof(VGint),
41 VG_lARGB_8888,
42 0, 0, window_width(), window_height());
43
44 fprintf(stderr, "Red 0 = 0x%x and at 600 = 0x%x\n",
45 data[0], data[600]);
46 for (i = 0; i < window_width() * window_height(); ++i) {
47 assert(data[i] == red_pixel);
48 }
49
50 vgSetfv(VG_CLEAR_COLOR, 4, blue_color);
51 vgClear(50, 50, 50, 50);
52 vgFlush();
53
54 memset(data, 0, window_width() * window_height() * sizeof(VGint));
55
56 vgReadPixels(data, 50 * sizeof(VGint),
57 VG_lARGB_8888,
58 50, 50, 50, 50);
59
60 fprintf(stderr, "Blue 0 = 0x%x and at 100 = 0x%x\n",
61 data[0], data[100]);
62 for (i = 0; i < 50 * 50; ++i) {
63 assert(data[i] == blue_pixel);
64 }
65 }
66
67
68 int main(int argc, char **argv)
69 {
70 int ret = run(argc, argv, init, reshape,
71 draw, 0);
72
73 free(data);
74 return ret;
75 }