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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
|
/*
Copyright (c) 1990, 1991 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
*
* Copyright 1990, 1991 by 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 name of UniSoft not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. UniSoft
* makes no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* $XConsortium: allcclrpln.m,v 1.7 92/06/11 16:14:43 rws Exp $
*/
>>TITLE XAllocColorPlanes CH05
Status
XAllocColorPlanes(display, colormap, contig, pixels_return, ncolors, nreds, ngreens, nblues, rmask_return, gmask_return, bmask_return)
Display *display = Dsp;
Colormap colormap = DefaultColormap(display, DefaultScreen(display));
Bool contig;
unsigned long *pixels_return = &dummy;
int ncolors = 1;
int nreds;
int ngreens;
int nblues;
unsigned long *rmask_return = &dummy;
unsigned long *gmask_return = &dummy;
unsigned long *bmask_return = &dummy;
>>EXTERN
static unsigned long dummy;
static int contiguous(mask)
unsigned long mask;
{
if(!mask)
return(0L);
while((mask&1) == 0L)
mask>>=1;
mask++;
return( bitcount(mask) == 1);
}
static int maskshift(mask)
unsigned long mask;
{
int i = 0;
if(!mask)
return(0);
while((mask&1) == 0L) {
mask>>=1;
i++;
}
return(i);
}
>>ASSERTION Good A
A call to xname allocates
.A ncolors*2pow(nreds+ngreens+nblues)
read/write colourmap entries whose indices in the colourmap are
obtained by ORing each pixel value returned in the
.A pixels_return
argument
with zero or more of the planes obtained by ORing the masks
returned in the
.A rmask_return ,
.A gmask_return
and
.A bmask_return
arguments.
>>STRATEGY
For visual class DirectColor:
Create a colormap with alloc set to AllocNone.
Allocate one colour and all planes with XAllocColorPlanes.
Verify that the function did not return zero.
Verify the correct number of cells have been allocated by initialising
them with XStoreColors, and reading them with XQueryColors.
>>CODE
XVisualInfo *vp;
unsigned long vmask = (1<<DirectColor);
unsigned long *pixm, *rr, *gr, *br;
unsigned long rm, gm, bm, pm, rgbmask, pixel, r, g, b;
XColor color, qcolor;
Status status;
int cells;
int rshift, gshift, bshift;
if( (vmask = visualsupported(display, vmask)) == 0L) {
tet_result(TET_UNSUPPORTED);
return;
}
resetsupvis(vmask);
nextsupvis(&vp);
colormap = makecolmap(display, vp->visual, AllocNone);
ncolors = 1;
nreds = bitcount(vp->red_mask);
ngreens = bitcount(vp->green_mask);
nblues = bitcount(vp->blue_mask);
cells = ncolors * (1 << (nreds+ngreens+nblues));
contig = False;
pixels_return = ±
rmask_return = &rm;
gmask_return = &gm;
bmask_return = &bm;
status = XCALL;
if(status == (Status) 0) {
report("%s failed to return non-zero", TestName);
FAIL;
} else {
trace("%d cells allocated in the colormap", cells);
CHECK;
}
rgbmask = rm | gm | bm ;
rshift = maskshift(rm);
gshift = maskshift(gm);
bshift = maskshift(bm);
trace("rgbmask is %x", rgbmask);
trace("red shift is %d", rshift);
trace("green shift is %d", gshift);
trace("blue shift is %d", bshift);
/*
* The following code works on the assumption that for each subfield,
* all planes in the subfield mask are allocated (so are contiguous).
*
* (It does not assume the subfields are adjacent)
*/
for(r = 0; r<(1<<nreds); r++) {
pixel = (r<<rshift) | pm;
debug(1, "pixel value %x", pixel);
color.pixel = pixel;
color.flags =DoRed;
color.red = 0xffff;
startcall(display);
XStoreColor(display, colormap, &color);
endcall(display);
if(geterr() != Success) {
report("XStoreColor() failed with pixel value %lu", pixel);
FAIL;
} else {
qcolor.pixel = pixel;
startcall(display);
XQueryColor(display, colormap, &qcolor);
endcall(display);
if(geterr() != Success) {
report("XQueryColor() failed with pixel value %lu", pixel);
FAIL;
} else
CHECK;
}
}
for(g = 0; g<(1<<ngreens); g++) {
pixel = (g<<gshift) | pm;
debug(1, "pixel value %x", pixel);
color.pixel = pixel;
color.flags =DoGreen;
color.green = 0xffff;
startcall(display);
XStoreColor(display, colormap, &color);
endcall(display);
if(geterr() != Success) {
report("XStoreColor() failed with pixel value %lu", pixel);
FAIL;
} else {
qcolor.pixel = pixel;
startcall(display);
XQueryColor(display, colormap, &qcolor);
endcall(display);
if(geterr() != Success) {
report("XQueryColor() failed with pixel value %lu", pixel);
FAIL;
} else
CHECK;
}
}
for(b = 0; b<(1<<nblues); b++) {
pixel = (b<<bshift) | pm;
debug(1, "pixel value %x", pixel);
color.pixel = pixel;
color.flags =DoBlue;
color.blue = 0xffff;
startcall(display);
XStoreColor(display, colormap, &color);
endcall(display);
if(geterr() != Success) {
report("XStoreColor() failed with pixel value %lu", pixel);
FAIL;
} else {
qcolor.pixel = pixel;
startcall(display);
XQueryColor(display, colormap, &qcolor);
endcall(display);
if(geterr() != Success) {
report("XQueryColor() failed with pixel value %lu", pixel);
FAIL;
} else
CHECK;
}
}
CHECKPASS(1 + (1<<nreds) + (1<<ngreens) + (1<<nblues));
>>ASSERTION Good A
A call to xname sets
.A nreds
bits to one in the mask named by
.A rmask_return ,
.A ngreens
bits to one in the mask named by
.A gmask_return ,
and
.A nblues
bits to one in the mask named by
.A bmask_return
and returns
.A ncolors
pixels values in the
.A pixels_return
argument
such that no mask has a bit set in common with
any other mask or with any of the pixels.
>>STRATEGY
For the visual class DirectColor:
Create a colormap with alloc set to AllocNone.
Allocate one colour and all planes with XAllocColorPlanes.
Verify the bitcount of the OR of the colourplane masks equals the
sum of the individual bitcounts.
Verify that the AND of the pixel and the OR of the colourplane masks is zero.
Create a colormap with alloc set to AllocNone.
Allocate 3 colours and 3 planes with XAllocColorPlanes.
Verify the bitcount of the OR of the colourplane masks equals the
sum of the individual bitcounts.
Verify that the AND of each pixel and the OR of the colourplane masks is zero.
>>CODE
XVisualInfo *vp;
unsigned long vmask = (1<<DirectColor);
unsigned long *pixm, *rr, *gr, *br;
unsigned long rm, gm, bm, pm, rgbmask;
unsigned long pm_array[3], i;
Status status;
int cells, rnreds, rngreens, rnblues;
if( (vmask = visualsupported(display, vmask)) == 0L) {
tet_result(TET_UNSUPPORTED);
return;
}
resetsupvis(vmask);
nextsupvis(&vp);
colormap = makecolmap(display, vp->visual, AllocNone);
ncolors = 1;
nreds = bitcount(vp->red_mask);
ngreens = bitcount(vp->green_mask);
nblues = bitcount(vp->blue_mask);
cells = ncolors * (1 << (nreds+ngreens+nblues));
contig = False;
pixels_return = ±
rmask_return = &rm;
gmask_return = &gm;
bmask_return = &bm;
status = XCALL;
if(status == (Status) 0) {
report("%s failed to return non-zero", TestName);
FAIL;
} else {
trace("%d cells allocated in the colormap", cells);
CHECK;
}
rnreds = bitcount(rm);
rngreens = bitcount(gm);
rnblues = bitcount(bm);
if( (rnreds != nreds) || (rngreens != ngreens) || (rnblues != nblues) ) {
report("Request for %d reds %d greens %d blues returned %d reds %d greens %d blues.",
nreds, ngreens, nblues, rnreds, rngreens, rnblues);
FAIL;
} else
CHECK;
rgbmask = rm | gm | bm ;
if( bitcount(rgbmask) != rnreds + rnblues + rngreens) {
report("The returned colourplane masks had at least one shared bit.");
FAIL;
} else
CHECK;
if( (rgbmask & pm) != 0L) {
report("A pixel shared at least one bit with a colourplane.");
FAIL;
} else
CHECK;
/*
* Repeat requesting a number of colours and fewer planes.
*/
colormap = makecolmap(display, vp->visual, AllocNone);
ncolors = 3;
/* Make sure that this visual is big enough to support so many colours */
if (ncolors > bitcount(vp->blue_mask))
ncolors = bitcount(vp->blue_mask);
if (ncolors > bitcount(vp->green_mask))
ncolors = bitcount(vp->green_mask);
if (ncolors > bitcount(vp->red_mask))
ncolors = bitcount(vp->red_mask);
debug(1, "ncolors = %d", ncolors);
nreds = 1;
ngreens = 1;
nblues = 1;
cells = ncolors * (1 << (nreds+ngreens+nblues));
contig = False;
pixels_return = &pm_array[0];
rmask_return = &rm;
gmask_return = &gm;
bmask_return = &bm;
status = XCALL;
if(status == (Status) 0) {
report("%s failed to return non-zero", TestName);
FAIL;
} else {
trace("%d cells allocated in the colormap", cells);
CHECK;
}
rnreds = bitcount(rm);
rngreens = bitcount(gm);
rnblues = bitcount(bm);
if( (rnreds != nreds) || (rngreens != ngreens) || (rnblues != nblues) ) {
report("Request for %d reds %d greens %d blues returned %d reds %d greens %d blues.",
nreds, ngreens, nblues, rnreds, rngreens, rnblues);
FAIL;
} else
CHECK;
rgbmask = rm | gm | bm ;
if( bitcount(rgbmask) != rnreds + rnblues + rngreens) {
report("The returned colourplane masks had at least one shared bit.");
FAIL;
} else
CHECK;
for (i = 0; i < ncolors; i++) {
pm = pm_array[i];
trace("pixel value of 0x%lx", pm);
if( (rgbmask & pm) != 0L) {
report("pixel value %ld shared at least one bit with a colourplane.", pm);
FAIL;
} else
CHECK;
if ((pm & ~DEPTHMASK(vp->depth)) != 0L) {
report("pixel value 0x%lx contained bits outside the depth", pm);
FAIL;
} else
CHECK;
}
CHECKPASS(7+2*ncolors);
>>ASSERTION Good A
If the visual class
.S DirectColor
is supported:
When the visual type of the
.A colormap
argument is
.S DirectColor ,
then
.A rmask_return
lies within the red pixel subfield
and
the
.A gmask_return
lies within the green pixel subfield
and
the
.A bmask_return
lies within the blue pixel subfield.
>>STRATEGY
For the visual class DirectColor:
Create a colormap with alloc set to AllocNone.
Allocate one colour and all planes with XAllocColorPlanes.
Verify that the returned masks and the colour subfield masks are identical.
>>CODE
XVisualInfo *vp;
unsigned long vmask = (1<<DirectColor);
unsigned long *pixm, *rr, *gr, *br;
unsigned long rm, gm, bm, pm, rgbmask, pixel, i;
Status status;
int cells;
if( (vmask = visualsupported(display, vmask)) == 0L) {
tet_result(TET_UNSUPPORTED);
return;
}
resetsupvis(vmask);
nextsupvis(&vp);
colormap = makecolmap(display, vp->visual, AllocNone);
ncolors = 1;
nreds = bitcount(vp->red_mask);
ngreens = bitcount(vp->green_mask);
nblues = bitcount(vp->blue_mask);
cells = ncolors * (1 << (nreds+ngreens+nblues));
contig = False;
pixels_return = ±
rmask_return = &rm;
gmask_return = &gm;
bmask_return = &bm;
status = XCALL;
if(status == (Status) 0) {
report("%s failed to return non-zero", TestName);
FAIL;
} else {
trace("%d cells allocated in the colormap", cells);
CHECK;
}
/*
* We can check the mask returned matches the pixel subfield exactly
* since we requested all planes to be allocated.
*/
if( (vp->red_mask != rm) ) {
report("Returned red mask not contained in red pixel subfield");
FAIL;
} else
CHECK;
if( (vp->green_mask != gm) ) {
report("Returned green mask not contained in green pixel subfield");
FAIL;
} else
CHECK;
if( (vp->blue_mask != bm) ) {
report("Returned blue mask not contained in blue pixel subfield");
FAIL;
} else
CHECK;
CHECKPASS(4);
>>ASSERTION Good A
When the
.A contig
argument is
.S True ,
then
.A rmask_return ,
.A gmask_return
and
.A bmask_return
each contains a contiguous set of bits set to one.
>>STRATEGY
For the visual class DirectColor:
Create a colormap with alloc set to AllocNone.
Allocate one colour and some planes with XAllocColorPlanes and contig = True.
Verify that the returned masks were contiguous.
>>CODE
XVisualInfo *vp;
unsigned long vmask = (1<<DirectColor);
unsigned long *pixm, *rr, *gr, *br;
unsigned long rm, gm, bm, pm, rgbmask, pixel, i;
XColor color;
Status status;
int cells;
if( (vmask = visualsupported(display, vmask)) == 0L) {
tet_result(TET_UNSUPPORTED);
return;
}
resetsupvis(vmask);
nextsupvis(&vp);
colormap = makecolmap(display, vp->visual, AllocNone);
ncolors = 1;
nreds = bitcount(vp->red_mask);
ngreens = bitcount(vp->green_mask);
nblues = bitcount(vp->blue_mask);
cells = ncolors * (1 << (nreds+ngreens+nblues));
contig = True;
pixels_return = ±
rmask_return = &rm;
gmask_return = &gm;
bmask_return = &bm;
/*
* Just ask for a small number of planes if more was possible.
* Originally this test requested all planes - but of course this
* gave little scope for contig to make any difference.
*/
if(nreds > 2)
nreds = 2;
if(ngreens > 2)
ngreens = 2;
if(nblues > 2)
nblues = 2;
trace("test with %d reds %d greens %d blues", nreds, ngreens, nblues);
status = XCALL;
if(status == (Status) 0) {
report("%s failed to return non-zero", TestName);
FAIL;
} else {
trace("%d cells allocated in the colormap", cells);
CHECK;
}
if((contiguous(rm) && contiguous(gm) && contiguous(bm)) == 0) {
report("Returned colourplane masks were not contiguous");
FAIL;
} else
CHECK;
CHECKPASS(2);
>>ASSERTION Bad A
.ER BadColor
>>ASSERTION Bad A
When the
.A ncolors
argument is zero, then a
.S BadValue
error occurs.
>>STRATEGY
For all supported visual classes:
Create a colormap with alloc set to AllocNone.
Call XAllocColorPlanes with ncolors = 0.
>>CODE BadValue
XVisualInfo *vp;
Visual *visual;
unsigned long vmask = (1<<DirectColor);
if( (vmask = visualsupported(display, vmask)) == 0L) {
tet_result(TET_UNSUPPORTED);
return;
}
for(resetsupvis(vmask); nextsupvis(&vp); ) {
colormap = makecolmap(display, vp->visual, AllocNone);
ncolors = 0;
XCALL;
if(geterr() == BadValue)
CHECK;
}
CHECKPASS(nsupvis());
>>ASSERTION Bad A
.ER BadValue contig True False
>>#HISTORY Cal Completed Written in new style and format 4/12/90
>>#HISTORY Cal Action Writing code.
|