Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High Bit Depth Gamma Correction Algorithm for APA102/Dotstar LEDs #1545

Closed
zackees opened this issue Sep 28, 2023 · 3 comments
Closed

High Bit Depth Gamma Correction Algorithm for APA102/Dotstar LEDs #1545

zackees opened this issue Sep 28, 2023 · 3 comments

Comments

@zackees
Copy link
Member

zackees commented Sep 28, 2023

High Bit Depth Gamma Correction Algorithm for APA102/Dotstar LEDs

This algorithm gamma corrects into 16 bit then bit shifts against the global brightness then converts back into 8,8,8,5 space.

This gives an additional 5 bits of precision at the low end.

IMG_1274_mute_small.mp4
@zackees zackees changed the title APA102 / Dotstar Gamma Bit shifting gamma correction formula High Bit Depth Algorithm for APA102/Dotstar LEDs Sep 28, 2023
@zackees
Copy link
Member Author

zackees commented Sep 28, 2023

Algorithm

void five_bit_hd_gamma_bitshift(
    uint8_t r8, uint8_t g8, uint8_t b8,
    uint8_t* out_r8,
    uint8_t* out_g8,
    uint8_t* out_b8,
    uint8_t* out_power_5bit) {

    // Step 1: Gamma Correction
    uint16_t r16, g16, b16;
    five_bit_hd_gamma_function(r8, g8, b8, &r16, &g16, &b16);

    // Step 2: Initialize 5-bit brightness.
    // Note: we only get 5 levels of brightness
    uint8_t v8 = 31;

    uint16_t numerator = 1;
    uint16_t denominator = 1;
    const uint32_t r16_const = r16;
    const uint32_t g16_const = g16;
    const uint32_t b16_const = b16;

    // Step 3: Bit Shifting Loop, can probably replaced with a
    // single pass bit-twiddling hack.
    do {
        // Note that to avoid slow divisions, we multiply the max_value
        // by the denominator.
        uint32_t max_value = 0xfffful * 15;
        if (r16_const * 31 > max_value) {
          break;
        }
        if (g16_const * 31 > max_value) {
          break;
        }
        if (b16_const * 31 > max_value) {
          break;
        }
        numerator = 31;
        denominator = 15;
        v8 = 15;

        max_value = 0xfffful * 15 * 7;
        if (r16_const * 31 * 15 > max_value) {
          break;
        }
        if (g16_const * 31 * 15 > max_value) {
          break;
        }
        if (b16_const * 31 * 15 > max_value) {
          break;
        }
        numerator = 31 * 15;
        denominator = 15 * 7;
        v8 = 7;

        max_value = 0xfffful * 15 * 7 * 3;
        if (r16_const * 31 * 15 * 7 > max_value) {
          break;
        }
        if (g16_const * 31 * 15 * 7 > max_value) {
          break;
        }
        if (b16_const * 31 * 15 * 7 > max_value) {
          break;
        }
        numerator = 31 * 15 * 7;
        denominator = 15 * 7 * 3;
        v8 = 3;

        max_value = 0xfffful * 15 * 7 * 3;
        if (r16_const * 31 * 15 * 7 * 3 > max_value) {
          break;
        }
        if (g16_const * 31 * 15 * 7 * 3 > max_value) {
          break;
        }
        if (b16_const * 31 * 15 * 7 * 3 > max_value) {
          break;
        }
        numerator = 31 * 15 * 7 * 3;
        v8 = 1;
    } while(false);

    r16 = uint16_t(r16_const * numerator / denominator);
    g16 = uint16_t(g16_const * numerator / denominator);
    b16 = uint16_t(b16_const * numerator / denominator);

    // Step 4: Conversion Back to 8-bit.
    uint8_t r8_final = (r8 == 255 && uint8_t(r16 >> 8) >= 254) ? 255 : uint8_t(r16 >> 8);
    uint8_t g8_final = (g8 == 255 && uint8_t(g16 >> 8) >= 254) ? 255 : uint8_t(g16 >> 8);
    uint8_t b8_final = (b8 == 255 && uint8_t(b16 >> 8) >= 254) ? 255 : uint8_t(b16 >> 8);

#if FASTLED_FIVE_BIT_HD_GAMMA_LOW_END_LINEAR_RAMP == 1
    if (v8 == 1) {
      // Linear tuning for the lowest possible brightness. x=y until
      // the intersection point at 9.
      if (r8 < 9 && r16 > 0) {
        r8_final = r8;
      }
      if (g8 < 9 && g16 > 0) {
        g8_final = g8;
      }
      if (b8 < 9 && b16 > 0) {
        b8_final = b8;
      }
    }
#endif

    // Step 5: Output
    *out_r8 = r8_final;
    *out_g8 = g8_final;
    *out_b8 = b8_final;
    *out_power_5bit = v8;
}

Output

