Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPixelColor unpacked #88

Open
tablatronix opened this issue Jan 10, 2016 · 2 comments
Open

getPixelColor unpacked #88

tablatronix opened this issue Jan 10, 2016 · 2 comments

Comments

@tablatronix
Copy link
Contributor

A nice helper function for unpacking rgb/w would be nice.

@Luro02
Copy link

Luro02 commented Nov 2, 2018

here is the code that unpacks a uint8_t rgbw value:

uint8_t *unpackColor(uint32_t c)
{
    uint8_t *color = (uint8_t *)calloc(4, sizeof(uint8_t));
    color[0] = (uint8_t)((c >> 16) & 0xFF);
    color[1] = (uint8_t)((c >>  8) & 0xFF);
    color[2] = (uint8_t)((c      ) & 0xFF);
    color[3] = (uint8_t)((c >> 24) & 0xFF);
    return color;
}

this function requires the user to free the returned object and this may not be the most "user-friendly" way of returning rgbw values. I'd suggest creating a rgbw_t type.

typedef struct {
    uint8_t r;
    uint8_t g;
    uint8_t b;
    uint8_t w;
} rgbw_t;

this would allow the user to simply do this

rgbw_t color = unpackColor(color);
printf("(%d, %d, %d, %d)\n", color.r, color.g, color.b, color.w);

@tablatronix
Copy link
Contributor Author

could also pass in refs args I suppose,
I have been using red(c) green(c) ... wrappers for this

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

No branches or pull requests

2 participants