@@ -20,11 +20,11 @@ void full_screen(void) {
20
20
Display * display ;
21
21
Window screen , root ;
22
22
XWindowAttributes gwa ;
23
- XImage * image ;
23
+ XImage * ximage ;
24
24
int left , top ;
25
25
unsigned int x , y , width , height , offset ;
26
26
unsigned long allplanes , pixel ;
27
- unsigned char * pixels ;
27
+ unsigned char * pixels , * addr ;
28
28
29
29
gettimeofday (& start , NULL );
30
30
@@ -37,7 +37,7 @@ void full_screen(void) {
37
37
width = gwa .width ;
38
38
height = gwa .height ;
39
39
allplanes = XAllPlanes ();
40
- image = XGetImage (display , root , left , top , width , height , allplanes , ZPixmap );
40
+ ximage = XGetImage (display , root , left , top , width , height , allplanes , ZPixmap );
41
41
pixels = malloc (sizeof (unsigned char ) * width * height * 3 );
42
42
43
43
/*printf("display = %d\n", display);
@@ -48,51 +48,37 @@ void full_screen(void) {
48
48
printf("width = %d\n", width);
49
49
printf("height = %d\n", height);
50
50
printf("allplanes = %u\n", allplanes);
51
- printf("bits_per_pixel = %d\n", image ->bits_per_pixel);
52
- printf("bytes_per_line = %d\n", image ->bytes_per_line);
53
- printf("depth = %d\n", image ->depth);
51
+ printf("bits_per_pixel = %d\n", ximage ->bits_per_pixel);
52
+ printf("bytes_per_line = %d\n", ximage ->bytes_per_line);
53
+ printf("depth = %d\n", ximage ->depth);
54
54
*/
55
55
56
56
// Processus habituel
57
57
for ( x = 0 ; x < width ; ++ x ) {
58
58
for ( y = 0 ; y < height ; ++ y ) {
59
- pixel = XGetPixel (image , x , y );
59
+ pixel = XGetPixel (ximage , x , y );
60
60
offset = width * y * 3 ;
61
- pixels [x * 3 + offset ] = (pixel & image -> red_mask ) >> 16 ;
62
- pixels [x * 3 + offset + 1 ] = (pixel & image -> green_mask ) >> 8 ;
63
- pixels [x * 3 + offset + 2 ] = pixel & image -> blue_mask ;
61
+ pixels [x * 3 + offset ] = (pixel & ximage -> red_mask ) >> 16 ;
62
+ pixels [x * 3 + offset + 1 ] = (pixel & ximage -> green_mask ) >> 8 ;
63
+ pixels [x * 3 + offset + 2 ] = pixel & ximage -> blue_mask ;
64
64
}
65
65
}
66
66
67
- // Processus sans passer par XGetPixel (pas vraiment mieux... )
67
+ // Processus sans passer par XGetPixel (ça se vaut )
68
68
/*
69
- unsigned int shift = 0xffffffff;
70
- if ( image->depth == 24 ) {
71
- shift = 0x00ffffff;
72
- }
73
- unsigned long px;
74
- register char *src, *dst;
75
- register int i, j;
76
69
for ( x = 0; x < width; ++x ) {
77
70
for ( y = 0; y < height; ++y ) {
78
- offset = (y * image->bytes_per_line + ((x * image->bits_per_pixel) >> 3)) + 4;
79
- src = &image->data[offset];
80
- dst = (char*)&px;
81
- px = 0;
82
- for ( i = (image->bits_per_pixel + 7) >> 3; --i >= 0; )
83
- *dst++ = *src++;
84
- pixel = 0;
85
- for ( i = sizeof(unsigned long); --i >= 0; )
86
- pixel = (pixel << 8) | ((unsigned char *)&px)[i];
87
71
offset = width * y * 3;
88
- pixels[x * 3 + offset] = (pixel & image->red_mask) >> 16;
89
- pixels[x * 3 + offset + 1] = (pixel & image->green_mask) >> 8;
90
- pixels[x * 3 + offset + 2] = pixel & image->blue_mask;
72
+ addr = &(ximage->data)[y * ximage->bytes_per_line + (x << 2)];
73
+ pixel = addr[3] << 24 | addr[2] << 16 | addr[1] << 8 | addr[0];
74
+ pixels[x * 3 + offset] = (pixel & ximage->red_mask) >> 16;
75
+ pixels[x * 3 + offset + 1] = (pixel & ximage->green_mask) >> 8;
76
+ pixels[x * 3 + offset + 2] = pixel & ximage->blue_mask;
91
77
}
92
78
}
93
79
*/
94
80
95
- XDestroyImage (image );
81
+ XDestroyImage (ximage );
96
82
XCloseDisplay (display );
97
83
98
84
gettimeofday (& end , NULL );
@@ -110,8 +96,7 @@ void each_screen(void) {
110
96
Window root ;
111
97
XRRScreenResources * monitors ;
112
98
XRRCrtcInfo * crtc_info ;
113
- XWindowAttributes gwa ;
114
- XImage * image ;
99
+ XImage * ximage ;
115
100
int left , top ;
116
101
unsigned int n , x , y , width , height , offset ;
117
102
unsigned long allplanes , pixel ;
@@ -132,25 +117,24 @@ void each_screen(void) {
132
117
printf(" mode = %d\n", crtc_info->mode);
133
118
printf(" rotation = %d\n", crtc_info->rotation);*/
134
119
135
- XGetWindowAttributes (display , root , & gwa );
136
120
left = crtc_info -> x ;
137
121
top = crtc_info -> y ;
138
122
width = crtc_info -> width ;
139
123
height = crtc_info -> height ;
140
124
allplanes = XAllPlanes ();
141
- image = XGetImage (display , root , left , top , width , height , allplanes , ZPixmap );
125
+ ximage = XGetImage (display , root , left , top , width , height , allplanes , ZPixmap );
142
126
pixels = malloc (sizeof (unsigned char ) * width * height * 3 );
143
127
144
128
for ( x = 0 ; x < width ; ++ x ) {
145
129
for ( y = 0 ; y < height ; ++ y ) {
146
- pixel = XGetPixel (image , x , y );
147
130
offset = width * y * 3 ;
148
- pixels [x * 3 + offset ] = (pixel & image -> red_mask ) >> 16 ;
149
- pixels [x * 3 + offset + 1 ] = (pixel & image -> green_mask ) >> 8 ;
150
- pixels [x * 3 + offset + 2 ] = pixel & image -> blue_mask ;
131
+ pixel = XGetPixel (ximage , x , y );
132
+ pixels [x * 3 + offset ] = (pixel & ximage -> red_mask ) >> 16 ;
133
+ pixels [x * 3 + offset + 1 ] = (pixel & ximage -> green_mask ) >> 8 ;
134
+ pixels [x * 3 + offset + 2 ] = pixel & ximage -> blue_mask ;
151
135
}
152
136
}
153
- XDestroyImage (image );
137
+ XDestroyImage (ximage );
154
138
XRRFreeCrtcInfo (crtc_info );
155
139
156
140
gettimeofday (& end , NULL );
0 commit comments