Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions | Variables
driver.h File Reference
#include "color.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  driver
struct  device

Defines

#define COM_SENDM   0x6f37
#define COM_RECVM   0x51da
#define COM_CLEAR   0
#define COM_PAINTR   1
#define COM_GETCUR   2
#define COM_COMOUT   3
#define COM_COMIN   4
#define COM_FLUSH   5
#define NREQUESTS   6 /* number of valid requests */
#define MB1   ('\n') /* mouse button 1 */
#define MB2   ('\r') /* mouse button 2 */
#define MB3   (' ') /* mouse button 3 */
#define ABORT   ('C'-'@') /* abort key */

Typedefs

typedef struct driverdr_initf_t (char *dname, char *id)
typedef int dr_getchf_t (void)
typedef void dr_newcolrf_t (int ndx, int r, int g, int b)
typedef void dr_closef_t (void)
typedef void dr_clearf_t (int, int)
typedef void dr_paintrf_t (COLOR col, int xmin, int ymin, int xmax, int ymax)
typedef int dr_getcurf_t (int *, int *)
typedef void dr_comoutf_t (char *)
typedef void dr_cominf_t (char *, char *)
typedef void dr_flushf_t (void)

Functions

void editline (char *buf, dr_getchf_t *c_get, dr_comoutf_t *s_put)
void tocombuf (char *b, struct driver *d)
int fromcombuf (char *b, struct driver *d)
struct drivercomm_init (char *dname, char *id)
int new_ctab (int ncolors)
int get_pixel (COLOR col, dr_newcolrf_t *newcolr)
void make_gmap (double gam)
void set_cmap (BYTE *rmap, BYTE *gmap, BYTE *bmap)
void map_color (BYTE rgb[3], COLOR col)

Variables

struct device devtable []
char dev_default []
dr_initf_t slave_init

Class Documentation

struct driver

Definition at line 14 of file rhdriver.h.

Collaboration diagram for driver:
Class Members
dr_clearf_t * clear
dr_closef_t * close
dr_cominf_t * comin
dr_comoutf_t * comout
int firstuse
dr_flushf_t * flush
dr_getcurf_t * getcur
int hres
int ifd
int inpready
char * name
dr_paintrf_t * paintr
double pixaspect
VIEW v
int vres
int xsiz
int ysiz
struct device

Definition at line 50 of file driver.h.

Class Members
char * descrip
dr_initf_t * init
char * name

Define Documentation

#define ABORT   ('C'-'@') /* abort key */

Definition at line 61 of file driver.h.

#define COM_CLEAR   0

Definition at line 42 of file driver.h.

#define COM_COMIN   4

Definition at line 46 of file driver.h.

#define COM_COMOUT   3

Definition at line 45 of file driver.h.

#define COM_FLUSH   5

Definition at line 47 of file driver.h.

#define COM_GETCUR   2

Definition at line 44 of file driver.h.

#define COM_PAINTR   1

Definition at line 43 of file driver.h.

#define COM_RECVM   0x51da

Definition at line 40 of file driver.h.

#define COM_SENDM   0x6f37

Definition at line 39 of file driver.h.

#define MB1   ('\n') /* mouse button 1 */

Definition at line 58 of file driver.h.

#define MB2   ('\r') /* mouse button 2 */

Definition at line 59 of file driver.h.

#define MB3   (' ') /* mouse button 3 */

Definition at line 60 of file driver.h.

#define NREQUESTS   6 /* number of valid requests */

Definition at line 48 of file driver.h.


Typedef Documentation

typedef void dr_clearf_t(int, int)

Definition at line 19 of file driver.h.

typedef void dr_closef_t(void)

Definition at line 18 of file driver.h.

typedef void dr_cominf_t(char *, char *)

Definition at line 23 of file driver.h.

typedef void dr_comoutf_t(char *)

Definition at line 22 of file driver.h.

typedef void dr_flushf_t(void)

Definition at line 24 of file driver.h.

typedef int dr_getchf_t(void)

Definition at line 15 of file driver.h.

typedef int dr_getcurf_t(int *, int *)

Definition at line 21 of file driver.h.

typedef struct driver* dr_initf_t(char *dname, char *id)

Definition at line 14 of file driver.h.

typedef void dr_newcolrf_t(int ndx, int r, int g, int b)

Definition at line 16 of file driver.h.

