Pixels in 24 bit resolutions
Does anyone have any example code that can draw pixels on a 24 bit resolution? Thanks!
Re: Pixels in 24 bit resolutions
While not the most efficient way to do it, this works.
Where x and y is the pixel location and c is the colour. This routine will work for all bit-depths, in this example I've hard-coded fb_depth to be 24.
Hope this helps.
V.
Where x and y is the pixel location and c is the colour. This routine will work for all bit-depths, in this example I've hard-coded fb_depth to be 24.
Code: Select all
void set_pixel(unsigned int x, unsigned int y, unsigned int c)
{
volatile unsigned char *pixel_addr;
unsigned int fb_depth = 24;
unsigned int ws = fb_depth / 8;
// Calculate the pixel address
pixel_addr = (volatile unsigned char *)FB_ADDRESS + (y * FB_PITCH) + (x * ws);
// Set the pixel
if (fb_depth >= 8)
{
*pixel_addr++ = (c & 0x000000FF);
}
if (fb_depth >= 16)
{
*pixel_addr++ = (c & 0x0000FF00) >> 8;
}
if (fb_depth >= 24)
{
*pixel_addr++ = (c & 0x00FF0000) >> 16;
}
if (fb_depth == 32)
{
*pixel_addr++ = (c & 0xFF000000) >> 24;
}
}
V.