8 bit colour palette: more information


3 posts
by -rst- » Mon Nov 26, 2012 10:42 am
Hi,

Found this thread http://www.raspberrypi.org/phpBB3/viewtopic.php?f=72&t=11682 in the Bare Metal forum - went on to reply before realising this would be more appropriate forum...

So I hereby try to branch the discussion here:

-rst- wrote:
dom wrote:Yes, and the 16-bit format is 5 bits red, 6 bits green, 5 bits blue.
The 8bpp does default to "web safe" palette, but can also be set. See:
https://github.com/raspberrypi/linux/bl ... m2708_fb.c


Hmm, that seems to be driver code, so not directly accessible by user-mode applications? Or have I missed a way to access this...

The framebuffer ioctl method does not seem to work on RPi - my code:

Code: Select all
#include <linux/fb.h>
...
  fbfd = open("/dev/fb0", O_RDWR);
...
  if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
    printf("Error reading variable information.\n");
    close(fbfd);
    return(3);
  }
  printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel );

  // Get palette information
  unsigned short r[256];
  unsigned short g[256];
  unsigned short b[256];
  unsigned short a[256];
  memset(r, 0xff, 256 * sizeof(unsigned short));
  memset(g, 0xff, 256 * sizeof(unsigned short));
  memset(b, 0xff, 256 * sizeof(unsigned short));
  memset(a, 0xff, 256 * sizeof(unsigned short));
  struct fb_cmap cmap;
  cmap.start = 0;
  cmap.len = 256;
  cmap.red = r;
  cmap.green = g;
  cmap.blue = b;
  cmap.transp = a;
  if (ioctl(fbfd, FBIOGETCMAP, &cmap)) {
    printf("Error reading palette.\n");
    close(fbfd);
    return(4);
  }
...

Succeeds to print out the resolution and bit depth, but always fails to read the palette (regardless of the mode set using 'fbset -depth x').

Does anybody know any other ways to access the driver (to set the palette)?

Thanks,

JP


The question remains: is this the only way to access the driver? And is this possibly a bug in the driver (google 'FBIOGETCMAP fail' finds bug reports for other drivers...)?

Thanks,

JP
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
Posts: 895
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland
by -rst- » Sat Dec 01, 2012 11:45 pm
Uh, ok - this time my carefulness seems to have 'bitten me in the leg'... I was hoping to read the default cmap and save it for restoring, so did not even try FBIOPUTCMAP ...which seems to work!!! I used 'fbset -depth 8' before running my test app.

Obviously it is easy to mangle the display so that the prompt etc. is lost, but 'blind typing' the command 'fbset -depth 16' luckily restores the default palette.

Now the question is: if this fb palette change applies to the 8 bit GPU/VC resources too... Well, time to get some sleep - I'll try it out tomorrow!
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
Posts: 895
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland
by -rst- » Sun Dec 02, 2012 6:10 pm
Nope, setting the fb palette/colmap does not seem to propagate to the GPU/VC resource :(
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
Posts: 895
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland