color8 0.1.1

Rust port of FastLED colorutils — CRGB/CHSV pixel types, HSV/RGB conversion, blending and gradients for embedded LED programming
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
//! `CrgbPalette16`/`32`/`256`, `ChsvPalette16`/`32`/`256`, `ColorFromPalette`,
//! `nblendPaletteTowardPalette` and `UpscalePalette` — direct port of the
//! palette logic in
//! FastLED 3.6.0's `colorutils.cpp`, transcribed from the actual
//! 3.6.0-tagged source (`github.com/FastLED/FastLED`, tag `3.6.0`). Only
//! the RAM-backed palette overloads are ported — not the
//! `TProgmemRGBPalette*` ones, which color8 has no analogue of.
//!
//! Brightness handling is transcribed exactly as FastLED has it, and it is
//! *not* uniform across these six functions:
//! - `CrgbPalette16`/`32`: `brightness == 0` forces black; otherwise plain
//!   `scale8(x, brightness + 1)` (not `scale8_video`).
//! - `CrgbPalette256`: `scale8_video(x, brightness + 1)` — no
//!   `brightness == 0` special case, unlike the 16/32-entry versions.
//! - `ChsvPalette16`/`32`/`256`: only `val` is brightness-scaled, via plain
//!   `scale8_video(val, brightness)` — no "+1" rounding adjustment, unlike
//!   the `Crgb` versions.
//!
//! `LinearBlendNoWrap` rescales the index via FastLED's `map8(index, 0, N)`,
//! which reduces to `scale8(index, N)`. `N` is 239 for the 16-entry
//! palettes and 247 for the 32-entry ones — *not* 240/248: `scale8`'s
//! internal `+1` means `scale8(index, N)` can reach up to `N`, and landing
//! exactly on the last entry (with no fractional remainder) requires `N` to
//! be one less than the "obvious" `240`/`248`.

use lib8tion::{Fract8, scale8, scale8_video};

use crate::hsv::Chsv;
use crate::rgb::Crgb;

/// How the 16- and 32-entry `color_from_palette*` functions blend between
/// adjacent palette entries. FastLED's `TBlendType`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ColorBlend {
    /// No interpolation: step to the nearest lower entry.
    NoBlend,
    /// Linearly interpolate between entries, wrapping from the last entry
    /// back to the first as the index crosses 255 -> 0.
    LinearBlend,
    /// Linearly interpolate between entries, but rescale the index first so
    /// that the top of the range lands exactly on the last entry instead of
    /// blending toward a wrapped-around entry 0.
    LinearBlendNoWrap,
}

/// A 16-entry RGB color palette, indexed by a `u8` via
/// [`color_from_palette16`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CrgbPalette16(pub [Crgb; 16]);

/// A 32-entry RGB color palette, indexed by a `u8` via
/// [`color_from_palette32`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CrgbPalette32(pub [Crgb; 32]);

/// A 256-entry RGB color palette: one entry per possible `u8` index, so
/// [`color_from_palette256`] never interpolates.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CrgbPalette256(pub [Crgb; 256]);

/// A 16-entry HSV color palette, indexed by a `u8` via
/// [`color_from_palette16_hsv`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ChsvPalette16(pub [Chsv; 16]);

/// A 32-entry HSV color palette, indexed by a `u8` via
/// [`color_from_palette32_hsv`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ChsvPalette32(pub [Chsv; 32]);

/// A 256-entry HSV color palette: one entry per possible `u8` index, so
/// [`color_from_palette256_hsv`] never interpolates.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ChsvPalette256(pub [Chsv; 256]);

impl CrgbPalette16 {
    /// Builds a palette from its 16 entries.
    #[inline]
    pub const fn new(entries: [Crgb; 16]) -> Self {
        Self(entries)
    }
}

impl CrgbPalette32 {
    /// Builds a palette from its 32 entries.
    #[inline]
    pub const fn new(entries: [Crgb; 32]) -> Self {
        Self(entries)
    }
}

impl CrgbPalette256 {
    /// Builds a palette from its 256 entries.
    #[inline]
    pub const fn new(entries: [Crgb; 256]) -> Self {
        Self(entries)
    }
}

impl ChsvPalette16 {
    /// Builds a palette from its 16 entries.
    #[inline]
    pub const fn new(entries: [Chsv; 16]) -> Self {
        Self(entries)
    }
}

impl ChsvPalette32 {
    /// Builds a palette from its 32 entries.
    #[inline]
    pub const fn new(entries: [Chsv; 32]) -> Self {
        Self(entries)
    }
}

