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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
* Copyright 1990, 1991 by the Massachusetts Institute of Technology and
* UniSoft Group Limited.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the names of MIT and UniSoft not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. MIT and UniSoft
* make no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* $XConsortium$
*/
>>TITLE XGetPixel CH10
unsigned long
XGetPixel(ximage, x, y)
XImage *ximage;
int x;
int y;
>>ASSERTION Good A
When the image
.A ximage
contains coordinates
.A x, y ,
then a call to xname returns the normalised value of the pixel located at
.A x, y
in the image.
>>STRATEGY
For all supported drawables:
Create a drawable.
For a range of pixel values over the drawable's depth:
Set a pixel in the drawable using XDrawPoint.
For XYPixmap and ZPixmap:
Obtain an XImage using XGetImage.
Obtain the pixel value using xname.
Verify that the values are the same.
>>CODE
XVisualInfo *vi;
GC gc;
int npix;
Pixmap pm;
Window win;
int i;
int j;
unsigned long pixel;
unsigned long rpixel;
unsigned long mask;
static int fmats[2] = { XYPixmap, ZPixmap };
x = 2;
y = 1;
for(resetvinf(VI_PIX); nextvinf(&vi);) {
pm = makepixm(Dsp, vi);
gc = makegc(Dsp, pm);
mask = (1<<vi->depth) - 1;
for(i = 0; i <= (15 & mask); i++) {
pixel = mask & (i | i<<4 | i<<12 | i<<20);
XSetForeground(Dsp, gc, pixel);
XDrawPoint(Dsp, pm, gc, x+1, y+2);
for(j=0; j<2; j++) {
ximage = XGetImage(Dsp, pm, 1,2, 2*x,2*y, AllPlanes, fmats[j]);
if( ximage == (XImage *) NULL ) {
delete("XGetImage() returned NULL.");
return;
} else {
rpixel = XCALL;
if(rpixel != pixel) {
report("%s() returned 0x%lx instead of 0x%lx.", TestName, rpixel, pixel);
FAIL;
} else
if(i == 0 && j == 0)
CHECK;
XDestroyImage(ximage);
}
}
}
}
npix = nvinf();
for(resetvinf(VI_WIN); nextvinf(&vi);) {
win = makewin(Dsp, vi);
gc = makegc(Dsp, win);
mask = (1<<vi->depth) - 1;
for(i = 0; i <= (15 & mask); i++) {
pixel = mask & (i | i<<4 | i<<12 | i<<20);
XSetForeground(Dsp, gc, pixel);
XDrawPoint(Dsp, win, gc, x+1, y+2);
for(j=0; j<2; j++) {
ximage = XGetImage(Dsp, win, 1,2, 2*x,2*y, AllPlanes, fmats[j]);
if( ximage == (XImage *) NULL ) {
delete("XGetImage() returned NULL.");
return;
} else {
rpixel = XCALL;
if(rpixel != pixel) {
report("%s() returned 0x%lx instead of 0x%lx.", TestName, rpixel, pixel);
FAIL;
} else
if(i == 0 && j == 0)
CHECK;
XDestroyImage(ximage);
}
}
}
}
CHECKPASS(npix + nvinf());
|