typedef void dr_paintrf_t(COLOR col, int xmin, int ymin, int xmax, int ymax)

Definition at line 20 of file driver.h.


Function Documentation

struct driver* comm_init ( char *  dname,
char *  id 
) [read]

Definition at line 79 of file devcomm.c.

{
       char   *dvcname;
       int    p1[2], p2[2];
       char   pin[16], pout[16];
                                          /* find driver program */
       if ((dvcname = getpath(dname, DEVPATH, X_OK)) == NULL) {
              eputs(dname);
              eputs(": not found\n");
              return(NULL);
       }
#ifdef RHAS_FORK_EXEC
                                          /* open communication pipes */
       if (pipe(p1) == -1 || pipe(p2) == -1)
              goto syserr;
       if ((devchild = fork()) == 0) {    /* fork driver process */
              close(p1[1]);
              close(p2[0]);
              sprintf(pin, "%d", p1[0]);
              sprintf(pout, "%d", p2[1]);
              execl(dvcname, dname, pin, pout, id, NULL);
              perror(dvcname);
              _exit(127);
       }
       if (devchild == -1)
              goto syserr;
       close(p1[0]);
       close(p2[1]);
       /*
        * Close write stream on exec to avoid multiprocessing deadlock.
        * No use in read stream without it, so set flag there as well.
        */
       fcntl(p1[1], F_SETFD, FD_CLOEXEC);
       fcntl(p2[0], F_SETFD, FD_CLOEXEC);
       if ((devout = fdopen(p1[1], "w")) == NULL)
              goto syserr;
       if ((devin = fdopen(p2[0], "r")) == NULL)
              goto syserr;
       return(final_connect());           /* verify initialization */
syserr:
       perror(dname);
       return(NULL);

#else  /* ! RHAS_FORK_EXEC */

       eputs(dname);
       eputs(": no fork/exec\n");
       return(NULL);

#endif /* ! RHAS_FORK_EXEC */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void editline ( char *  buf,
dr_getchf_t c_get,
dr_comoutf_t s_put 
)

Definition at line 27 of file editline.c.

{
       static char  erases[] = "\b \b";
       static char  obuf[4];
       register int  i;
       register int  c;
       
       i = 0;
       while ((c = (*c_get)()&0177) != '\n' && c != '\r')
              if (iserase(c)) {           /* single char erase */
                     if (i > 0) {
                            (*s_put)(erases);
                            --i;
                     }
              } else if (iswerase(c)) {   /* word erase */
                     while (i > 0 && isblank(buf[i-1])) {
                            (*s_put)(erases);
                            --i;
                     }
                     while (i > 0 && !isblank(buf[i-1])) {
                            (*s_put)(erases);
                            --i;
                     }
              } else if (iskill(c)) {            /* kill line */
                     while (i > 0) {
                            (*s_put)(erases);
                            --i;
                     }
              } else if (iscntrl(c)) {           /* control char */
                     i = 0;
                     buf[i++] = c;
                     obuf[0] = '^'; obuf[1] = c|0100; obuf[2] = '\0';
                     (*s_put)(obuf);
                     break;
              } else {                           /* regular char */
                     buf[i++] = c;
                     obuf[0] = c; obuf[1] = '\0';
                     (*s_put)(obuf);
              }
       buf[i] = '\0';
       (*s_put)("\n");
}

Here is the caller graph for this function:

int fromcombuf ( char *  b,
struct driver d 
)

Definition at line 101 of file editline.c.

{
       register char *cp;
                                          /* get next command */
       for (cp = mybuf; *cp != '\n'; cp++)
              if (!*cp)
                     return(0);
       *cp++ = '\0';
#ifdef DEBUG
       (*d->comout)(mybuf);               /* echo my command */
       (*d->comout)("\n");
#endif
                                          /* send it as reply */
       strcpy(b, mybuf);
       d->inpready--;
                                          /* advance commands */
       strcpy(mybuf, cp);
       return(1);
}

Here is the caller graph for this function:

int get_pixel ( COLOR  col,
dr_newcolrf_t newcolr 
)

Definition at line 97 of file colortab.c.

