+ int depth = visual_depth (screen, visual);
+ unsigned long masks;
+ XVisualInfo vi_in, *vi_out;
+
+ /* Find out which bits the R, G, and B components actually occupy
+ on this visual. */
+ vi_in.screen = screen_number (screen);
+ vi_in.visualid = XVisualIDFromVisual (visual);
+ vi_out = XGetVisualInfo (dpy, VisualScreenMask|VisualIDMask,
+ &vi_in, &i);
+ if (! vi_out) abort ();
+ masks = vi_out[0].red_mask | vi_out[0].green_mask | vi_out[0].blue_mask;
+ XFree ((char *) vi_out);
+
+ if (nplanes > depth)
+ nplanes = depth;
+ *nplanesP = nplanes;
+ *base_pixelP = 0;
+ *plane_masks = (unsigned long *) calloc(sizeof(unsigned long), nplanes);
+
+ /* Pick the planar values randomly, but constrain them to fall within
+ the bit positions of the R, G, and B fields. */
+ for (i = 0; i < nplanes; i++)
+ (*plane_masks)[i] = random() & masks;