Input RGB: (0, 0, 0)
Output RGBV (Gamma corrected): (0, 0, 0, v: 1)
max component power: 0
-----------------------------
Input RGB: (1, 0, 0)
Output RGBV (Gamma corrected): (1, 0, 0, v: 1)
max component power: 0.0322581
-----------------------------
Input RGB: (2, 0, 0)
Output RGBV (Gamma corrected): (2, 0, 0, v: 1)
max component power: 0.0645161
-----------------------------
Input RGB: (3, 0, 0)
Output RGBV (Gamma corrected): (3, 0, 0, v: 1)
max component power: 0.0967742
-----------------------------
Input RGB: (4, 0, 0)
Output RGBV (Gamma corrected): (4, 0, 0, v: 1)
max component power: 0.129032
-----------------------------
Input RGB: (5, 0, 0)
Output RGBV (Gamma corrected): (5, 0, 0, v: 1)
max component power: 0.16129
-----------------------------
Input RGB: (6, 0, 0)
Output RGBV (Gamma corrected): (6, 0, 0, v: 1)
max component power: 0.193548
-----------------------------
Input RGB: (7, 0, 0)
Output RGBV (Gamma corrected): (7, 0, 0, v: 1)
max component power: 0.225806
-----------------------------
Input RGB: (8, 0, 0)
Output RGBV (Gamma corrected): (8, 0, 0, v: 1)
max component power: 0.258065
-----------------------------
Input RGB: (9, 0, 0)
Output RGBV (Gamma corrected): (9, 0, 0, v: 1)
max component power: 0.290323
-----------------------------
Input RGB: (10, 0, 0)
Output RGBV (Gamma corrected): (12, 0, 0, v: 1)
max component power: 0.387097
-----------------------------
Input RGB: (11, 0, 0)
Output RGBV (Gamma corrected): (14, 0, 0, v: 1)
max component power: 0.451613
-----------------------------
Input RGB: (12, 0, 0)
Output RGBV (Gamma corrected): (17, 0, 0, v: 1)
max component power: 0.548387
-----------------------------
Input RGB: (13, 0, 0)
Output RGBV (Gamma corrected): (20, 0, 0, v: 1)
max component power: 0.645161
-----------------------------
Input RGB: (14, 0, 0)
Output RGBV (Gamma corrected): (23, 0, 0, v: 1)
max component power: 0.741935
-----------------------------
Input RGB: (15, 0, 0)
Output RGBV (Gamma corrected): (27, 0, 0, v: 1)
max component power: 0.870968
-----------------------------
Input RGB: (16, 0, 0)
Output RGBV (Gamma corrected): (31, 0, 0, v: 1)
max component power: 1
-----------------------------
Input RGB: (17, 0, 0)
Output RGBV (Gamma corrected): (34, 0, 0, v: 1)
max component power: 1.09677
-----------------------------
Input RGB: (18, 0, 0)
Output RGBV (Gamma corrected): (39, 0, 0, v: 1)
max component power: 1.25806
-----------------------------
Input RGB: (19, 0, 0)
Output RGBV (Gamma corrected): (43, 0, 0, v: 1)
max component power: 1.3871
-----------------------------
Input RGB: (20, 0, 0)
Output RGBV (Gamma corrected): (48, 0, 0, v: 1)
max component power: 1.54839
-----------------------------
Input RGB: (21, 0, 0)
Output RGBV (Gamma corrected): (53, 0, 0, v: 1)
max component power: 1.70968
-----------------------------
Input RGB: (22, 0, 0)
Output RGBV (Gamma corrected): (58, 0, 0, v: 1)
max component power: 1.87097
-----------------------------
Input RGB: (23, 0, 0)
Output RGBV (Gamma corrected): (64, 0, 0, v: 1)
max component power: 2.06452
-----------------------------
Input RGB: (24, 0, 0)
Output RGBV (Gamma corrected): (69, 0, 0, v: 1)
max component power: 2.22581
-----------------------------
Input RGB: (25, 0, 0)
Output RGBV (Gamma corrected): (75, 0, 0, v: 1)
max component power: 2.41935
-----------------------------
Input RGB: (26, 0, 0)
Output RGBV (Gamma corrected): (81, 0, 0, v: 1)
max component power: 2.6129
-----------------------------
Input RGB: (27, 0, 0)
Output RGBV (Gamma corrected): (88, 0, 0, v: 1)
max component power: 2.83871
-----------------------------
Input RGB: (28, 0, 0)
Output RGBV (Gamma corrected): (94, 0, 0, v: 1)
max component power: 3.03226
-----------------------------
Input RGB: (29, 0, 0)
Output RGBV (Gamma corrected): (101, 0, 0, v: 1)
max component power: 3.25806
-----------------------------
Input RGB: (30, 0, 0)
Output RGBV (Gamma corrected): (108, 0, 0, v: 1)
max component power: 3.48387
-----------------------------
Input RGB: (31, 0, 0)
Output RGBV (Gamma corrected): (116, 0, 0, v: 1)
max component power: 3.74194
-----------------------------
Input RGB: (32, 0, 0)
Output RGBV (Gamma corrected): (124, 0, 0, v: 1)
max component power: 4
-----------------------------
Input RGB: (33, 0, 0)
Output RGBV (Gamma corrected): (131, 0, 0, v: 1)
max component power: 4.22581
-----------------------------
Input RGB: (34, 0, 0)
Output RGBV (Gamma corrected): (139, 0, 0, v: 1)
max component power: 4.48387
-----------------------------
Input RGB: (35, 0, 0)
Output RGBV (Gamma corrected): (148, 0, 0, v: 1)
max component power: 4.77419
-----------------------------
Input RGB: (36, 0, 0)
Output RGBV (Gamma corrected): (156, 0, 0, v: 1)
max component power: 5.03226
-----------------------------
Input RGB: (37, 0, 0)
Output RGBV (Gamma corrected): (165, 0, 0, v: 1)
max component power: 5.32258
-----------------------------
Input RGB: (38, 0, 0)
Output RGBV (Gamma corrected): (174, 0, 0, v: 1)
max component power: 5.6129
-----------------------------
Input RGB: (39, 0, 0)
Output RGBV (Gamma corrected): (184, 0, 0, v: 1)
max component power: 5.93548
-----------------------------
Input RGB: (40, 0, 0)
Output RGBV (Gamma corrected): (193, 0, 0, v: 1)
max component power: 6.22581
-----------------------------
Input RGB: (41, 0, 0)
Output RGBV (Gamma corrected): (203, 0, 0, v: 1)
max component power: 6.54839
-----------------------------
Input RGB: (42, 0, 0)
Output RGBV (Gamma corrected): (213, 0, 0, v: 1)
max component power: 6.87097
-----------------------------
Input RGB: (43, 0, 0)
Output RGBV (Gamma corrected): (223, 0, 0, v: 1)
max component power: 7.19355
-----------------------------
Input RGB: (44, 0, 0)
Output RGBV (Gamma corrected): (234, 0, 0, v: 1)
max component power: 7.54839
-----------------------------
Input RGB: (45, 0, 0)
Output RGBV (Gamma corrected): (245, 0, 0, v: 1)
max component power: 7.90323
-----------------------------
Input RGB: (46, 0, 0)
Output RGBV (Gamma corrected): (85, 0, 0, v: 3)
max component power: 8.22581
-----------------------------
Input RGB: (47, 0, 0)
Output RGBV (Gamma corrected): (89, 0, 0, v: 3)
max component power: 8.6129
-----------------------------
Input RGB: (48, 0, 0)
Output RGBV (Gamma corrected): (93, 0, 0, v: 3)
max component power: 9
-----------------------------
Input RGB: (49, 0, 0)
Output RGBV (Gamma corrected): (96, 0, 0, v: 3)
max component power: 9.29032
-----------------------------
Input RGB: (50, 0, 0)
Output RGBV (Gamma corrected): (100, 0, 0, v: 3)
max component power: 9.67742
-----------------------------
Input RGB: (51, 0, 0)
Output RGBV (Gamma corrected): (104, 0, 0, v: 3)
max component power: 10.0645
-----------------------------
Input RGB: (52, 0, 0)
Output RGBV (Gamma corrected): (109, 0, 0, v: 3)
max component power: 10.5484
-----------------------------
Input RGB: (53, 0, 0)
Output RGBV (Gamma corrected): (113, 0, 0, v: 3)
max component power: 10.9355
-----------------------------
Input RGB: (54, 0, 0)
Output RGBV (Gamma corrected): (117, 0, 0, v: 3)
max component power: 11.3226
-----------------------------
Input RGB: (55, 0, 0)
Output RGBV (Gamma corrected): (122, 0, 0, v: 3)
max component power: 11.8065
-----------------------------
Input RGB: (56, 0, 0)
Output RGBV (Gamma corrected): (126, 0, 0, v: 3)
max component power: 12.1935
-----------------------------
Input RGB: (57, 0, 0)
Output RGBV (Gamma corrected): (131, 0, 0, v: 3)
max component power: 12.6774
-----------------------------
Input RGB: (58, 0, 0)
Output RGBV (Gamma corrected): (135, 0, 0, v: 3)
max component power: 13.0645
-----------------------------
Input RGB: (59, 0, 0)
Output RGBV (Gamma corrected): (140, 0, 0, v: 3)
max component power: 13.5484
-----------------------------
Input RGB: (60, 0, 0)
Output RGBV (Gamma corrected): (145, 0, 0, v: 3)
max component power: 14.0323
-----------------------------
Input RGB: (61, 0, 0)
Output RGBV (Gamma corrected): (150, 0, 0, v: 3)
max component power: 14.5161
-----------------------------
Input RGB: (62, 0, 0)
Output RGBV (Gamma corrected): (155, 0, 0, v: 3)
max component power: 15
-----------------------------
Input RGB: (63, 0, 0)
Output RGBV (Gamma corrected): (160, 0, 0, v: 3)
max component power: 15.4839
-----------------------------
Input RGB: (64, 0, 0)
Output RGBV (Gamma corrected): (165, 0, 0, v: 3)
max component power: 15.9677
-----------------------------
Input RGB: (65, 0, 0)
Output RGBV (Gamma corrected): (170, 0, 0, v: 3)
max component power: 16.4516
-----------------------------
Input RGB: (66, 0, 0)
Output RGBV (Gamma corrected): (175, 0, 0, v: 3)
max component power: 16.9355
-----------------------------
Input RGB: (67, 0, 0)
Output RGBV (Gamma corrected): (181, 0, 0, v: 3)
max component power: 17.5161
-----------------------------
Input RGB: (68, 0, 0)
Output RGBV (Gamma corrected): (186, 0, 0, v: 3)
max component power: 18
-----------------------------
Input RGB: (69, 0, 0)
Output RGBV (Gamma corrected): (192, 0, 0, v: 3)
max component power: 18.5806
-----------------------------
Input RGB: (70, 0, 0)
Output RGBV (Gamma corrected): (197, 0, 0, v: 3)
max component power: 19.0645
-----------------------------
Input RGB: (71, 0, 0)
Output RGBV (Gamma corrected): (203, 0, 0, v: 3)
max component power: 19.6452
-----------------------------
Input RGB: (72, 0, 0)
Output RGBV (Gamma corrected): (209, 0, 0, v: 3)
max component power: 20.2258
-----------------------------
Input RGB: (73, 0, 0)
Output RGBV (Gamma corrected): (215, 0, 0, v: 3)
max component power: 20.8065
-----------------------------Input RGB: (74, 0, 0)
Output RGBV (Gamma corrected): (221, 0, 0, v: 3)
max component power: 21.3871
-----------------------------
Input RGB: (75, 0, 0)
Output RGBV (Gamma corrected): (227, 0, 0, v: 3)
max component power: 21.9677
-----------------------------
Input RGB: (76, 0, 0)
Output RGBV (Gamma corrected): (233, 0, 0, v: 3)
max component power: 22.5484
-----------------------------
Input RGB: (77, 0, 0)
Output RGBV (Gamma corrected): (239, 0, 0, v: 3)
max component power: 23.129
-----------------------------
Input RGB: (78, 0, 0)
Output RGBV (Gamma corrected): (245, 0, 0, v: 3)
max component power: 23.7097
-----------------------------
Input RGB: (79, 0, 0)
Output RGBV (Gamma corrected): (251, 0, 0, v: 3)
max component power: 24.2903
-----------------------------
Input RGB: (80, 0, 0)
Output RGBV (Gamma corrected): (110, 0, 0, v: 7)
max component power: 24.8387
-----------------------------
Input RGB: (81, 0, 0)
Output RGBV (Gamma corrected): (113, 0, 0, v: 7)
max component power: 25.5161
-----------------------------
Input RGB: (82, 0, 0)
Output RGBV (Gamma corrected): (116, 0, 0, v: 7)
max component power: 26.1935
-----------------------------
Input RGB: (83, 0, 0)
Output RGBV (Gamma corrected): (119, 0, 0, v: 7)
max component power: 26.871
-----------------------------
Input RGB: (84, 0, 0)
Output RGBV (Gamma corrected): (122, 0, 0, v: 7)
max component power: 27.5484
-----------------------------
Input RGB: (85, 0, 0)
Output RGBV (Gamma corrected): (124, 0, 0, v: 7)
max component power: 28
-----------------------------
Input RGB: (86, 0, 0)
Output RGBV (Gamma corrected): (127, 0, 0, v: 7)
max component power: 28.6774
-----------------------------
Input RGB: (87, 0, 0)
Output RGBV (Gamma corrected): (130, 0, 0, v: 7)
max component power: 29.3548
-----------------------------
Input RGB: (88, 0, 0)
Output RGBV (Gamma corrected): (133, 0, 0, v: 7)
max component power: 30.0323
-----------------------------
Input RGB: (89, 0, 0)
Output RGBV (Gamma corrected): (137, 0, 0, v: 7)
max component power: 30.9355
-----------------------------
Input RGB: (90, 0, 0)
Output RGBV (Gamma corrected): (140, 0, 0, v: 7)
max component power: 31.6129
-----------------------------
Input RGB: (91, 0, 0)
Output RGBV (Gamma corrected): (143, 0, 0, v: 7)
max component power: 32.2903
-----------------------------
Input RGB: (92, 0, 0)
Output RGBV (Gamma corrected): (146, 0, 0, v: 7)
max component power: 32.9677
-----------------------------
Input RGB: (93, 0, 0)
Output RGBV (Gamma corrected): (149, 0, 0, v: 7)
max component power: 33.6452
-----------------------------
Input RGB: (94, 0, 0)
Output RGBV (Gamma corrected): (152, 0, 0, v: 7)
max component power: 34.3226
-----------------------------
Input RGB: (95, 0, 0)
Output RGBV (Gamma corrected): (156, 0, 0, v: 7)
max component power: 35.2258
-----------------------------
Input RGB: (96, 0, 0)
Output RGBV (Gamma corrected): (159, 0, 0, v: 7)
max component power: 35.9032
-----------------------------
Input RGB: (97, 0, 0)
Output RGBV (Gamma corrected): (162, 0, 0, v: 7)
max component power: 36.5806
-----------------------------
Input RGB: (98, 0, 0)
Output RGBV (Gamma corrected): (166, 0, 0, v: 7)
max component power: 37.4839
-----------------------------
Input RGB: (99, 0, 0)
Output RGBV (Gamma corrected): (169, 0, 0, v: 7)
max component power: 38.1613
-----------------------------
Input RGB: (100, 0, 0)
Output RGBV (Gamma corrected): (172, 0, 0, v: 7)
max component power: 38.8387
-----------------------------
Input RGB: (101, 0, 0)
Output RGBV (Gamma corrected): (176, 0, 0, v: 7)
max component power: 39.7419
-----------------------------
Input RGB: (102, 0, 0)
Output RGBV (Gamma corrected): (179, 0, 0, v: 7)
max component power: 40.4194
-----------------------------
Input RGB: (103, 0, 0)
Output RGBV (Gamma corrected): (183, 0, 0, v: 7)
max component power: 41.3226
-----------------------------
Input RGB: (104, 0, 0)
Output RGBV (Gamma corrected): (187, 0, 0, v: 7)
max component power: 42.2258
-----------------------------
Input RGB: (105, 0, 0)
Output RGBV (Gamma corrected): (190, 0, 0, v: 7)
max component power: 42.9032
-----------------------------
Input RGB: (106, 0, 0)
Output RGBV (Gamma corrected): (194, 0, 0, v: 7)
max component power: 43.8064
-----------------------------
Input RGB: (107, 0, 0)
Output RGBV (Gamma corrected): (198, 0, 0, v: 7)
max component power: 44.7097
-----------------------------
Input RGB: (108, 0, 0)
Output RGBV (Gamma corrected): (201, 0, 0, v: 7)
max component power: 45.3871
-----------------------------
Input RGB: (109, 0, 0)
Output RGBV (Gamma corrected): (205, 0, 0, v: 7)
max component power: 46.2903
-----------------------------
Input RGB: (110, 0, 0)
Output RGBV (Gamma corrected): (209, 0, 0, v: 7)
max component power: 47.1936
-----------------------------
Input RGB: (111, 0, 0)
Output RGBV (Gamma corrected): (213, 0, 0, v: 7)
max component power: 48.0968
-----------------------------
Input RGB: (112, 0, 0)
Output RGBV (Gamma corrected): (217, 0, 0, v: 7)
max component power: 49
-----------------------------
Input RGB: (113, 0, 0)
Output RGBV (Gamma corrected): (220, 0, 0, v: 7)
max component power: 49.6774
-----------------------------
Input RGB: (114, 0, 0)
Output RGBV (Gamma corrected): (224, 0, 0, v: 7)
max component power: 50.5806
-----------------------------
Input RGB: (115, 0, 0)
Output RGBV (Gamma corrected): (228, 0, 0, v: 7)
max component power: 51.4839
-----------------------------
Input RGB: (116, 0, 0)
Output RGBV (Gamma corrected): (232, 0, 0, v: 7)
max component power: 52.3871
-----------------------------
Input RGB: (117, 0, 0)
Output RGBV (Gamma corrected): (236, 0, 0, v: 7)
max component power: 53.2903
-----------------------------
Input RGB: (118, 0, 0)
Output RGBV (Gamma corrected): (240, 0, 0, v: 7)
max component power: 54.1936
-----------------------------
Input RGB: (119, 0, 0)
Output RGBV (Gamma corrected): (244, 0, 0, v: 7)
max component power: 55.0968
-----------------------------
Input RGB: (120, 0, 0)
Output RGBV (Gamma corrected): (249, 0, 0, v: 7)
max component power: 56.2258
-----------------------------
Input RGB: (121, 0, 0)
Output RGBV (Gamma corrected): (253, 0, 0, v: 7)
max component power: 57.129
-----------------------------
Input RGB: (122, 0, 0)
Output RGBV (Gamma corrected): (120, 0, 0, v: 15)
max component power: 58.0645
-----------------------------
Input RGB: (123, 0, 0)
Output RGBV (Gamma corrected): (122, 0, 0, v: 15)
max component power: 59.0323
-----------------------------
Input RGB: (124, 0, 0)
Output RGBV (Gamma corrected): (124, 0, 0, v: 15)
max component power: 60
-----------------------------
Input RGB: (125, 0, 0)
Output RGBV (Gamma corrected): (126, 0, 0, v: 15)
max component power: 60.9677
-----------------------------
Input RGB: (126, 0, 0)
Output RGBV (Gamma corrected): (128, 0, 0, v: 15)
max component power: 61.9355
-----------------------------
Input RGB: (127, 0, 0)
Output RGBV (Gamma corrected): (130, 0, 0, v: 15)
max component power: 62.9032
-----------------------------
Input RGB: (128, 0, 0)
Output RGBV (Gamma corrected): (132, 0, 0, v: 15)
max component power: 63.871
-----------------------------
Input RGB: (129, 0, 0)
Output RGBV (Gamma corrected): (134, 0, 0, v: 15)
max component power: 64.8387
-----------------------------
Input RGB: (130, 0, 0)
Output RGBV (Gamma corrected): (136, 0, 0, v: 15)
max component power: 65.8064
-----------------------------
Input RGB: (131, 0, 0)
Output RGBV (Gamma corrected): (138, 0, 0, v: 15)
max component power: 66.7742
-----------------------------
Input RGB: (132, 0, 0)
Output RGBV (Gamma corrected): (140, 0, 0, v: 15)
max component power: 67.7419
-----------------------------
Input RGB: (133, 0, 0)
Output RGBV (Gamma corrected): (142, 0, 0, v: 15)
max component power: 68.7097
-----------------------------
Input RGB: (134, 0, 0)
Output RGBV (Gamma corrected): (144, 0, 0, v: 15)
max component power: 69.6774
-----------------------------
Input RGB: (135, 0, 0)
Output RGBV (Gamma corrected): (147, 0, 0, v: 15)
max component power: 71.129
-----------------------------
Input RGB: (136, 0, 0)
Output RGBV (Gamma corrected): (149, 0, 0, v: 15)
max component power: 72.0968
-----------------------------
Input RGB: (137, 0, 0)
Output RGBV (Gamma corrected): (151, 0, 0, v: 15)
max component power: 73.0645
-----------------------------
Input RGB: (138, 0, 0)
Output RGBV (Gamma corrected): (153, 0, 0, v: 15)
max component power: 74.0323
-----------------------------
Input RGB: (139, 0, 0)
Output RGBV (Gamma corrected): (155, 0, 0, v: 15)
max component power: 75
-----------------------------
Input RGB: (140, 0, 0)
Output RGBV (Gamma corrected): (158, 0, 0, v: 15)
max component power: 76.4516
-----------------------------
Input RGB: (141, 0, 0)
Output RGBV (Gamma corrected): (160, 0, 0, v: 15)
max component power: 77.4194
-----------------------------
Input RGB: (142, 0, 0)
Output RGBV (Gamma corrected): (162, 0, 0, v: 15)
max component power: 78.3871
-----------------------------
Input RGB: (143, 0, 0)
Output RGBV (Gamma corrected): (165, 0, 0, v: 15)
max component power: 79.8387
-----------------------------
Input RGB: (144, 0, 0)
Output RGBV (Gamma corrected): (167, 0, 0, v: 15)
max component power: 80.8064
-----------------------------
Input RGB: (145, 0, 0)
Output RGBV (Gamma corrected): (169, 0, 0, v: 15)
max component power: 81.7742
-----------------------------
Input RGB: (146, 0, 0)
Output RGBV (Gamma corrected): (172, 0, 0, v: 15)
max component power: 83.2258
-----------------------------
Input RGB: (147, 0, 0)
Output RGBV (Gamma corrected): (174, 0, 0, v: 15)
max component power: 84.1936
-----------------------------
Input RGB: (148, 0, 0)
Output RGBV (Gamma corrected): (176, 0, 0, v: 15)
max component power: 85.1613
-----------------------------
Input RGB: (149, 0, 0)
Output RGBV (Gamma corrected): (179, 0, 0, v: 15)
max component power: 86.6129
-----------------------------
Input RGB: (150, 0, 0)
Output RGBV (Gamma corrected): (181, 0, 0, v: 15)
max component power: 87.5806
-----------------------------
Input RGB: (151, 0, 0)
Output RGBV (Gamma corrected): (184, 0, 0, v: 15)
max component power: 89.0323
-----------------------------
Input RGB: (152, 0, 0)
Output RGBV (Gamma corrected): (186, 0, 0, v: 15)
max component power: 90
-----------------------------
Input RGB: (153, 0, 0)
Output RGBV (Gamma corrected): (188, 0, 0, v: 15)
max component power: 90.9677
-----------------------------
Input RGB: (154, 0, 0)
Output RGBV (Gamma corrected): (191, 0, 0, v: 15)
max component power: 92.4194
-----------------------------
Input RGB: (155, 0, 0)
Output RGBV (Gamma corrected): (193, 0, 0, v: 15)
max component power: 93.3871
-----------------------------
Input RGB: (156, 0, 0)
Output RGBV (Gamma corrected): (196, 0, 0, v: 15)
max component power: 94.8387
-----------------------------
Input RGB: (157, 0, 0)
Output RGBV (Gamma corrected): (198, 0, 0, v: 15)
max component power: 95.8064
-----------------------------
Input RGB: (158, 0, 0)
Output RGBV (Gamma corrected): (201, 0, 0, v: 15)
max component power: 97.2581
-----------------------------
Input RGB: (159, 0, 0)Output RGBV (Gamma corrected): (204, 0, 0, v: 15)
max component power: 98.7097
-----------------------------
Input RGB: (160, 0, 0)
Output RGBV (Gamma corrected): (206, 0, 0, v: 15)
max component power: 99.6774
-----------------------------
Input RGB: (161, 0, 0)
Output RGBV (Gamma corrected): (209, 0, 0, v: 15)
max component power: 101.129
-----------------------------
Input RGB: (162, 0, 0)
Output RGBV (Gamma corrected): (211, 0, 0, v: 15)
max component power: 102.097
-----------------------------
Input RGB: (163, 0, 0)
Output RGBV (Gamma corrected): (214, 0, 0, v: 15)
max component power: 103.548
-----------------------------
Input RGB: (164, 0, 0)
Output RGBV (Gamma corrected): (217, 0, 0, v: 15)
max component power: 105
-----------------------------
Input RGB: (165, 0, 0)
Output RGBV (Gamma corrected): (219, 0, 0, v: 15)
max component power: 105.968
-----------------------------
Input RGB: (166, 0, 0)
Output RGBV (Gamma corrected): (222, 0, 0, v: 15)
max component power: 107.419
-----------------------------
Input RGB: (167, 0, 0)
Output RGBV (Gamma corrected): (225, 0, 0, v: 15)
max component power: 108.871
-----------------------------
Input RGB: (168, 0, 0)
Output RGBV (Gamma corrected): (227, 0, 0, v: 15)
max component power: 109.839
-----------------------------
Input RGB: (169, 0, 0)
Output RGBV (Gamma corrected): (230, 0, 0, v: 15)
max component power: 111.29
-----------------------------Input RGB: (170, 0, 0)
Output RGBV (Gamma corrected): (233, 0, 0, v: 15)
max component power: 112.742
-----------------------------
Input RGB: (171, 0, 0)
Output RGBV (Gamma corrected): (236, 0, 0, v: 15)
max component power: 114.194
-----------------------------
Input RGB: (172, 0, 0)
Output RGBV (Gamma corrected): (238, 0, 0, v: 15)
max component power: 115.161
-----------------------------
Input RGB: (173, 0, 0)
Output RGBV (Gamma corrected): (241, 0, 0, v: 15)
max component power: 116.613
-----------------------------
Input RGB: (174, 0, 0)
Output RGBV (Gamma corrected): (244, 0, 0, v: 15)
max component power: 118.065
-----------------------------
Input RGB: (175, 0, 0)
Output RGBV (Gamma corrected): (247, 0, 0, v: 15)
max component power: 119.516
-----------------------------
Input RGB: (176, 0, 0)
Output RGBV (Gamma corrected): (250, 0, 0, v: 15)
max component power: 120.968
-----------------------------
Input RGB: (177, 0, 0)
Output RGBV (Gamma corrected): (252, 0, 0, v: 15)
max component power: 121.935
-----------------------------
Input RGB: (178, 0, 0)
Output RGBV (Gamma corrected): (255, 0, 0, v: 15)
max component power: 123.387
-----------------------------
Input RGB: (179, 0, 0)
Output RGBV (Gamma corrected): (125, 0, 0, v: 31)
max component power: 125
-----------------------------
Input RGB: (180, 0, 0)
Output RGBV (Gamma corrected): (126, 0, 0, v: 31)
max component power: 126
-----------------------------
Input RGB: (181, 0, 0)
Output RGBV (Gamma corrected): (127, 0, 0, v: 31)
max component power: 127
-----------------------------
Input RGB: (182, 0, 0)
Output RGBV (Gamma corrected): (129, 0, 0, v: 31)
max component power: 129
-----------------------------
Input RGB: (183, 0, 0)
Output RGBV (Gamma corrected): (130, 0, 0, v: 31)
max component power: 130
-----------------------------
Input RGB: (184, 0, 0)
Output RGBV (Gamma corrected): (132, 0, 0, v: 31)
max component power: 132
-----------------------------
Input RGB: (185, 0, 0)
Output RGBV (Gamma corrected): (133, 0, 0, v: 31)
max component power: 133
-----------------------------
Input RGB: (186, 0, 0)
Output RGBV (Gamma corrected): (135, 0, 0, v: 31)
max component power: 135
-----------------------------
Input RGB: (187, 0, 0)
Output RGBV (Gamma corrected): (136, 0, 0, v: 31)
max component power: 136
-----------------------------
Input RGB: (188, 0, 0)
Output RGBV (Gamma corrected): (138, 0, 0, v: 31)
max component power: 138
-----------------------------
Input RGB: (189, 0, 0)
Output RGBV (Gamma corrected): (139, 0, 0, v: 31)
max component power: 139
-----------------------------
Input RGB: (190, 0, 0)
Output RGBV (Gamma corrected): (141, 0, 0, v: 31)
max component power: 141
-----------------------------
Input RGB: (191, 0, 0)
Output RGBV (Gamma corrected): (142, 0, 0, v: 31)
max component power: 142
-----------------------------
Input RGB: (192, 0, 0)
Output RGBV (Gamma corrected): (144, 0, 0, v: 31)
max component power: 144
-----------------------------
Input RGB: (193, 0, 0)
Output RGBV (Gamma corrected): (145, 0, 0, v: 31)
max component power: 145
-----------------------------
Input RGB: (194, 0, 0)
Output RGBV (Gamma corrected): (147, 0, 0, v: 31)
max component power: 147
-----------------------------
Input RGB: (195, 0, 0)
Output RGBV (Gamma corrected): (148, 0, 0, v: 31)
max component power: 148
-----------------------------
Input RGB: (196, 0, 0)
Output RGBV (Gamma corrected): (150, 0, 0, v: 31)
max component power: 150
-----------------------------
Input RGB: (197, 0, 0)
Output RGBV (Gamma corrected): (151, 0, 0, v: 31)
max component power: 151
-----------------------------
Input RGB: (198, 0, 0)
Output RGBV (Gamma corrected): (153, 0, 0, v: 31)
max component power: 153
-----------------------------
Input RGB: (199, 0, 0)
Output RGBV (Gamma corrected): (154, 0, 0, v: 31)
max component power: 154
-----------------------------
Input RGB: (200, 0, 0)
Output RGBV (Gamma corrected): (156, 0, 0, v: 31)
max component power: 156
-----------------------------
Input RGB: (201, 0, 0)
Output RGBV (Gamma corrected): (157, 0, 0, v: 31)
max component power: 157
-----------------------------
Input RGB: (202, 0, 0)
Output RGBV (Gamma corrected): (159, 0, 0, v: 31)
max component power: 159
-----------------------------
Input RGB: (203, 0, 0)
Output RGBV (Gamma corrected): (160, 0, 0, v: 31)
max component power: 160
-----------------------------
Input RGB: (204, 0, 0)
Output RGBV (Gamma corrected): (162, 0, 0, v: 31)
max component power: 162
-----------------------------
Input RGB: (205, 0, 0)
Output RGBV (Gamma corrected): (164, 0, 0, v: 31)
max component power: 164
-----------------------------
Input RGB: (206, 0, 0)
Output RGBV (Gamma corrected): (165, 0, 0, v: 31)
max component power: 165
-----------------------------
Input RGB: (207, 0, 0)
Output RGBV (Gamma corrected): (167, 0, 0, v: 31)
max component power: 167
-----------------------------
Input RGB: (208, 0, 0)
Output RGBV (Gamma corrected): (169, 0, 0, v: 31)
max component power: 169
-----------------------------
Input RGB: (209, 0, 0)
Output RGBV (Gamma corrected): (170, 0, 0, v: 31)
max component power: 170
-----------------------------
Input RGB: (210, 0, 0)
Output RGBV (Gamma corrected): (172, 0, 0, v: 31)
max component power: 172
-----------------------------
Input RGB: (211, 0, 0)
Output RGBV (Gamma corrected): (173, 0, 0, v: 31)
max component power: 173
-----------------------------
Input RGB: (212, 0, 0)
Output RGBV (Gamma corrected): (175, 0, 0, v: 31)
max component power: 175
-----------------------------
Input RGB: (213, 0, 0)
Output RGBV (Gamma corrected): (177, 0, 0, v: 31)
max component power: 177
-----------------------------
Input RGB: (214, 0, 0)
Output RGBV (Gamma corrected): (178, 0, 0, v: 31)
max component power: 178
-----------------------------
Input RGB: (215, 0, 0)
Output RGBV (Gamma corrected): (180, 0, 0, v: 31)
max component power: 180
-----------------------------
Input RGB: (216, 0, 0)
Output RGBV (Gamma corrected): (182, 0, 0, v: 31)
max component power: 182
-----------------------------
Input RGB: (217, 0, 0)
Output RGBV (Gamma corrected): (183, 0, 0, v: 31)
max component power: 183
-----------------------------
Input RGB: (218, 0, 0)
Output RGBV (Gamma corrected): (185, 0, 0, v: 31)
max component power: 185
-----------------------------
Input RGB: (219, 0, 0)
Output RGBV (Gamma corrected): (187, 0, 0, v: 31)
max component power: 187
-----------------------------
Input RGB: (220, 0, 0)
Output RGBV (Gamma corrected): (189, 0, 0, v: 31)
max component power: 189
-----------------------------
Input RGB: (221, 0, 0)
Output RGBV (Gamma corrected): (190, 0, 0, v: 31)
max component power: 190
-----------------------------
Input RGB: (222, 0, 0)
Output RGBV (Gamma corrected): (192, 0, 0, v: 31)
max component power: 192
-----------------------------
Input RGB: (223, 0, 0)
Output RGBV (Gamma corrected): (194, 0, 0, v: 31)
max component power: 194
-----------------------------
Input RGB: (224, 0, 0)
Output RGBV (Gamma corrected): (196, 0, 0, v: 31)
max component power: 196
-----------------------------
Input RGB: (225, 0, 0)
Output RGBV (Gamma corrected): (197, 0, 0, v: 31)
max component power: 197
-----------------------------
Input RGB: (226, 0, 0)
Output RGBV (Gamma corrected): (199, 0, 0, v: 31)
max component power: 199
-----------------------------
Input RGB: (227, 0, 0)
Output RGBV (Gamma corrected): (201, 0, 0, v: 31)
max component power: 201
-----------------------------
Input RGB: (228, 0, 0)
Output RGBV (Gamma corrected): (203, 0, 0, v: 31)
max component power: 203
-----------------------------
Input RGB: (229, 0, 0)
Output RGBV (Gamma corrected): (204, 0, 0, v: 31)
max component power: 204
-----------------------------
Input RGB: (230, 0, 0)
Output RGBV (Gamma corrected): (206, 0, 0, v: 31)
max component power: 206
-----------------------------
Input RGB: (231, 0, 0)
Output RGBV (Gamma corrected): (208, 0, 0, v: 31)
max component power: 208
-----------------------------
Input RGB: (232, 0, 0)
Output RGBV (Gamma corrected): (210, 0, 0, v: 31)
max component power: 210
-----------------------------
Input RGB: (233, 0, 0)
Output RGBV (Gamma corrected): (212, 0, 0, v: 31)
max component power: 212
-----------------------------
Input RGB: (234, 0, 0)
Output RGBV (Gamma corrected): (213, 0, 0, v: 31)
max component power: 213
-----------------------------
Input RGB: (235, 0, 0)
Output RGBV (Gamma corrected): (215, 0, 0, v: 31)
max component power: 215
-----------------------------
Input RGB: (236, 0, 0)
Output RGBV (Gamma corrected): (217, 0, 0, v: 31)
max component power: 217
-----------------------------
Input RGB: (237, 0, 0)
Output RGBV (Gamma corrected): (219, 0, 0, v: 31)
max component power: 219
-----------------------------
Input RGB: (238, 0, 0)
Output RGBV (Gamma corrected): (221, 0, 0, v: 31)
max component power: 221
-----------------------------
Input RGB: (239, 0, 0)
Output RGBV (Gamma corrected): (223, 0, 0, v: 31)
max component power: 223
-----------------------------
Input RGB: (240, 0, 0)
Output RGBV (Gamma corrected): (225, 0, 0, v: 31)
max component power: 225
-----------------------------
Input RGB: (241, 0, 0)
Output RGBV (Gamma corrected): (226, 0, 0, v: 31)
max component power: 226
-----------------------------
Input RGB: (242, 0, 0)
Output RGBV (Gamma corrected): (228, 0, 0, v: 31)
max component power: 228
-----------------------------
Input RGB: (243, 0, 0)
Output RGBV (Gamma corrected): (230, 0, 0, v: 31)
max component power: 230
-----------------------------
Input RGB: (244, 0, 0)
Output RGBV (Gamma corrected): (232, 0, 0, v: 31)
max component power: 232
-----------------------------
Input RGB: (245, 0, 0)
Output RGBV (Gamma corrected): (234, 0, 0, v: 31)
max component power: 234
-----------------------------
Input RGB: (246, 0, 0)
Output RGBV (Gamma corrected): (236, 0, 0, v: 31)
max component power: 236
-----------------------------
Input RGB: (247, 0, 0)
Output RGBV (Gamma corrected): (238, 0, 0, v: 31)
max component power: 238
-----------------------------
Input RGB: (248, 0, 0)
Output RGBV (Gamma corrected): (240, 0, 0, v: 31)
max component power: 240
-----------------------------
Input RGB: (249, 0, 0)
Output RGBV (Gamma corrected): (242, 0, 0, v: 31)
max component power: 242
-----------------------------
Input RGB: (250, 0, 0)
Output RGBV (Gamma corrected): (244, 0, 0, v: 31)
max component power: 244
-----------------------------
Input RGB: (251, 0, 0)
Output RGBV (Gamma corrected): (246, 0, 0, v: 31)
max component power: 246
-----------------------------
Input RGB: (252, 0, 0)
Output RGBV (Gamma corrected): (248, 0, 0, v: 31)
max component power: 248
-----------------------------
Input RGB: (253, 0, 0)
Output RGBV (Gamma corrected): (250, 0, 0, v: 31)
max component power: 250
-----------------------------
Input RGB: (254, 0, 0)
Output RGBV (Gamma corrected): (252, 0, 0, v: 31)
max component power: 252
-----------------------------
Input RGB: (255, 0, 0)
Output RGBV (Gamma corrected): (255, 0, 0, v: 31)
max component power: 255
-----------------------------