{
       int    r, g, b;
       int    cv[3];
       register CNODE       *tp;
       register int  h;
                                          /* map color */
       r = map_col(col,RED);
       g = map_col(col,GRN);
       b = map_col(col,BLU);
                                          /* reduce resolution */
       cv[RED] = (r*NRED)>>8;
       cv[GRN] = (g*NGRN)>>8;
       cv[BLU] = (b*NBLU)>>8;
                                          /* add to histogram */
       histo[cv[RED]][cv[GRN]][cv[BLU]]++;
                                          /* find pixel in tree */
       for (tp = ctree, h = 0; is_branch(*tp); h++)
              if (cv[prim(*tp)] < part(*tp))
                     tp += 1<<h;          /* left branch */
              else
                     tp += 1<<(h+1);             /* right branch */
       h = pval(*tp);
                                          /* add to color table */
       clrtab[h].sum[RED] += r;
       clrtab[h].sum[GRN] += g;
       clrtab[h].sum[BLU] += b;
       clrtab[h].n++;
                                   /* recompute average */
       r = clrtab[h].sum[RED] / clrtab[h].n;
       g = clrtab[h].sum[GRN] / clrtab[h].n;
       b = clrtab[h].sum[BLU] / clrtab[h].n;
                                   /* check for movement */
       if (clrtab[h].n == 1 ||
                     (r-clrtab[h].ent[RED])*(r-clrtab[h].ent[RED]) +
                     (g-clrtab[h].ent[GRN])*(g-clrtab[h].ent[GRN]) +
                     (b-clrtab[h].ent[BLU])*(b-clrtab[h].ent[BLU]) > MAXDST2) {
              clrtab[h].ent[RED] = r;
              clrtab[h].ent[GRN] = g; /* reassign pixel */
              clrtab[h].ent[BLU] = b;
#ifdef DEBUG
              sprintf(errmsg, "pixel %d = (%d,%d,%d) (%d refs)\n",
                            h, r, g, b, clrtab[h].n);
              eputs(errmsg);
#endif
              (*newcolr)(h, r, g, b);
       }
       return(h);                         /* return pixel value */
}

Here is the call graph for this function:

void make_gmap ( double  gam)

Definition at line 152 of file colortab.c.

{
       register int  i;
       
       for (i = 0; i < 256; i++)
              clrmap[RED][i] =
              clrmap[GRN][i] =
              clrmap[BLU][i] = 256.0 * pow((i+0.5)/256.0, 1.0/gam);
}

Here is the caller graph for this function:

void map_color ( BYTE  rgb[3],
COLOR  col 
)
int new_ctab ( int  ncolors)

Definition at line 61 of file rhd_ctab.c.

{
       int    treesize;

       if (ncolors < 1)
              return(0);
                            /* free old tables */
       if (clrtab != NULL)
              free((void *)clrtab);
       if (ctree != NULL)
              free((void *)ctree);
                            /* get new tables */
       for (treesize = 1; treesize < ncolors; treesize <<= 1)
              ;
       treesize <<= 1;
       clrtab = (struct tabent *)calloc(ncolors, sizeof(struct tabent));
       ctree = (CNODE *)malloc(treesize*sizeof(CNODE));
       if (clrtab == NULL || ctree == NULL)
              return(0);
                            /* partition color space */
       cut(ctree, 0, CLRCUBE, 0, ncolors);
                            /* clear histogram */
       memset((void *)histo, '\0', sizeof(histo));
                            /* return number of colors used */
       return(ncolors);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_cmap ( BYTE rmap,
BYTE gmap,
BYTE bmap 
)

Definition at line 165 of file colortab.c.

{
       memcpy((void *)clrmap[RED], (void *)rmap, 256);
       memcpy((void *)clrmap[GRN], (void *)gmap, 256);
       memcpy((void *)clrmap[BLU], (void *)bmap, 256);
}
void tocombuf ( char *  b,
struct driver d 
)

Definition at line 79 of file editline.c.

{
       register char  *cp;
       char  *comstart;

       for (cp = mybuf; *cp; cp++)
              ;
       comstart = cp;
       while ( (*cp++ = *b) )
              if (cp >= mybuf+sizeof(mybuf)) {
                     *comstart = '\0';
                     return;              /* what should I do about this? */
              } else if (*b++ == '\n') {
                     d->inpready++;
                     comstart = cp;
              }
}

Here is the caller graph for this function:


Variable Documentation

char dev_default[]

Definition at line 15 of file devtable.c.

struct device devtable[]