forked from Makuna/NeoPixelBus
fix endian issue with 16bit (#699)
This commit is contained in:
@@ -31,21 +31,26 @@ class NeoGrb48Feature : public Neo6ByteElementsNoSettings
|
|||||||
public:
|
public:
|
||||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||||
{
|
{
|
||||||
uint16_t* p = reinterpret_cast<uint16_t*>(getPixelAddress(pPixels, indexPixel));
|
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||||
|
|
||||||
*p++ = color.G;
|
// due to endianness the byte order must be copied to output
|
||||||
*p++ = color.R;
|
*p++ = color.G >> 8;
|
||||||
*p = color.B;
|
*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)
|
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
|
||||||
{
|
{
|
||||||
ColorObject color;
|
ColorObject color;
|
||||||
const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(pPixels, indexPixel));
|
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||||
|
|
||||||
color.G = *p++;
|
// due to endianness the byte order must be copied to output
|
||||||
color.R = *p++;
|
color.G = (static_cast<uint16_t>(*p++) << 8) | *p++;
|
||||||
color.B = *p;
|
color.R = (static_cast<uint16_t>(*p++) << 8) | *p++;
|
||||||
|
color.B = (static_cast<uint16_t>(*p++) << 8) | *p;
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
@@ -55,6 +60,8 @@ public:
|
|||||||
ColorObject color;
|
ColorObject color;
|
||||||
const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel));
|
const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(reinterpret_cast<const uint8_t*>(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.G = pgm_read_word(p++);
|
||||||
color.R = pgm_read_word(p++);
|
color.R = pgm_read_word(p++);
|
||||||
color.B = pgm_read_word(p);
|
color.B = pgm_read_word(p);
|
||||||
|
@@ -31,21 +31,26 @@ class NeoRgb48Feature : public Neo6ByteElementsNoSettings
|
|||||||
public:
|
public:
|
||||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||||
{
|
{
|
||||||
uint16_t* p = reinterpret_cast<uint16_t*>(getPixelAddress(pPixels, indexPixel));
|
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||||
|
|
||||||
*p++ = color.R;
|
// due to endianness the byte order must be copied to output
|
||||||
*p++ = color.G;
|
*p++ = color.R >> 8;
|
||||||
*p = color.B;
|
*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)
|
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
|
||||||
{
|
{
|
||||||
ColorObject color;
|
ColorObject color;
|
||||||
const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(pPixels, indexPixel));
|
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||||
|
|
||||||
color.R = *p++;
|
// due to endianness the byte order must be copied to output
|
||||||
color.G = *p++;
|
color.R = (static_cast<uint16_t>(*p++) << 8) | *p++;
|
||||||
color.B = *p;
|
color.G = (static_cast<uint16_t>(*p++) << 8) | *p++;
|
||||||
|
color.B = (static_cast<uint16_t>(*p++) << 8) | *p;
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
@@ -55,6 +60,8 @@ public:
|
|||||||
ColorObject color;
|
ColorObject color;
|
||||||
const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel));
|
const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(reinterpret_cast<const uint8_t*>(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.R = pgm_read_word(p++);
|
||||||
color.G = pgm_read_word(p++);
|
color.G = pgm_read_word(p++);
|
||||||
color.B = pgm_read_word(p);
|
color.B = pgm_read_word(p);
|
||||||
|
@@ -32,23 +32,29 @@ class NeoRgbw64Feature : public Neo8ByteElementsNoSettings
|
|||||||
public:
|
public:
|
||||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||||
{
|
{
|
||||||
uint16_t* p = reinterpret_cast<uint16_t*>(getPixelAddress(pPixels, indexPixel));
|
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||||
|
|
||||||
*p++ = color.R;
|
// due to endianness the byte order must be copied to output
|
||||||
*p++ = color.G;
|
*p++ = color.R >> 8;
|
||||||
*p++ = color.B;
|
*p++ = color.R & 0x0f;
|
||||||
*p = color.W;
|
*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)
|
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
|
||||||
{
|
{
|
||||||
ColorObject color;
|
ColorObject color;
|
||||||
const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(pPixels, indexPixel));
|
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||||
|
|
||||||
color.R = *p++;
|
// due to endianness the byte order must be copied to output
|
||||||
color.G = *p++;
|
color.R = (static_cast<uint16_t>(*p++) << 8) | *p++;
|
||||||
color.B = *p++;
|
color.G = (static_cast<uint16_t>(*p++) << 8) | *p++;
|
||||||
color.W = *p;
|
color.B = (static_cast<uint16_t>(*p++) << 8) | *p++;
|
||||||
|
color.W = (static_cast<uint16_t>(*p++) << 8) | *p;
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
@@ -58,6 +64,8 @@ public:
|
|||||||
ColorObject color;
|
ColorObject color;
|
||||||
const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel));
|
const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(reinterpret_cast<const uint8_t*>(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.R = pgm_read_word(p++);
|
||||||
color.G = pgm_read_word(p++);
|
color.G = pgm_read_word(p++);
|
||||||
color.B = pgm_read_word(p++);
|
color.B = pgm_read_word(p++);
|
||||||
|
Reference in New Issue
Block a user