Article View: comp.sys.sun
Article #9412Re: How to discover screen depth
From: Mike Khaw
Date: Sun, 04 Dec 1988 05:05
Date: Sun, 04 Dec 1988 05:05
116 lines
3431 bytes
3431 bytes
>>> Is there an easy way to find out the screen depth?
...
> There should be a better way to handle color 3/60's or other machines with
> two framebuffers correctly. It currently reports monochrome. Perhaps
> someone knows how to do it?
You can go through a lot of gyrations to open the root window's "screen"
and look at the bits for 8bit_color_only, or overlay_only, etc. Or, if
you assume you are in suntools when you want to find out, it looks like a
simple program like this will do it:
<--- cut here --->
/*
* fbdepth - works for cgfours under suntools.
* compile with -lsuntool -lsunwindow -lpixrect
*/
#include <suntool/sunview.h>
main()
{
Frame base;
Pixwin *pw;
if ((base = window_create(0, FRAME, WIN_SHOW, FALSE, 0)) == NULL)
{
fprintf(stderr, "suntools not running!?\n");
exit(1);
}
pw = (Pixwin *) window_get(base, WIN_PIXWIN);
printf("desktop bitplane depth = %d\n", pw->pw_pixrect->pr_depth);
exit(0);
}
<--- cut here --->
This will return "1" if your have a monochrome frame buffer or are running
on the b&w desktop of a cgfour; otherwise it should return "8".
Now the more elaborate program that will work even if you're not running
under suntools. This one returns "monochrome" or "color" if it can figure
it out, or "prism" if you have a cgfour and it can't tell which planes are
in use:
<--- cut here --->
/*
* fbtype - compile with -lsunwindow -lpixrect
*/
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sun/fbio.h>
#include <sunwindow/window_hs.h>
main()
{
int fd;
char windevname[12];
struct fbgattr attr_buff;
errno = 0;
if ((fd = open("/dev/fb", O_RDONLY)) < 0)
exit(errno);
errno = 0;
if (ioctl(fd, FBIOGATTR, &attr_buff) < 0)
if (ioctl(fd, FBIOGTYPE, &attr_buff.fbtype) < 0)
exit(errno);
(void) close(fd);
if (attr_buff.fbtype.fb_type != FBTYPE_SUN4COLOR)
switch (attr_buff.fbtype.fb_depth)
{
case 1:
printf("monochrome\n");
break;
case 8:
printf("color\n");
break;
default:
printf("unknown\n");
break;
}
else if (we_getparentwindow(windevname))
printf("prism\n"); /* not in suntools? */
else
{
struct screen screen;
errno = 0;
if ((fd = open(windevname)) < 0)
exit(errno);
win_screenget(fd, &screen);
(void) close(fd);
if (screen.scr_flags & SCR_8BITCOLORONLY)
printf("color\n");
else if (strncmp("/dev/bw", screen.scr_fbname, 7) == 0 ||
screen.scr_flags & SCR_OVERLAYONLY)
printf("monochrome\n");
else
printf("prism\n");
}
exit(0);
}
<--- cut here --->
Mike Khaw
--
internet: mkhaw@teknowledge.arpa
uucp: {uunet|sun|ucbvax|decwrl|ames|hplabs}!mkhaw%teknowledge.arpa
hardcopy: Teknowledge Inc, 1850 Embarcadero Rd, POB 10119, Palo Alto, CA 94303
Technical Details
Message-ID:
<25958@teknowledge-vaxc.ARPA>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!att!ucbvax!husc6!rice!sun-spots-requestReferences:
<8811142048.AA08370@emmy.umd.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!att!ucbvax!husc6!rice!sun-spots-request From: mkhaw@teknowledge-vaxc.arpa (Mike Khaw) Newsgroups: comp.sys.sun Subject: Re: How to discover screen depth Message-ID: <25958@teknowledge-vaxc.ARPA> Date: 4 Dec 88 05:05:30 GMT References: <8811142048.AA08370@emmy.umd.edu> Sender: usenet@rice.edu Organization: Rice University, Houston, Texas Lines: 116 Approved: Sun-Spots@rice.edu Original-Date: 23 Nov 88 18:15:13 GMT X-Sun-Spots-Digest: Volume 7, Issue 37, message 9 of 12