diff --git a/src/internal/features/NeoGrb48Feature.h b/src/internal/features/NeoGrb48Feature.h index f53bba2..644f430 100644 --- a/src/internal/features/NeoGrb48Feature.h +++ b/src/internal/features/NeoGrb48Feature.h @@ -31,21 +31,26 @@ class NeoGrb48Feature : public Neo6ByteElementsNoSettings public: static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) { - uint16_t* p = reinterpret_cast(getPixelAddress(pPixels, indexPixel)); + uint8_t* p = getPixelAddress(pPixels, indexPixel); - *p++ = color.G; - *p++ = color.R; - *p = color.B; + // due to endianness the byte order must be copied to output + *p++ = color.G >> 8; + *p++ = color.G & 0x0f; + *p++ = color.R >> 8; + *p++ = color.R & 0x0f; + *p++ = color.B >> 8; + *p = color.B & 0x0f; } static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) { ColorObject color; - const uint16_t* p = reinterpret_cast(getPixelAddress(pPixels, indexPixel)); + const uint8_t* p = getPixelAddress(pPixels, indexPixel); - color.G = *p++; - color.R = *p++; - color.B = *p; + // due to endianness the byte order must be copied to output + color.G = (static_cast(*p++) << 8) | *p++; + color.R = (static_cast(*p++) << 8) | *p++; + color.B = (static_cast(*p++) << 8) | *p; return color; } @@ -55,6 +60,8 @@ public: ColorObject color; const uint16_t* p = reinterpret_cast(getPixelAddress(reinterpret_cast(pPixels), indexPixel)); + // PROGMEM unit of storage expected to be the same size as color element + // so no endianness issues to worry about color.G = pgm_read_word(p++); color.R = pgm_read_word(p++); color.B = pgm_read_word(p); diff --git a/src/internal/features/NeoRgb48Feature.h b/src/internal/features/NeoRgb48Feature.h index e9c7b63..e138962 100644 --- a/src/internal/features/NeoRgb48Feature.h +++ b/src/internal/features/NeoRgb48Feature.h @@ -31,21 +31,26 @@ class NeoRgb48Feature : public Neo6ByteElementsNoSettings public: static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) { - uint16_t* p = reinterpret_cast(getPixelAddress(pPixels, indexPixel)); + uint8_t* p = getPixelAddress(pPixels, indexPixel); - *p++ = color.R; - *p++ = color.G; - *p = color.B; + // due to endianness the byte order must be copied to output + *p++ = color.R >> 8; + *p++ = color.R & 0x0f; + *p++ = color.G >> 8; + *p++ = color.G & 0x0f; + *p++ = color.B >> 8; + *p = color.B & 0x0f; } static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) { ColorObject color; - const uint16_t* p = reinterpret_cast(getPixelAddress(pPixels, indexPixel)); + const uint8_t* p = getPixelAddress(pPixels, indexPixel); - color.R = *p++; - color.G = *p++; - color.B = *p; + // due to endianness the byte order must be copied to output + color.R = (static_cast(*p++) << 8) | *p++; + color.G = (static_cast(*p++) << 8) | *p++; + color.B = (static_cast(*p++) << 8) | *p; return color; } @@ -55,6 +60,8 @@ public: ColorObject color; const uint16_t* p = reinterpret_cast(getPixelAddress(reinterpret_cast(pPixels), indexPixel)); + // PROGMEM unit of storage expected to be the same size as color element + // so no endianness issues to worry about color.R = pgm_read_word(p++); color.G = pgm_read_word(p++); color.B = pgm_read_word(p); diff --git a/src/internal/features/NeoRgbw64Feature.h b/src/internal/features/NeoRgbw64Feature.h index b09369e..f657773 100644 --- a/src/internal/features/NeoRgbw64Feature.h +++ b/src/internal/features/NeoRgbw64Feature.h @@ -32,23 +32,29 @@ class NeoRgbw64Feature : public Neo8ByteElementsNoSettings public: static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) { - uint16_t* p = reinterpret_cast(getPixelAddress(pPixels, indexPixel)); + uint8_t* p = getPixelAddress(pPixels, indexPixel); - *p++ = color.R; - *p++ = color.G; - *p++ = color.B; - *p = color.W; + // due to endianness the byte order must be copied to output + *p++ = color.R >> 8; + *p++ = color.R & 0x0f; + *p++ = color.G >> 8; + *p++ = color.G & 0x0f; + *p++ = color.B >> 8; + *p++ = color.B & 0x0f; + *p++ = color.W >> 8; + *p = color.W & 0x0f; } static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) { ColorObject color; - const uint16_t* p = reinterpret_cast(getPixelAddress(pPixels, indexPixel)); + const uint8_t* p = getPixelAddress(pPixels, indexPixel); - color.R = *p++; - color.G = *p++; - color.B = *p++; - color.W = *p; + // due to endianness the byte order must be copied to output + color.R = (static_cast(*p++) << 8) | *p++; + color.G = (static_cast(*p++) << 8) | *p++; + color.B = (static_cast(*p++) << 8) | *p++; + color.W = (static_cast(*p++) << 8) | *p; return color; } @@ -58,6 +64,8 @@ public: ColorObject color; const uint16_t* p = reinterpret_cast(getPixelAddress(reinterpret_cast(pPixels), indexPixel)); + // PROGMEM unit of storage expected to be the same size as color element + // so no endianness issues to worry about color.R = pgm_read_word(p++); color.G = pgm_read_word(p++); color.B = pgm_read_word(p++);