Back to index

radiance  4R0+20100331
Defines | Functions | Variables
pcompos.c File Reference
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "copyright.h"
#include "platform.h"
#include "rtprocess.h"
#include "rterror.h"
#include "color.h"
#include "resolu.h"

Go to the source code of this file.

Defines

#define MAXFILE   1024
#define HASMIN   1
#define HASMAX   2

Functions

static void compos (void)
static int cmpcolr (COLR c1, double lv2)
static FILE * lblopen (char *s, int *xp, int *yp)
static int headline (char *s, void *p)
int main (int argc, char *argv[])
static int cmpcolr (register COLR c1, double lv2)
void quit (int code)

Variables

static const char RCSid [] = "$Id: pcompos.c,v 2.33 2009/08/10 04:26:38 greg Exp $"
int xsiz = 0
int ysiz = 0
int xmin = 0
int ymin = 0
int xmax = 0
int ymax = 0
COLR bgcolr = BLKCOLR
int labelht = 24
int checkthresh = 0
char StandardInput [] = "<stdin>"
char Command [] = "<Command>"
char Label [] = "<Label>"
char * progname
struct {
char * name
FILE * fp
int xres
int yres
int xloc
int yloc
int flags
double thmin
double thmax
input [MAXFILE]
int nfile
int echoheader = 1
char ourfmt [LPICFMT+1] = PICFMT
int wrongformat = 0
static gethfunc headline

Define Documentation

#define HASMAX   2

Definition at line 26 of file pcompos.c.

#define HASMIN   1

Definition at line 25 of file pcompos.c.

#define MAXFILE   1024

Definition at line 23 of file pcompos.c.


Function Documentation

static int cmpcolr ( COLR  c1,
double  lv2 
) [static]

Here is the caller graph for this function:

static int cmpcolr ( register COLR  c1,
double  lv2 
) [static]

Definition at line 395 of file pcompos.c.

{
       double lv1 = .0;
       
       if (c1[EXP])
              lv1 = ldexp((double)normbright(c1), (int)c1[EXP]-(COLXS+8));
       if (lv1 < lv2) return(-1);
       if (lv1 > lv2) return(1);
       return(0);
}
static void compos ( void  ) [static]

Definition at line 328 of file pcompos.c.

{
       COLR  *scanin, *scanout;
       int  y;
       register int  x, i;

       scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR));
       if (scanin == NULL)
              goto memerr;
       scanin -= xmin;
       if (checkthresh) {
              scanout = (COLR *)malloc(xsiz*sizeof(COLR));
              if (scanout == NULL)
                     goto memerr;
       } else
              scanout = scanin;
       for (y = ymax-1; y >= 0; y--) {
              for (x = 0; x < xsiz; x++)
                     copycolr(scanout[x], bgcolr);
              for (i = 0; i < nfile; i++) {
                     if (input[i].yloc > y ||
                                   input[i].yloc+input[i].yres <= y)
                            continue;
                     if (freadcolrs(scanin+input[i].xloc,
                                   input[i].xres, input[i].fp) < 0) {
                            fprintf(stderr, "%s: read error (y==%d)\n",
                                          input[i].name,
                                          y-input[i].yloc);
                            quit(1);
                     }
                     if (y >= ysiz)
                            continue;
                     if (checkthresh) {
                            x = input[i].xloc+input[i].xres;
                            if (x > xsiz)
                                   x = xsiz;
                            for (x--; x >= 0 && x >= input[i].xloc; x--) {
                                   if (input[i].flags & HASMIN &&
                                   cmpcolr(scanin[x], input[i].thmin) <= 0)
                                          continue;
                                   if (input[i].flags & HASMAX &&
                                   cmpcolr(scanin[x], input[i].thmax) >= 0)
                                          continue;
                                   copycolr(scanout[x], scanin[x]);
                            }
                     }
              }
              if (y >= ysiz)
                     continue;
              if (fwritecolrs(scanout, xsiz, stdout) < 0) {
                     perror(progname);
                     quit(1);
              }
       }
                                   /* read remainders from streams */
       for (i = 0; i < nfile; i++)
              if (input[i].name[0] == '<')
                     while (getc(input[i].fp) != EOF)
                            ;
       return;
