thebuell
Posts: 33
Joined: Mon Sep 19, 2011 8:22 pm

Pixels in 24 bit resolutions

Wed Apr 24, 2013 10:02 pm

Does anyone have any example code that can draw pixels on a 24 bit resolution? Thanks!

valtonia
Posts: 26
Joined: Wed Jul 04, 2012 9:09 pm

Re: Pixels in 24 bit resolutions

Fri Apr 26, 2013 9:13 pm

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.

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;
   }
}
Hope this helps.

V.

Return to “Bare metal, Assembly language”