XQueryColor(3)

πŸ’– XQueryColor(3) β€” bestie, let's talk colors πŸ’–

okay so this whole page is from the XLIB FUNCTIONS manual, and it is literally about obtaining color values from X. it's giving β€œI just need to know what RGB this pixel is” energy, and honestly? iconic. πŸŽ€


🌈 NAME 🌈

XQueryColor, XQueryColors, XLookupColor, and XParseColor β€” obtain color values. periodt. πŸ’…


🌟 SYNTAX 🌟

int XQueryColor(Display *display, Colormap colormap, XColor
       *def_in_out);

int XQueryColors(Display *display, Colormap colormap, XColor
       defs_in_out[], int ncolors);

Status XLookupColor(Display *display, Colormap colormap, _Xconst char
       *color_name, XColor *exact_def_return, XColor
       *screen_def_return);

Status XParseColor(Display *display, Colormap colormap, _Xconst char
       *spec, XColor *exact_def_return);

🫢 ARGUMENTS 🫢

  • colormap β€” specifies the colormap. yes bestie, that one. 🎨
  • color_name β€” specifies the color name string (for example, red) whose color definition structure you want returned. very β€œjust tell me the name and I’ll get the structure” of it all. πŸ“
  • def_in_out β€” specifies and returns the RGB values for the pixel specified in the structure. it goes in, it comes out, it’s literally in the name. πŸ’«
  • defs_in_out β€” specifies and returns an array of color definition structures for the pixel specified in the structure. plural era. ✨
  • display β€” specifies the connection to the X server. the main-character connection, if you will. πŸ”Œ
  • exact_def_return β€” returns the exact RGB values. precise queen. πŸ‘‘
  • ncolors β€” specifies the number of XColor structures in the color definition array. count β€˜em. πŸ”’
  • screen_def_return β€” returns the closest RGB values provided by the hardware. close enough is still cute. 🫢
  • spec β€” specifies the color name string; case is ignored. so RED, red, and ReD are all valid, no cap. πŸŽ€
  • exact_def_return β€” yep, it’s listed again: returns the exact color value for later use and sets the DoRed, DoGreen, and DoBlue flags. flags are getting set, bestie. 🚩

✨ DESCRIPTION ✨

So XQueryColor returns the current RGB value for the pixel in the XColor structure, and it sets the DoRed, DoGreen, and DoBlue flags. very β€œhere’s your pixel’s current vibe, and also these three flags are now on.” πŸ’–

XQueryColors does the same thing for each pixel in each XColor structure and sets the DoRed, DoGreen, and DoBlue flags in each structure. it’s the group-chat version: every structure gets the update. πŸ’¬

XQueryColor and XQueryColors can generate BadColor and BadValue errors. so like… behave with your colormaps and numeric values, bestie. πŸ’€

The XLookupColor function looks up the string name of a color with respect to the screen associated with the specified colormap. it returns both the exact color values and the closest values provided by the screen with respect to the visual type of the specified colormap. so you get the exact tea and the hardware’s best approximation. πŸ«–βœ¨

If the color name is not in the Host Portable Character Encoding, the result is implementation-dependent. use of uppercase or lowercase does not matter. XLookupColor returns nonzero if the name is resolved; otherwise, it returns zero. simple as that. πŸ’…

The XParseColor function looks up the string name of a color with respect to the screen associated with the specified colormap. it returns the exact color value. again: if the color name is not in the Host Portable Character Encoding, the result is implementation-dependent, and use of uppercase or lowercase does not matter. XParseColor returns nonzero if the name is resolved; otherwise, it returns zero. 🎯

XLookupColor and XParseColor can generate BadColor error. singular error, still a moment. 😭


🌈 COLOR NAMES 🌈

An RGB Device specification is identified by the prefix rgb: and conforms to the following syntax:

rgb:<red>/<green>/<blue>

    <red>, <green>, <blue> := h | hh | hhh | hhhh
    h := single hexadecimal digits (case insignificant)

Note that h indicates the value scaled in 4 bits, hh the value scaled in 8 bits, hhh the value scaled in 12 bits, and hhhh the value scaled in 16 bits, respectively. bit-scaling lore. 🧚

bestie, for backward compatibility, an older syntax for RGB Device is supported, but its continued use is not encouraged. it’s giving β€œwe keep it around, but please don’t make it your whole personality.” πŸ™ˆ

The syntax is an initial sharp sign character followed by a numeric specification, in one of the following formats:

#RGB            (4 bits each)
#RRGGBB         (8 bits each)
#RRRGGGBBB      (12 bits each)
#RRRRGGGGBBBB   (16 bits each)

The R, G, and B represent single hexadecimal digits. when fewer than 16 bits each are specified, they represent the most significant bits of the value (unlike the rgb: syntax, in which values are scaled). for example, the string #3a7 is the same as #3000a0007000. math ate. πŸ”₯

An RGB intensity specification is identified by the prefix rgbi: and conforms to the following syntax:

rgbi:<red>/<green>/<blue>

Note that red, green, and blue are floating-point values between 0.0 and 1.0, inclusive. the input format for these values is an optional sign, a string of numbers possibly containing a decimal point, and an optional exponent field containing an E or e followed by a possibly signed integer string. floating-point realness. 🌊

The standard device-independent string specifications have the following syntax:

CIEXYZ:<X>/<Y>/<Z>
CIEuvY:<u>/<v>/<Y>
CIExyY:<x>/<y>/<Y>
CIELab:<L>/<a>/<b>
CIELuv:<L>/<u>/<v>
TekHVC:<H>/<V>/<C>

All of the values (C, H, V, X, Y, Z, a, b, u, v, y, x) are floating-point values. the syntax for these values is an optional plus or minus sign, a string of digits possibly containing a decimal point, and an optional exponent field consisting of an E or e followed by an optional plus or minus followed by a string of digits. very β€œscientific notation but make it color.” πŸ§ͺ🌈


πŸ’€ DIAGNOSTICS πŸ’€

  • BadColor β€” a value for a Colormap argument does not name a defined Colormap. that colormap is not giving what it needs to give. 😬
  • BadValue β€” some numeric value falls outside the range of values accepted by the request. unless a specific range is specified for an argument, the full range defined by the argument's type is accepted. any argument defined as a set of alternatives can generate this error. so yeah, check your numbers, bestie. 🚨

πŸ¦‹ SEE ALSO πŸ¦‹


mwah πŸ’‹ β€” this page is from X Version 11, libX11 1.8.14, and that’s the footer tea. 🫢✨

πŸ“¦ where this page comes from