---- Other Values ----

Input RGB: (255, 255, 255)
Output RGBV (Gamma corrected): (255, 255, 255, v: 31)
max component power: 255
-----------------------------
Input RGB: (127, 1, 1)
Output RGBV (Gamma corrected): (130, 0, 0, v: 15)
max component power: 62.9032
-----------------------------
Input RGB: (128, 1, 1)
Output RGBV (Gamma corrected): (132, 0, 0, v: 15)
max component power: 63.871
-----------------------------
Input RGB: (128, 16, 1)
Output RGBV (Gamma corrected): (132, 2, 0, v: 15)
max component power: 63.871
-----------------------------
Input RGB: (32, 16, 1)
Output RGBV (Gamma corrected): (124, 31, 1, v: 1)
max component power: 4
-----------------------------
Input RGB: (3, 6, 1)
Output RGBV (Gamma corrected): (3, 6, 1, v: 1)
max component power: 0.193548
-----------------------------

@zackees zackees changed the title High Bit Depth Algorithm for APA102/Dotstar LEDs High Bit Depth Gamma Correction Algorithm for APA102/Dotstar LEDs Sep 28, 2023
@Joshfindit
Copy link

Joshfindit commented Jan 23, 2024

@zackees Apologies if I'm out of line, I just ran across this issues during research and noticed it's resolved by the linked (merged) PR.

@zackees
Copy link
Member Author

zackees commented Jan 25, 2024

Yeah I had to shift scaling post gamma instead of pre gamma.

@zackees zackees closed this as completed Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants