Colors are sorted by the rearrangement order of their RGB channel values when sorted to increasing order*, or, sorted by hue in which the hue value only stays unchanged if it's a multiple of 60°, and if not, then the value is set to the midpoint between the nearest multiples of 60°.
- Example: [125, 23, 77] would become [2, 0, 1]. 0 when the value is the lowest, 2 when the value is the highest, 1 when neither.
The sort order in this image: 200, 210, 220, 120, 020, 021, 022, 012, 002, 102, 202, 201, 000 (grayscale)
TRIVIA: for each group with only 0s and 2s, they contain 32,640 colors. With all three digits, 2,763,520 colors. For grayscale, 256 colors.