memerr:
       perror(progname);
       quit(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int headline ( char *  s,
void *  p 
) [static]

Definition at line 73 of file pcompos.c.

{
       char  fmt[32];

       if (isheadid(s))
              return(0);
       if (formatval(fmt, s)) {
              if (globmatch(ourfmt, fmt)) {
                     wrongformat = 0;
                     strcpy(ourfmt, fmt);
              } else
                     wrongformat = 1;
       } else if (echoheader) {
              putc('\t', stdout);
              fputs(s, stdout);
       }
       return(0);
}

Here is the call graph for this function:

static FILE * lblopen ( char *  s,
int *  xp,
int *  yp 
) [static]

Definition at line 411 of file pcompos.c.

{
       char  com[PATH_MAX];
       FILE  *fp;

       sprintf(com, "psign -s -.15 -a 2 -x %d -y %d '%.90s'", *xp, *yp, s);
       if ((fp = popen(com, "r")) == NULL)
              return(NULL);
       if (checkheader(fp, COLRFMT, NULL) < 0)
              goto err;
       if (fgetresolu(xp, yp, fp) < 0)
              goto err;
       return(fp);
err:
       pclose(fp);
       return(NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 97 of file pcompos.c.

{
       int  ncolumns = 0;
       int  autolabel = 0;
       int  curcol = 0, x0 = 0, curx = 0, cury = 0, spacing = 0;
       int  xsgn, ysgn;
       char  *thislabel;
       int  an;
       SET_DEFAULT_BINARY();
       SET_FILE_BINARY(stdin);
       SET_FILE_BINARY(stdout);
       progname = argv[0];

       for (an = 1; an < argc && argv[an][0] == '-'; an++)
              switch (argv[an][1]) {
              case 'h':
                     echoheader = !echoheader;
                     break;
              case 'x':
                     xsiz = atoi(argv[++an]);
                     break;
              case 'y':
                     ysiz = atoi(argv[++an]);
                     break;
              case 'b':
                     setcolr(bgcolr, atof(argv[an+1]),
                                   atof(argv[an+2]),
                                   atof(argv[an+3]));
                     an += 3;
                     break;
              case 'a':
                     ncolumns = atoi(argv[++an]);
                     break;
              case 's':
                     spacing = atoi(argv[++an]);
                     break;
              case 'o':
                     curx = x0 = atoi(argv[++an]);
                     cury = atoi(argv[++an]);
                     break;
              case 'l':
                     switch (argv[an][2]) {
                     case 'a':
                            autolabel++;
                            break;
                     case 'h':
                            labelht = atoi(argv[++an]);
                            break;
                     case '\0':
                            goto dofiles;
                     default:
                            goto userr;
                     }
                     break;
              case '\0':
              case 't':
                     goto dofiles;
              default:
                     goto userr;
              }
dofiles:
       newheader("RADIANCE", stdout);
       fputnow(stdout);
       for (nfile = 0; an < argc; nfile++) {
              if (nfile >= MAXFILE)
                     goto toomany;
              thislabel = NULL;
              input[nfile].flags = 0;
              xsgn = ysgn = '-';
              while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+'
                            || argv[an][0] == '=')) {
                     switch (argv[an][1]) {
                     case 't':
                            checkthresh = 1;
                            if (argv[an][0] == '-') {
                                   input[nfile].flags |= HASMIN;
                                   input[nfile].thmin = atof(argv[an+1]);
                            } else if (argv[an][0] == '+') {
                                   input[nfile].flags |= HASMAX;
                                   input[nfile].thmax = atof(argv[an+1]);
                            } else
                                   goto userr;
                            an++;
                            break;
                     case 'l':
                            if (strcmp(argv[an], "-l"))
                                   goto userr;
                            thislabel = argv[++an];
                            break;
                     case '+':
                     case '-':
                     case '0':
                            if (argv[an][0] != '=')
                                   goto userr;
                            xsgn = argv[an][1];
                            ysgn = argv[an][2];
                            if (ysgn != '+' && ysgn != '-' && ysgn != '0')
                                   goto userr;
                            break;
                     case '\0':
                            if (argv[an][0] == '-')
                                   goto getfile;
                            goto userr;
                     default:
                            goto userr;
                     }
                     an++;
              }
getfile:
              if (argc-an < (ncolumns ? 1 : 3))
                     goto userr;
              if (autolabel && thislabel == NULL)
                     thislabel = argv[an];
              if (!strcmp(argv[an], "-")) {
                     input[nfile].name = StandardInput;
                     input[nfile].fp = stdin;
              } else {
                     if (argv[an][0] == '!') {
                            input[nfile].name = Command;
                            input[nfile].fp = popen(argv[an]+1, "r");
                     } else {
                            input[nfile].name = argv[an];
                            input[nfile].fp = fopen(argv[an], "r");
                     }
                     if (input[nfile].fp == NULL) {
                            perror(argv[an]);
                            quit(1);
                     }
              }
              an++;
                                          /* get header */
              if (echoheader)
                     printf("%s:\n", input[nfile].name);
              getheader(input[nfile].fp, headline, NULL);
              if (wrongformat) {
                     fprintf(stderr, "%s: incompatible input format\n",
                                   input[nfile].name);
                     quit(1);
              }
                                          /* get picture size */
              if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
                            input[nfile].fp) < 0) {
                     fprintf(stderr, "%s: bad picture size\n",
                                   input[nfile].name);
                     quit(1);
              }
              if (ncolumns > 0) {
                     if (curcol >= ncolumns) {
                            cury = ymax + spacing;
                            curx = x0;
                            curcol = 0;
                     }
                     input[nfile].xloc = curx;
                     input[nfile].yloc = cury;
                     curx += input[nfile].xres + spacing;
                     curcol++;
              } else {
                     input[nfile].xloc = atoi(argv[an++]);
                     if (xsgn == '+')
                            input[nfile].xloc -= input[nfile].xres;
                     else if (xsgn == '0')
                            input[nfile].xloc -= input[nfile].xres/2;
                     input[nfile].yloc = atoi(argv[an++]);
                     if (ysgn == '+')
                            input[nfile].yloc -= input[nfile].yres;
                     else if (ysgn == '0')
                            input[nfile].yloc -= input[nfile].yres/2;
              }
              if (input[nfile].xloc < xmin)
                     xmin = input[nfile].xloc;
              if (input[nfile].yloc < ymin)
                     ymin = input[nfile].yloc;
              if (input[nfile].xloc+input[nfile].xres > xmax)
                     xmax = input[nfile].xloc+input[nfile].xres;
              if (input[nfile].yloc+input[nfile].yres > ymax)
                     ymax = input[nfile].yloc+input[nfile].yres;
              if (thislabel != NULL) {
                     if (++nfile >= MAXFILE)
                            goto toomany;
                     input[nfile].name = Label;
                     input[nfile].flags = 0;
                     input[nfile].xres = input[nfile-1].xres;
                     input[nfile].yres = labelht;
                     if ((input[nfile].fp = lblopen(thislabel,
                                   &input[nfile].xres,
                                   &input[nfile].yres)) == NULL)
                            goto labelerr;
                     input[nfile].xloc = input[nfile-1].xloc;
                     input[nfile].yloc = input[nfile-1].yloc +
                                   input[nfile-1].yres-input[nfile].yres;
              }
       }
       if (xsiz <= 0)
              xsiz = xmax;
       else if (xsiz > xmax)
              xmax = xsiz;
       if (ysiz <= 0)
              ysiz = ymax;
       else if (ysiz > ymax)
              ymax = ysiz;
                                   /* add new header info. */
       printargs(argc, argv, stdout);
       if (strcmp(ourfmt, PICFMT))
              fputformat(ourfmt, stdout); /* print format if known */
       putchar('\n');
       fprtresolu(xsiz, ysiz, stdout);

       compos();
       
       quit(0);