impl ChsvPalette256 {
    /// Builds a palette from its 256 entries.
    #[inline]
    pub const fn new(entries: [Chsv; 256]) -> Self {
        Self(entries)
    }
}

macro_rules! impl_index {
    ($ty:ty, $entry:ty) => {
        impl core::ops::Index<usize> for $ty {
            type Output = $entry;
            #[inline]
            fn index(&self, i: usize) -> &$entry {
                &self.0[i]
            }
        }
    };
}

impl_index!(CrgbPalette16, Crgb);
impl_index!(CrgbPalette32, Crgb);
impl_index!(CrgbPalette256, Crgb);
impl_index!(ChsvPalette16, Chsv);
impl_index!(ChsvPalette32, Chsv);
impl_index!(ChsvPalette256, Chsv);

/// Blends between `entries[hi]` and its (possibly wrapped-around) neighbor
/// by `f2/255`, per FastLED's `scale8_LEAVING_R1_DIRTY` pair-sum. On the
/// portable-C path that primitive is bit-identical to plain `scale8`; the
/// `_LEAVING_R1_DIRTY` naming only matters for an AVR register-zeroing step.
#[inline]
fn interpolate_rgb(entries: &[Crgb], hi: usize, f2: u8, blend: ColorBlend) -> Crgb {
    let e0 = entries[hi];
    if blend == ColorBlend::NoBlend || f2 == 0 {
        return e0;
    }

    let next = if hi + 1 == entries.len() { 0 } else { hi + 1 };
    let e1 = entries[next];
    let f1 = 255 - f2;

    // FastLED assigns the two scale8 terms' sum back into a uint8_t, which
    // truncates rather than saturates.
    Crgb::new(
        scale8(e0.r, Fract8(f1)).wrapping_add(scale8(e1.r, Fract8(f2))),
        scale8(e0.g, Fract8(f1)).wrapping_add(scale8(e1.g, Fract8(f2))),
        scale8(e0.b, Fract8(f1)).wrapping_add(scale8(e1.b, Fract8(f2))),
    )
}

/// Applies a `CrgbPalette16`/`32` ColorFromPalette's brightness stage:
/// `brightness == 0` forces black, otherwise plain `scale8(x, brightness+1)`.
#[inline]
fn apply_brightness_rgb(mut entry: Crgb, brightness: u8) -> Crgb {
    if brightness == 255 {
        return entry;
    }
    if brightness == 0 {
        return Crgb::new(0, 0, 0);
    }
    let b2 = brightness + 1;
    entry.r = scale8(entry.r, Fract8(b2));
    entry.g = scale8(entry.g, Fract8(b2));
    entry.b = scale8(entry.b, Fract8(b2));
    entry
}

/// `ColorFromPalette` against a 16-entry RGB palette.
pub fn color_from_palette16(
    pal: &CrgbPalette16,
    mut index: u8,
    brightness: u8,
    blend: ColorBlend,
) -> Crgb {
    if blend == ColorBlend::LinearBlendNoWrap {
        index = scale8(index, Fract8(239));
    }

    let hi4 = (index >> 4) as usize;
    let lo4 = index & 0x0F;
    let f2 = lo4 << 4;

    let entry = interpolate_rgb(&pal.0, hi4, f2, blend);
    apply_brightness_rgb(entry, brightness)
}

/// `ColorFromPalette` against a 32-entry RGB palette.
pub fn color_from_palette32(
    pal: &CrgbPalette32,
    mut index: u8,
    brightness: u8,
    blend: ColorBlend,
) -> Crgb {
    if blend == ColorBlend::LinearBlendNoWrap {
        index = scale8(index, Fract8(247));
    }

    let hi5 = (index >> 3) as usize;
    let lo3 = index & 0x07;
    let f2 = lo3 << 5;

    let entry = interpolate_rgb(&pal.0, hi5, f2, blend);
    apply_brightness_rgb(entry, brightness)
}

/// `ColorFromPalette` against a 256-entry RGB palette. Every index maps to
/// exactly one entry, so there is nothing to interpolate between.
pub fn color_from_palette256(pal: &CrgbPalette256, index: u8, brightness: u8) -> Crgb {
    let mut entry = pal.0[index as usize];
    if brightness != 255 {
        let b2 = brightness + 1;
        entry.r = scale8_video(entry.r, Fract8(b2));
        entry.g = scale8_video(entry.g, Fract8(b2));
        entry.b = scale8_video(entry.b, Fract8(b2));
    }
    entry
}

/// Blends `entries[hi]` toward its (possibly wrapped-around) neighbor by
/// `f2/255`. Saturation and value blend like RGB channels; hue blends along
/// the shorter of the two directions around the 8-bit hue wheel, and
/// black/white entries (`sat == 0` or `val == 0`) adopt the other entry's
/// hue first, since they have no hue of their own.
#[inline]
fn interpolate_hsv(entries: &[Chsv], hi: usize, f2: u8, blend: ColorBlend) -> Chsv {
    let e0 = entries[hi];
    if blend == ColorBlend::NoBlend || f2 == 0 {
        return e0;
    }

    let next = if hi + 1 == entries.len() { 0 } else { hi + 1 };
    let e1 = entries[next];
    let f1 = 255 - f2;

    let mut hue1 = e0.hue;
    let mut hue2 = e1.hue;
    if e0.sat == 0 || e0.val == 0 {
        hue1 = hue2;
    }
    if e1.sat == 0 || e1.val == 0 {
        hue2 = hue1;
    }

    let sat = scale8(e0.sat, Fract8(f1)).wrapping_add(scale8(e1.sat, Fract8(f2)));
    let val = scale8(e0.val, Fract8(f1)).wrapping_add(scale8(e1.val, Fract8(f2)));

    let deltahue = hue2.wrapping_sub(hue1);
    let hue = if deltahue & 0x80 != 0 {
        let reverse_delta = (256u16 - deltahue as u16) as u8;
        hue1.wrapping_sub(scale8(reverse_delta, Fract8(f2)))
    } else {
        hue1.wrapping_add(scale8(deltahue, Fract8(f2)))
    };

    Chsv::new(hue, sat, val)
}

/// `ColorFromPalette` against a 16-entry HSV palette.
pub fn color_from_palette16_hsv(
    pal: &ChsvPalette16,
    mut index: u8,
    brightness: u8,
    blend: ColorBlend,
) -> Chsv {
    if blend == ColorBlend::LinearBlendNoWrap {
        index = scale8(index, Fract8(239));
    }

    let hi4 = (index >> 4) as usize;
    let lo4 = index & 0x0F;
    let f2 = lo4 << 4;

    let mut entry = interpolate_hsv(&pal.0, hi4, f2, blend);
    if brightness != 255 {
        entry.val = scale8_video(entry.val, Fract8(brightness));
    }
    entry
}

/// `ColorFromPalette` against a 32-entry HSV palette.
pub fn color_from_palette32_hsv(
    pal: &ChsvPalette32,
    mut index: u8,
    brightness: u8,
    blend: ColorBlend,
) -> Chsv {
    if blend == ColorBlend::LinearBlendNoWrap {
        index = scale8(index, Fract8(247));
    }

    let hi5 = (index >> 3) as usize;
    let lo3 = index & 0x07;
    let f2 = lo3 << 5;

    let mut entry = interpolate_hsv(&pal.0, hi5, f2, blend);
    if brightness != 255 {
        entry.val = scale8_video(entry.val, Fract8(brightness));
    }
    entry
}

/// `ColorFromPalette` against a 256-entry HSV palette. Every index maps to
/// exactly one entry, so there is nothing to interpolate between.
pub fn color_from_palette256_hsv(pal: &ChsvPalette256, index: u8, brightness: u8) -> Chsv {
    let mut entry = pal.0[index as usize];
    if brightness != 255 {
        entry.val = scale8_video(entry.val, Fract8(brightness));
    }
    entry
}

/// A lookup a [`fill_palette`]/[`fill_palette_circular`] can drive — the
/// generic `PALETTE` template parameter FastLED's own `fill_palette`
/// functions take, made concrete per palette type. `Crgb` palettes ignore
/// `blend` for the 256-entry size (matching [`color_from_palette256`],
/// which has no blend parameter at all: every index already has its own
/// entry, so there is nothing to blend).
pub trait Palette {
    /// The pixel type this palette produces.
    type Entry: Copy;

    /// Looks up one color, exactly as the matching `color_from_palette*`
    /// free function would.
    fn color_from_palette(&self, index: u8, brightness: u8, blend: ColorBlend) -> Self::Entry;
}

impl Palette for CrgbPalette16 {
    type Entry = Crgb;
    #[inline]
    fn color_from_palette(&self, index: u8, brightness: u8, blend: ColorBlend) -> Crgb {
        color_from_palette16(self, index, brightness, blend)
    }
}

