Back to index

radiance  4R0+20100331
Functions | Variables
pflip.c File Reference
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "platform.h"
#include "color.h"
#include "resolu.h"

Go to the source code of this file.

Functions

static void memerr (void)
static void scanfile (void)
static void flip (void)
static int neworder (void)
int main (int argc, char *argv[])

Variables

static const char RCSid [] = "$Id: pflip.c,v 2.9 2006/08/08 18:04:41 greg Exp $"
int order
int xres
int yres
long * scanpos
int fhoriz = 0
int fvert = 0
int correctorder = 0
FILE * fin
char * progname

Function Documentation

static void flip ( void  ) [static]

Definition at line 144 of file pflip.c.

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

       if ((scanin = (COLR *)malloc(xres*sizeof(COLR))) == NULL)
              memerr();
       if (fhoriz) {
              if ((scanout = (COLR *)malloc(xres*sizeof(COLR))) == NULL)
                     memerr();
       } else
              scanout = scanin;
       for (y = yres-1; y >= 0; y--) {
              if (fvert && fseek(fin, scanpos[yres-1-y], 0) == EOF) {
                     fprintf(stderr, "%s: seek error\n", progname);
                     exit(1);
              }
              if (freadcolrs(scanin, xres, fin) < 0) {
                     fprintf(stderr, "%s: read error\n", progname);
                     exit(1);
              }
              if (fhoriz)
                     for (x = 0; x < xres; x++)
                            copycolr(scanout[x], scanin[xres-1-x]);
              if (fwritecolrs(scanout, xres, stdout) < 0) {
                     fprintf(stderr, "%s: write error\n", progname);
                     exit(1);
              }
       }
       free((void *)scanin);
       if (fhoriz)
              free((void *)scanout);
}

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 53 of file pflip.c.

{
       static char   picfmt[LPICFMT+1] = PICFMT;
       int    i, rval;
       SET_DEFAULT_BINARY();
       SET_FILE_BINARY(stdout);
       progname = argv[0];

       for (i = 1; i < argc; i++)
              if (!strcmp(argv[i], "-h"))
                     fhoriz++;
              else if (!strcmp(argv[i], "-v"))
                     fvert++;
              else if (!strcmp(argv[i], "-c"))
                     correctorder++;
              else
                     break;
       if (i >= argc || argv[i][0] == '-') {
              fprintf(stderr, "Usage: %s [-h][-v][-c] infile [outfile]\n",
                            progname);
              exit(1);
       }
       if ((fin = fopen(argv[i], "r")) == NULL) {
              fprintf(stderr, "%s: cannot open\n", argv[i]);
              exit(1);
       }
       if (i < argc-1 && freopen(argv[i+1], "w", stdout) == NULL) {
              fprintf(stderr, "%s: cannot open\n", argv[i+1]);
              exit(1);
       }
                                   /* transfer header */
       if ((rval = checkheader(fin, picfmt, stdout)) < 0) {
              fprintf(stderr, "%s: input not a Radiance picture\n",
                            progname);
              exit(1);
       }
       if (rval)
              fputformat(picfmt, stdout);
                                   /* add new header info. */
       printargs(i, argv, stdout);
       putchar('\n');
                                   /* get picture size */
       if ((order = fgetresolu(&xres, &yres, fin)) < 0) {
              fprintf(stderr, "%s: bad picture size\n", progname);
              exit(1);
       }
                                   /* write new picture size */
       fputresolu(neworder(), xres, yres, stdout);
                                   /* goto end if vertical flip */
       if (fvert)
              scanfile();
       flip();                            /* flip the image */
       exit(0);
}

Here is the call graph for this function:

static void memerr ( void  ) [static]

Definition at line 113 of file pflip.c.

{
       fprintf(stderr, "%s: out of memory\n", progname);
       exit(1);
}
static int neworder ( void  ) [static]

Definition at line 36 of file pflip.c.

{
       register int  no;

       if (correctorder)
              return(order);              /* just leave it */
       if ((no = order) & YMAJOR) {
              if (fhoriz) no ^= XDECR;
              if (fvert) no ^= YDECR;
       } else {
              if (fhoriz) no ^= YDECR;
              if (fvert) no ^= XDECR;
       }
       return(no);
}

Here is the caller graph for this function:

static void scanfile ( void  ) [static]

Definition at line 121 of file pflip.c.

{
       extern long   ftell();
       COLR   *scanin;
       int    y;

       if ((scanpos = (long *)malloc(yres*sizeof(long))) == NULL)
              memerr();
       if ((scanin = (COLR *)malloc(xres*sizeof(COLR))) == NULL)
              memerr();
       for (y = yres-1; y > 0; y--) {
              scanpos[y] = ftell(fin);
              if (freadcolrs(scanin, xres, fin) < 0) {
                     fprintf(stderr, "%s: read error\n", progname);
                     exit(1);
              }
       }
       scanpos[0] = ftell(fin);
       free((void *)scanin);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int correctorder = 0

Definition at line 23 of file pflip.c.

int fhoriz = 0

Definition at line 21 of file pflip.c.

FILE* fin

Definition at line 25 of file pflip.c.

int fvert = 0

Definition at line 21 of file pflip.c.

int order

Definition at line 16 of file pflip.c.

char* progname

Definition at line 27 of file pflip.c.

const char RCSid[] = "$Id: pflip.c,v 2.9 2006/08/08 18:04:41 greg Exp $" [static]

Definition at line 2 of file pflip.c.

long* scanpos

Definition at line 19 of file pflip.c.

int xres

Definition at line 17 of file pflip.c.

int yres

Definition at line 17 of file pflip.c.