Skip to content

Implements "High Bit Depth Gamma Correction Algorithm for APA102/Dotstar LEDs" for APA102 and SK9822 chipsets - #1546

Merged
kriegsman merged 6 commits into
FastLED:masterfrom
zackees:apa102-hd-gamma
Oct 25, 2023
Merged

kriegsman merged 6 commits into
FastLED:masterfrom
zackees:apa102-hd-gamma

Conversation

@zackees

@zackees zackees commented Sep 30, 2023 •

Copy link
Copy Markdown
Member

See issue: #1545

Working code. Ready to review.

Here is an example of how it's activated, by using APA102HD

  FastLED.addLeds<
    APA102HD, APA102_DATA_PIN, APA102_CLOCK_PIN, COLOR_ORDER, DATA_RATE_MHZ(12)
  >(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

Here's an example sketch:

/// @file    Apa102HD.ino
/// @brief   Tests two strips side by side showing off the gamma correction.
/// @example Apa102HD.ino

#include <Arduino.h>
#include <FastLED.h>
#include <assert.h>


#define NUM_LEDS  20

static bool gamma_function_hit = false;
CRGB leds_hd[NUM_LEDS] = {0};  // HD mode implies gamma.
CRGB leds[NUM_LEDS] = {0};     // Software gamma mode.

uint8_t gamma8(uint8_t x) {
    return uint8_t((uint16_t(x) * x) >> 8);
}

CRGB gammaCorrect(CRGB c) {
    c.r = gamma8(c.r);
    c.g = gamma8(c.g);
    c.b = gamma8(c.b);
    return c;
}

void setup() {
    delay(500); // power-up safety delay
    FastLED.addLeds<APA102HD, 1, 2, RGB>(leds_hd, NUM_LEDS);
    FastLED.addLeds<APA102, 3, 4, RGB>(leds, NUM_LEDS);
}

void loop() {
    uint32_t now = millis();
    uint32_t t = now / 100;
    for (int i = 0; i < NUM_LEDS; i++) {
        uint8_t brightness = sin8(t + i);
        CRGB c(brightness, brightness, brightness);
        leds_hd[i] = c;
        leds[i] = gammaCorrect(c);
    }
    FastLED.show();
    delay(8);
}

Demo:

IMG_1274_mute_small.mp4

@zackees

zackees commented Oct 2, 2023

Copy link
Copy Markdown
Member Author

@kriegsman @samguyer ready for review.

@kriegsman
kriegsman merged commit 3a03742 into FastLED:master Oct 25, 2023
@kriegsman

Copy link
Copy Markdown
Member

Thanks very much for this - great contribution, and nice implementation!

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

Successfully merging this pull request may close these issues.

2 participants