impl Palette for CrgbPalette32 {
    type Entry = Crgb;
    #[inline]
    fn color_from_palette(&self, index: u8, brightness: u8, blend: ColorBlend) -> Crgb {
        color_from_palette32(self, index, brightness, blend)
    }
}

impl Palette for CrgbPalette256 {
    type Entry = Crgb;
    #[inline]
    fn color_from_palette(&self, index: u8, brightness: u8, _blend: ColorBlend) -> Crgb {
        color_from_palette256(self, index, brightness)
    }
}

impl Palette for ChsvPalette16 {
    type Entry = Chsv;
    #[inline]
    fn color_from_palette(&self, index: u8, brightness: u8, blend: ColorBlend) -> Chsv {
        color_from_palette16_hsv(self, index, brightness, blend)
    }
}

impl Palette for ChsvPalette32 {
    type Entry = Chsv;
    #[inline]
    fn color_from_palette(&self, index: u8, brightness: u8, blend: ColorBlend) -> Chsv {
        color_from_palette32_hsv(self, index, brightness, blend)
    }
}

impl Palette for ChsvPalette256 {
    type Entry = Chsv;
    #[inline]
    fn color_from_palette(&self, index: u8, brightness: u8, _blend: ColorBlend) -> Chsv {
        color_from_palette256_hsv(self, index, brightness)
    }
}

/// Fills `leds` with a run of palette entries: `leds[0]` is
/// `pal[start_index]`, and the palette index advances by `inc_index`
/// (wrapping) for every subsequent pixel.
pub fn fill_palette<P: Palette>(
    leds: &mut [P::Entry],
    start_index: u8,
    inc_index: u8,
    pal: &P,
    brightness: u8,
    blend: ColorBlend,
) {
    let mut color_index = start_index;
    for led in leds.iter_mut() {
        *led = pal.color_from_palette(color_index, brightness, blend);
        color_index = color_index.wrapping_add(inc_index);
    }
}

/// Fills `leds` with the whole palette spread evenly across the slice, so
/// the last pixel is followed by the first as if the palette wrapped
/// around — unlike [`fill_palette`], the per-pixel index step is derived
/// from `leds.len()` rather than given, so the palette always covers the
/// full slice regardless of how many pixels there are. Set `reversed` to
/// walk the palette backwards.
pub fn fill_palette_circular<P: Palette>(
    leds: &mut [P::Entry],
    start_index: u8,
    pal: &P,
    brightness: u8,
    blend: ColorBlend,
    reversed: bool,
) {
    if leds.is_empty() {
        return; // avoid div/0
    }

    // Palette-index change per pixel, kept at 8 extra bits of precision.
    let color_change = 65535u16 / leds.len() as u16;
    let mut color_index = (start_index as u16) << 8;

    for led in leds.iter_mut() {
        *led = pal.color_from_palette((color_index >> 8) as u8, brightness, blend);
        if reversed {
            color_index = color_index.wrapping_sub(color_change);
        } else {
            color_index = color_index.wrapping_add(color_change);
        }
    }
}

/// Moves `current` a small step toward `target` — FastLED's
/// `nblendPaletteTowardPalette`.
///
/// The palettes are walked as 48 channel bytes (`r`, `g`, `b` of each entry,
/// in order). A byte below its target goes up by one; a byte above goes down
/// by one, then by one more if it is still above. Either counts as one
/// change, and the walk stops once `max_changes` changes have been made, so
/// later bytes wait for a later call. Calling this repeatedly — once per
/// frame, say — crossfades one palette into another; a larger budget
/// crossfades faster.
///
/// As in FastLED, the budget is checked only after a change, so a
/// `max_changes` of `0` still makes one.
pub fn nblend_palette_toward_palette(
    current: &mut CrgbPalette16,
    target: &CrgbPalette16,
    max_changes: u8,
) {
    let mut changes: u8 = 0;
    for (cur, tgt) in current.0.iter_mut().zip(target.0.iter()) {
        for (channel, goal) in [
            (&mut cur.r, tgt.r),
            (&mut cur.g, tgt.g),
            (&mut cur.b, tgt.b),
        ] {
            if *channel == goal {
                continue;
            }
            if *channel < goal {
                *channel += 1;
                changes += 1;
            }
            if *channel > goal {
                *channel -= 1;
                changes += 1;
                if *channel > goal {
                    *channel -= 1;
                }
            }
            if changes >= max_changes {
                return;
            }
        }
    }
}

