Back to index

radiance  4R0+20100331
Defines | Functions | Variables
meta2tga.c File Reference
#include "copyright.h"
#include "rtprocess.h"
#include "meta.h"
#include "plot.h"
#include "rast.h"
#include "targa.h"

Go to the source code of this file.

Defines

#define MAXALLOC   30000
#define DXSIZE   400 /* default x resolution */
#define DYSIZE   400 /* default y resolution */
#define XCOM   "pexpand +vOCImsp -DP %s | psort +y"
#define MINRUN   4

Functions

static int putthead (struct hdStruct *hp, char *ip, FILE *fp)
char * findtack (char *s)
int main (int argc, char **argv)
void thispage (void)
void initfile (void)
void nextpage (void)
void printblock (void)
void putint2 (register int i, register FILE *fp)
int putthead (struct hdStruct *hp, char *ip, register FILE *fp)

Variables

static const char RCSid [] = "$Id: meta2tga.c,v 1.6 2004/02/04 18:49:24 greg Exp $"
char * progname
SCANBLOCK outblock
int dxsize = DXSIZE
int dysize = DYSIZE
int maxalloc = MAXALLOC
int ydown = 0
static char outname [64]
static char * outtack = NULL
static FILE * fout
static int lineno = 0
static short condonly = FALSE
static short conditioned = FALSE

Define Documentation

#define DXSIZE   400 /* default x resolution */

Definition at line 17 of file meta2tga.c.

#define DYSIZE   400 /* default y resolution */

Definition at line 18 of file meta2tga.c.

#define MAXALLOC   30000

Definition at line 16 of file meta2tga.c.

#define MINRUN   4

Definition at line 213 of file meta2tga.c.

#define XCOM   "pexpand +vOCImsp -DP %s | psort +y"

Definition at line 19 of file meta2tga.c.


Function Documentation

char* findtack ( char *  s)

Definition at line 47 of file meta2tga.c.

{
       while (*s && *s != '.')
              s++;
       return(s);
}
void initfile ( void  )

Definition at line 154 of file meta2tga.c.

{
    static int  filenum = 0;
    /*
    static unsigned char  cmap[24] = {255,255,255, 255,152,0, 0,188,0, 0,0,255,
                     179,179,0, 255,0,255, 0,200,200, 0,0,0};
     */
    static unsigned char  cmap[24] = {0,0,0, 0,0,255, 0,188,0, 255,152,0,
                     0,200,200, 255,0,255, 179,179,0, 255,255,255};
    struct hdStruct  thead;
    register int  i;

    if (outtack != NULL) {
       sprintf(outtack, "%d.tga", ++filenum);
       fout = efopen(outname, "w");
    }
    if (fout == NULL)
       error(USER, "no output file");
    thead.mapType = CM_HASMAP;
    thead.dataType = IM_CCMAP;
    thead.mapOrig = 0;
    thead.mapLength = 256;
    thead.CMapBits = 24;
    thead.XOffset = 0;
    thead.YOffset = 0;
    thead.x = dxsize;
    thead.y = dysize;
    thead.dataBits = 8;
    thead.imType = 0;
    putthead(&thead, NULL, fout);
    for (i = 0; i < 8*3; i++)
       putc(cmap[i], fout);
    while (i++ < 256*3)
       putc(0, fout);
}

Here is the call graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 57 of file meta2tga.c.

{
 FILE  *fp;
 char  comargs[200], command[300];

  fout = stdout;
 progname = *argv++;
 argc--;

 condonly = FALSE;
 conditioned = FALSE;
 
 while (argc && **argv == '-')  {
    switch (*(*argv+1))  {
       case 'c':
         condonly = TRUE;
         break;
       case 'r':
         conditioned = TRUE;
         break;
       case 'm':
         minwidth = atoi(*++argv);
         argc--;
         break;
       case 'x':
         dxsize = atoi(*++argv);
         argc--;
         break;
       case 'y':
         dysize = atoi(*++argv);
         argc--;
         break;
       case 'o':
         strcpy(outname, *++argv);
         outtack = findtack(outname);
         argc--;
         break;
       default:
         error(WARNING, "unknown option");
         break;
       }
    argv++;
    argc--;
    }

 if (conditioned) {
    if (argc)
       while (argc)  {
         fp = efopen(*argv, "r");
         plot(fp);
         fclose(fp);
         argv++;
         argc--;
         }
    else
       plot(stdin);
    if (lineno)
       nextpage();
 } else  {
    comargs[0] = '\0';
    while (argc)  {
       strcat(comargs, " ");
       strcat(comargs, *argv);
       argv++;
       argc--;
       }
    sprintf(command, XCOM, comargs);
    if (condonly)
       return(system(command));
    else  {
       if ((fp = popen(command, "r")) == NULL)
          error(SYSTEM, "cannot execute input filter");
       plot(fp);
       pclose(fp);
       if (lineno)
         nextpage();
       }
    }

 return(0);
 }

