Back to index

radiance  4R0+20100331
Defines | Functions | Variables
protate.c File Reference
#include "standard.h"
#include "color.h"
#include <time.h>
#include "resolu.h"

Go to the source code of this file.

Defines

#define scanbar   ((COLR *)buf)

Functions

static int neworder (void)
static void rotatecw (FILE *fp)
static void rotateccw (FILE *fp)
int main (int argc, char *argv[])

Variables

static const char RCSid [] = "$Id: protate.c,v 2.10 2004/04/30 20:29:24 greg Exp $"
int order
int xres
int yres
int correctorder = 0
int ccw = 0
char buf [1<< 22]
int nrows
char * progname
short ordertab [4][2]

Define Documentation

#define scanbar   ((COLR *)buf)

Definition at line 32 of file protate.c.


Function Documentation

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

Definition at line 75 of file protate.c.

{
       static char   picfmt[LPICFMT+1] = PICFMT;
       int    rval;
       FILE   *fin;

       progname = argv[0];

       while (argc > 2 && argv[1][0] == '-') {
              switch (argv[1][1]) {
              case 'c':
                     correctorder = 1;
                     break;
              case 'r':
                     ccw = 1;
                     break;
              default:
                     goto userr;
              }
              argc--; argv++;
       }
       if (argc != 2 && argc != 3)
              goto userr;
       if ((fin = fopen(argv[1], "r")) == NULL) {
              fprintf(stderr, "%s: cannot open\n", argv[1]);
              exit(1);
       }
       if (argc == 3 && freopen(argv[2], "w", stdout) == NULL) {
              fprintf(stderr, "%s: cannot open\n", argv[2]);
              exit(1);
       }
                                   /* transfer header */
       if ((rval = checkheader(fin, picfmt, stdout)) < 0) {
              fprintf(stderr, "%s: not a Radiance picture\n", progname);
              exit(1);
       }
       if (rval)
              fputformat(picfmt, stdout);
                                   /* add new header info. */
       fputs(progname, stdout);
       if (ccw) fputs(" -r", stdout);
       if (correctorder) fputs(" -c", stdout);
       fputs("\n\n", stdout);
                                   /* 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(), yres, xres, stdout);
                                   /* compute buffer capacity */
       nrows = sizeof(buf)/sizeof(COLR)/yres;
       if (ccw)                    /* rotate the image */
              rotateccw(fin);
       else
              rotatecw(fin);
       exit(0);
userr:
       fprintf(stderr, "Usage: %s [-r][-c] infile [outfile]\n", progname);
       exit(1);
}

Here is the call graph for this function:

static int neworder ( void  ) [static]

Definition at line 48 of file protate.c.

{
       static short    ordercw[8];
       register int  i;

       if (correctorder)
              return(order);
       if (!ordercw[0]) {
              ordercw[YMAJOR|YDECR] = 0;
              ordercw[0] = YMAJOR|XDECR;
              ordercw[YMAJOR|XDECR] = XDECR|YDECR;
              ordercw[XDECR|YDECR] = YMAJOR|YDECR;
              ordercw[YMAJOR|XDECR|YDECR] = XDECR;
              ordercw[XDECR] = YMAJOR;
              ordercw[YMAJOR] = YDECR;
              ordercw[YDECR] = YMAJOR|XDECR|YDECR;
       }
       if (!ccw)
              return(ordercw[order]);
       for (i = 8; i--; )
              if (ordercw[i] == order)
                     return(i);
       fputs("Order botch!\n", stderr);
       exit(2);
}

Here is the caller graph for this function:

static void rotateccw ( FILE *  fp) [static]

Definition at line 180 of file protate.c.

{
       register COLR *inln;
       register int  xoff, inx, iny;
       long   start, ftell();

       if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
              fprintf(stderr, "%s: out of memory\n", progname);
              exit(1);
       }
       start = ftell(fp);
       for (xoff = xres-1; xoff >= 0; xoff -= nrows) {
              if (fseek(fp, start, 0) < 0) {
                     fprintf(stderr, "%s: seek error\n", progname);
                     exit(1);
              }
              for (iny = 0; iny < yres; iny++) {
                     if (freadcolrs(inln, xres, fp) < 0) {
                            fprintf(stderr, "%s: read error\n", progname);
                            exit(1);
                     }
                     for (inx = 0; inx < nrows && xoff-inx >= 0; inx++)
                            copycolr(scanbar[inx*yres+iny],
                                          inln[xoff-inx]);
              }
              for (inx = 0; inx < nrows && xoff-inx >= 0; inx++)
                     if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) {
                            fprintf(stderr, "%s: write error\n", progname);
                            exit(1);
                     }
       }
       free((void *)inln);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void rotatecw ( FILE *  fp) [static]

Definition at line 142 of file protate.c.

{
       register COLR *inln;
       register int  xoff, inx, iny;
       long   start, ftell();

       if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
              fprintf(stderr, "%s: out of memory\n", progname);
              exit(1);
       }
       start = ftell(fp);
       for (xoff = 0; xoff < xres; xoff += nrows) {
              if (fseek(fp, start, 0) < 0) {
                     fprintf(stderr, "%s: seek error\n", progname);
                     exit(1);
              }
              for (iny = yres-1; iny >= 0; iny--) {
                     if (freadcolrs(inln, xres, fp) < 0) {
                            fprintf(stderr, "%s: read error\n", progname);
                            exit(1);
                     }
                     for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
                            copycolr(scanbar[inx*yres+iny],
                                          inln[xoff+inx]);
              }
              for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
                     if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) {
                            fprintf(stderr, "%s: write error\n", progname);
                            exit(1);
                     }
       }
       free((void *)inln);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char buf[1<< 22]

Definition at line 27 of file protate.c.

int ccw = 0

Definition at line 22 of file protate.c.

int correctorder = 0

Definition at line 21 of file protate.c.

int nrows

Definition at line 30 of file protate.c.

int order

Definition at line 18 of file protate.c.

short ordertab[4][2]
Initial value:
 {
       {0,0}, {XDECR,XDECR|YDECR}, {XDECR|YDECR,YDECR}, {YDECR,XDECR}
}

Definition at line 36 of file protate.c.

char* progname

Definition at line 34 of file protate.c.

const char RCSid[] = "$Id: protate.c,v 2.10 2004/04/30 20:29:24 greg Exp $" [static]

Definition at line 2 of file protate.c.

int xres

Definition at line 19 of file protate.c.

int yres

Definition at line 19 of file protate.c.