/// Upscales a 16-entry palette to 256 entries — FastLED's `UpscalePalette`,
/// also behind [`From<CrgbPalette16>`](CrgbPalette256#impl-From%3CCrgbPalette16%3E-for-CrgbPalette256).
///
/// Entry `i` is [`color_from_palette16`] at index `i` with FastLED's default
/// arguments: full brightness and [`ColorBlend::LinearBlend`].
pub fn upscale_palette16_to_256(pal: &CrgbPalette16) -> CrgbPalette256 {
    CrgbPalette256(core::array::from_fn(|i| {
        color_from_palette16(pal, i as u8, 255, ColorBlend::LinearBlend)
    }))
}

/// Upscales a 16-entry palette to 32 entries — FastLED's `UpscalePalette`,
/// also behind [`From<CrgbPalette16>`](CrgbPalette32#impl-From%3CCrgbPalette16%3E-for-CrgbPalette32).
///
/// Each entry is copied into two adjacent slots, *not* interpolated — that is
/// what FastLED does for this pair of sizes, unlike its 256-entry upscales.
pub fn upscale_palette16_to_32(pal: &CrgbPalette16) -> CrgbPalette32 {
    CrgbPalette32(core::array::from_fn(|i| pal.0[i / 2]))
}

/// Upscales a 32-entry palette to 256 entries — FastLED's `UpscalePalette`,
/// also behind [`From<CrgbPalette32>`](CrgbPalette256#impl-From%3CCrgbPalette32%3E-for-CrgbPalette256).
///
/// Entry `i` is [`color_from_palette32`] at index `i`, full brightness,
/// [`ColorBlend::LinearBlend`].
pub fn upscale_palette32_to_256(pal: &CrgbPalette32) -> CrgbPalette256 {
    CrgbPalette256(core::array::from_fn(|i| {
        color_from_palette32(pal, i as u8, 255, ColorBlend::LinearBlend)
    }))
}

/// [`upscale_palette16_to_256`] for HSV palettes, via
/// [`color_from_palette16_hsv`].
pub fn upscale_palette16_to_256_hsv(pal: &ChsvPalette16) -> ChsvPalette256 {
    ChsvPalette256(core::array::from_fn(|i| {
        color_from_palette16_hsv(pal, i as u8, 255, ColorBlend::LinearBlend)
    }))
}

/// [`upscale_palette16_to_32`] for HSV palettes: each entry copied into two
/// slots.
pub fn upscale_palette16_to_32_hsv(pal: &ChsvPalette16) -> ChsvPalette32 {
    ChsvPalette32(core::array::from_fn(|i| pal.0[i / 2]))
}

/// [`upscale_palette32_to_256`] for HSV palettes, via
/// [`color_from_palette32_hsv`].
pub fn upscale_palette32_to_256_hsv(pal: &ChsvPalette32) -> ChsvPalette256 {
    ChsvPalette256(core::array::from_fn(|i| {
        color_from_palette32_hsv(pal, i as u8, 255, ColorBlend::LinearBlend)
    }))
}

impl From<CrgbPalette16> for CrgbPalette256 {
    /// See [`upscale_palette16_to_256`].
    fn from(pal: CrgbPalette16) -> Self {
        upscale_palette16_to_256(&pal)
    }
}

impl From<CrgbPalette16> for CrgbPalette32 {
    /// See [`upscale_palette16_to_32`].
    fn from(pal: CrgbPalette16) -> Self {
        upscale_palette16_to_32(&pal)
    }
}

impl From<CrgbPalette32> for CrgbPalette256 {
    /// See [`upscale_palette32_to_256`].
    fn from(pal: CrgbPalette32) -> Self {
        upscale_palette32_to_256(&pal)
    }
}

impl From<ChsvPalette16> for ChsvPalette256 {
    /// See [`upscale_palette16_to_256_hsv`].
    fn from(pal: ChsvPalette16) -> Self {
        upscale_palette16_to_256_hsv(&pal)
    }
}

impl From<ChsvPalette16> for ChsvPalette32 {
    /// See [`upscale_palette16_to_32_hsv`].
    fn from(pal: ChsvPalette16) -> Self {
        upscale_palette16_to_32_hsv(&pal)
    }
}

impl From<ChsvPalette32> for ChsvPalette256 {
    /// See [`upscale_palette32_to_256_hsv`].
    fn from(pal: ChsvPalette32) -> Self {
        upscale_palette32_to_256_hsv(&pal)
    }
}