userr:
       fprintf(stderr,
       "Usage: %s [-h][-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ",
                     progname);
       fprintf(stderr, "[-t min1][+t max1][-l lab][=SS] pic1 x1 y1 ..\n");
       quit(1);
toomany:
       fprintf(stderr, "%s: only %d files and labels allowed\n",
                     progname, MAXFILE);
       quit(1);
labelerr:
       fprintf(stderr, "%s: error opening label\n", progname);
       quit(1);
       return 1; /* pro forma return */
}

Here is the call graph for this function:

void quit ( int  code)

Definition at line 435 of file pcompos.c.

{
       register int  i;
                            /* close input files */
       for (i = 0; i < nfile; i++)
              if (input[i].name == Command || input[i].name == Label)
                     pclose(input[i].fp);
              else
                     fclose(input[i].fp);
       exit(code);
}

Variable Documentation

Definition at line 37 of file pcompos.c.

int checkthresh = 0

Definition at line 41 of file pcompos.c.

char Command[] = "<Command>"

Definition at line 44 of file pcompos.c.

int echoheader = 1

Definition at line 60 of file pcompos.c.

gethfunc headline [static]

Definition at line 65 of file pcompos.c.

struct { ... } input[MAXFILE]
char Label[] = "<Label>"

Definition at line 45 of file pcompos.c.

int labelht = 24

Definition at line 39 of file pcompos.c.

int nfile

Definition at line 58 of file pcompos.c.

char ourfmt[LPICFMT+1] = PICFMT

Definition at line 61 of file pcompos.c.

char* progname

Definition at line 47 of file pcompos.c.

const char RCSid[] = "$Id: pcompos.c,v 2.33 2009/08/10 04:26:38 greg Exp $" [static]

Definition at line 2 of file pcompos.c.

char StandardInput[] = "<stdin>"

Definition at line 43 of file pcompos.c.

int wrongformat = 0

Definition at line 62 of file pcompos.c.

int xmax = 0

Definition at line 34 of file pcompos.c.

int xmin = 0

Definition at line 32 of file pcompos.c.

int xsiz = 0

Definition at line 29 of file pcompos.c.

int ymax = 0

Definition at line 35 of file pcompos.c.

int ymin = 0

Definition at line 33 of file pcompos.c.

int ysiz = 0

Definition at line 30 of file pcompos.c.