Here is the call graph for this function:

void nextpage ( void  )

Definition at line 193 of file meta2tga.c.

{

    if (lineno == 0)
       return;
    if (fout != NULL) {
       while (lineno < dysize) {
           nextblock();
           outputblock();
       }
       fclose(fout);
       fout = NULL;
    }
    lineno = 0;

}

Here is the call graph for this function:

void printblock ( void  )

Definition at line 216 of file meta2tga.c.

{
    int  i, c2;
    register unsigned char  *scanline;
    register int  j, beg, cnt = 0;

    if (lineno == 0)
       initfile();
    for (i = outblock.ybot; i <= outblock.ytop && i < dysize; i++) {
       scanline = outblock.cols[i-outblock.ybot];
       for (j = outblock.xleft; j <= outblock.xright; j += cnt) {
           for (beg = j; beg <= outblock.xright; beg += cnt) {
              for (cnt = 1; cnt < 128 && beg+cnt <= outblock.xright &&
                     scanline[beg+cnt] == scanline[beg]; cnt++)
                  ;
              if (cnt >= MINRUN)
                  break;                  /* long enough */
           }
           while (j < beg) {              /* write out non-run */
              if ((c2 = beg-j) > 128) c2 = 128;
              putc(c2-1, fout);
              while (c2--)
                  putc(scanline[j++], fout);
           }
           if (cnt >= MINRUN) {           /* write out run */
              putc(127+cnt, fout);
              putc(scanline[beg], fout);
           } else
              cnt = 0;
       }
       lineno++;
    }
    
}

Here is the call graph for this function:

void putint2 ( register int  i,
register FILE *  fp 
)

Definition at line 254 of file meta2tga.c.

{
       putc(i&0xff, fp);
       putc(i>>8&0xff, fp);
}

Here is the caller graph for this function:

static int putthead ( struct hdStruct hp,
char *  ip,
FILE *  fp 
) [static]

Here is the caller graph for this function:

int putthead ( struct hdStruct hp,
char *  ip,
register FILE *  fp 
)

Definition at line 265 of file meta2tga.c.

{
       if (ip != NULL)
              putc(strlen(ip), fp);
       else
              putc(0, fp);
       putc(hp->mapType, fp);
       putc(hp->dataType, fp);
       putint2(hp->mapOrig, fp);
       putint2(hp->mapLength, fp);
       putc(hp->CMapBits, fp);
       putint2(hp->XOffset, fp);
       putint2(hp->YOffset, fp);
       putint2(hp->x, fp);
       putint2(hp->y, fp);
       putc(hp->dataBits, fp);
       putc(hp->imType, fp);

       if (ip != NULL)
              fputs(ip, fp);

       return(ferror(fp) ? -1 : 0);
}

Here is the call graph for this function:

void thispage ( void  )

Definition at line 146 of file meta2tga.c.

{
    if (lineno)
       error(USER, "cannot restart page in thispage");
}

Here is the call graph for this function:


Variable Documentation

short conditioned = FALSE [static]

Definition at line 40 of file meta2tga.c.

short condonly = FALSE [static]

Definition at line 39 of file meta2tga.c.

int dxsize = DXSIZE

Definition at line 26 of file meta2tga.c.

int dysize = DYSIZE

Definition at line 26 of file meta2tga.c.

FILE* fout [static]

Definition at line 35 of file meta2tga.c.

int lineno = 0 [static]

Definition at line 37 of file meta2tga.c.

Definition at line 28 of file meta2tga.c.

Definition at line 24 of file meta2tga.c.

char outname[64] [static]

Definition at line 32 of file meta2tga.c.

char* outtack = NULL [static]

Definition at line 33 of file meta2tga.c.

char* progname

Definition at line 22 of file meta2tga.c.

const char RCSid[] = "$Id: meta2tga.c,v 1.6 2004/02/04 18:49:24 greg Exp $" [static]

Definition at line 2 of file meta2tga.c.

int ydown = 0

Definition at line 30 of file meta2tga.c.