ANSI 256 Index From RGB
Match encoded RGB by Euclidean channel distance to explicit canonical xterm 256 palette, first-index ties; terminal ANSI 0–15 are theme-dependent, so assigned index may not render the assumed palette on every terminal.
Description
A canonical xterm palette combines 16 base colors, a 216-color cube and 24 grays.
A canonical xterm palette combines 16 base colors, a 216-color cube and 24 grays. Actual terminal themes can change the base entries.1
Enter normalized encoded RGB. Compare all 256 palette entries; cube byte levels are 0,95,135,175,215,255 and gray levels 8+10 i. Return index, palette RGB and distance; exact ties use lowest index.
When to use ANSI 256 Index From RGB
Use ANSI 256 Index From RGB when you need to evaluate the supplied records under the calculation and evidence rules below. No perceptual nearest match or identical rendering across terminal themes is guaranteed.
Prepare colors in the stated color space and scale. Use encoded RGB fractions, linear RGB, Lab, xy, byte values or ink percentages exactly as requested; supply caller tolerances and reference conditions.
How to use ANSI 256 Index From RGB and understand its results
- Prepare colors in the stated color space and scale. Use encoded RGB fractions, linear RGB, Lab, xy, byte values or ink percentages exactly as requested; supply caller tolerances and reference conditions.
- Enter rgbChannels using the field table and calculation rules, then run the tool.
- Read nearestAnsi256Index, nearestPaletteRgb, encodedRgbDistance. The explanation below defines the units, signs, ordering and any flags or placeholder values.
- If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
| Input field | Meaning | Value type; see rules below | Requirement |
|---|---|---|---|
| rgbChannels | Rgb channels | list of number | Required |
Enter normalized encoded RGB. Compare all 256 palette entries; cube byte levels are 0,95,135,175,215,255 and gray levels 8+10 i. Return index, palette RGB and distance; exact ties use lowest index.
nearest=first minimum Euclidean distance in encoded RGB Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.
| Output field | Meaning | Value type |
|---|---|---|
| nearestAnsi256Index | Nearest ansi256 index | number |
| nearestPaletteRgb | Nearest palette rgb | list of number |
| encodedRgbDistance | Encoded rgb distance | number |
{
"input": {
"rgbChannels": [
1,
0,
0
]
},
"output": {
"nearestAnsi256Index": 9,
"nearestPaletteRgb": [
1,
0,
0
],
"encodedRgbDistance": 0
}
} Limitations and assumptions
No perceptual nearest match or identical rendering across terminal themes is guaranteed.
Numeric inputs, where present, must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Numeric lists are limited to 10,000 entries; string lists to 128 strings of at most 128 characters each. The rules above may impose smaller limits. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors.
Alternative or Complementary methods
Use Web-Safe 216 Nearest Index: The legacy web-safe palette is a six-level RGB cube. Channel rounding gives an explicit red-major index. For a complementary task, use E-Ink 16-Level Grayscale Map: Sixteen-level grayscale quantization needs a declared code polarity. Reconstructed gray is independent of that device convention.
References
-
ANSI 256 Index From RGB — tool.io
Similar or alternative tools
- Web-Safe 216 Nearest Index
The legacy web-safe palette is a six-level RGB cube. Channel rounding gives an explicit red-major index.
- E-Ink 16-Level Grayscale Map
Sixteen-level grayscale quantization needs a declared code polarity. Reconstructed gray is independent of that device convention.