Newbie question: how can I adjust the brightness of an individual CRGB element?

Newbie question: how can I adjust the brightness of an individual CRGB element? Looking at using rgb2hsv_approximate() and then setting .val, but am I missing straightforward (obvious) solution? Thanks!!

Can you give a little more context for how the original color value got there in the first place and what you’re trying to achieve with it?

I am looking to work with single APA102 strip as 2 virtual strips, with one being always brighter than the other. So I was going to set up new variants of some colorutils (fill_rainbow, fill_solid, etc) to add HSV brightness (.val) parameter.

So looking at fill_solid() with CRGB: for example, if I want to set both virtual strips to pure red, but have 1st strip brightness .val=128 and 2nd strip brighter with .val=208.

I should be able to use CHSV variant of fill_solid() but just wanted to satisfy my understanding of whether I can more directly set a brightness level other than converting CRGB to CHSV. (And perhaps I’m totally missing the boat on something here!!)

There are a few ways to skin this cat, and you clearly have several ideas brewing - to mix metaphors.

But here’s something you might find useful: “nscale8_video”. It scales the R, G, and B of a pixel down to a given fraction of their original values. The fraction is expressed in 256ths, so to scale a pixel down to half brightness (128/256ths), you’d do this:

leds[i].nscale8_video( 128 );

You can also call it on an array of pixels, so for example:

uint16_t startingpos = {id number of first LED to dim} ;
uint16_t count = {number of LEDS to dim} ;
nscale8_video( leds + startingpos, count, 128);

This scaling is linear on the RGB values, so scaling
CRGB(100, 80, 60) by 128/256ths would produce
CRGB( 50, 40, 30)
which is nearly the same as converting to HSV, cutting the value (brightness) in half, and converting back to RGB.

Does this help?

Excellent… I’ll play around with this… should be good enough for my needs. Thank you!