# Why is cRGB data structure bgr inside?

**URL:** <https://community.keyboard.io/t/why-is-crgb-data-structure-bgr-inside/431>\
**Category:** Kaleidoscope Internals\
**Created:** [October 17, 2017, 9:01am UTC](https://community.keyboard.io/t/why-is-crgb-data-structure-bgr-inside/431 "2017-10-17T09:01:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![glasser](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/glasser/32/414_2.png) [@glasser](https://community.keyboard.io/u/glasser)\
**Post date:** [October 17, 2017, 9:01am UTC](https://community.keyboard.io/t/why-is-crgb-data-structure-bgr-inside/431/1 "2017-10-17T09:01:12Z")

</div>

There’s a cRGB struct type that’s used in a bunch of Kaleidoscope libraries. It’s [defined here](https://github.com/keyboardio/KeyboardioScanner/blob/dce4784cdcb317ca26581e54861be8d5b79bf94f/KeyboardioScanner.h#L6-L10), I think

I went searching for it when this code which I added to Kaleidoscope-LED-ActiveModColor based on something that’s already there gave me a blue light:

```auto
cRGB ActiveModColorEffect::sticky_color = (cRGB) {
  0xff, 0x00, 0x00
};

```

Am I missing something, or is it weird that something called cRGB has fields whose order isn’t r/g/b?

---

<div class="post-metadata">

**Author:** ![algernon](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/algernon/32/4404_2.png) [@algernon](https://community.keyboard.io/u/algernon)\
**Post date:** [October 17, 2017, 11:44am UTC](https://community.keyboard.io/t/why-is-crgb-data-structure-bgr-inside/431/2 "2017-10-17T11:44:13Z")

</div>

It is in `BGR` order because that’s the order the hardware wants, and having the struct in the same order allows the firmware to just copy buffers over, without having to rearrange them first. This is considerably more performant. It is called `cRGB` mostly for historical reasons, `Color` or something would perhaps be more appropriate. Renaming to `cBGR` would be wrong, though, because other hardware may very well have a different order (for example, the Shortcut is `GRB`).

You can use the `CRGB` macro which arranges the r/g/b order to the hardware-specific order at compile time (thus no performance penalty): `cRGB ActiveModColorEffect::sticky_color = CRGB(0xff, 0, 0)`

---

<div class="post-metadata">

**Author:** ![glasser](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/glasser/32/414_2.png) [@glasser](https://community.keyboard.io/u/glasser)\
**Post date:** [October 17, 2017, 5:23pm UTC](https://community.keyboard.io/t/why-is-crgb-data-structure-bgr-inside/431/3 "2017-10-17T17:23:12Z")

</div>

That makes sense!

> <https://github.com/keyboardio/Kaleidoscope-Hardware/pull/1>

---

<div class="post-metadata">

**Author:** ![jesse](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/jesse/32/361_2.png) [@jesse](https://community.keyboard.io/u/jesse)\
**Post date:** [October 17, 2017, 7:14pm UTC](https://community.keyboard.io/t/why-is-crgb-data-structure-bgr-inside/431/4 "2017-10-17T19:14:16Z")

</div>

> [@algernon](#):
>
> . It is called cRGB mostly for historical reasons,

I don’t think of it as ‘historical’, so much as naming by intent rather than implementation.  
“RGB” describes the colorspace. (FastLED has cRGB and cHSV)
