+/* Value is an array of XColor structures for the contents of the
+ color map of frame F. Set *NCELLS to the size of the array.
+ Note that this probably shouldn't be called for large color maps,
+ say a 24-bit TrueColor map. */
+
+static const XColor *
+x_color_cells (f, ncells)
+ struct frame *f;
+ int *ncells;
+{
+ struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+
+ if (dpyinfo->color_cells == NULL)
+ {
+ Display *display = FRAME_X_DISPLAY (f);
+ Screen *screen = FRAME_X_SCREEN (f);
+ int i;
+
+ dpyinfo->ncolor_cells
+ = XDisplayCells (display, XScreenNumberOfScreen (screen));
+ dpyinfo->color_cells
+ = (XColor *) xmalloc (dpyinfo->ncolor_cells
+ * sizeof *dpyinfo->color_cells);
+
+ for (i = 0; i < dpyinfo->ncolor_cells; ++i)
+ dpyinfo->color_cells[i].pixel = i;
+
+ XQueryColors (display, FRAME_X_COLORMAP (f),
+ dpyinfo->color_cells, dpyinfo->ncolor_cells);
+ }
+
+ *ncells = dpyinfo->ncolor_cells;
+ return dpyinfo->color_cells;
+}
+
+
+/* On frame F, translate pixel colors to RGB values for the NCOLORS
+ colors in COLORS. Use cached information, if available. */
+
+void
+x_query_colors (f, colors, ncolors)
+ struct frame *f;
+ XColor *colors;
+ int ncolors;
+{
+ struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+
+ if (dpyinfo->color_cells)
+ {
+ int i;
+ for (i = 0; i < ncolors; ++i)
+ {
+ unsigned long pixel = colors[i].pixel;
+ xassert (pixel < dpyinfo->ncolor_cells);
+ xassert (dpyinfo->color_cells[pixel].pixel == pixel);
+ colors[i] = dpyinfo->color_cells[pixel];
+ }
+ }
+ else
+ XQueryColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), colors, ncolors);
+}
+
+
+/* On frame F, translate pixel color to RGB values for the color in
+ COLOR. Use cached information, if available. */
+
+void
+x_query_color (f, color)
+ struct frame *f;
+ XColor *color;
+{
+ x_query_colors (f, color, 1);
+}
+
+