| 1 | 
– | 
/* Copyright (c) 1991 Regents of the University of California */ | 
| 2 | 
– | 
 | 
| 1 | 
  | 
#ifndef lint | 
| 2 | 
< | 
static char SCCSid[] = "$SunId$ LBL"; | 
| 2 | 
> | 
static const char       RCSid[] = "$Id$"; | 
| 3 | 
  | 
#endif | 
| 6 | 
– | 
 | 
| 4 | 
  | 
/* | 
| 5 | 
  | 
 * flip picture file horizontally and/or vertically | 
| 6 | 
  | 
 */ | 
| 7 | 
  | 
 | 
| 8 | 
  | 
#include <stdio.h> | 
| 9 | 
+ | 
#include  <time.h> | 
| 10 | 
+ | 
#include  <string.h> | 
| 11 | 
  | 
 | 
| 12 | 
+ | 
#include "platform.h" | 
| 13 | 
  | 
#include "color.h" | 
| 14 | 
– | 
 | 
| 14 | 
  | 
#include "resolu.h" | 
| 15 | 
  | 
 | 
| 16 | 
  | 
int     order;                          /* input orientation */ | 
| 27 | 
  | 
char    *progname; | 
| 28 | 
  | 
 | 
| 29 | 
  | 
 | 
| 30 | 
< | 
int | 
| 31 | 
< | 
neworder()                      /* figure out new order from old */ | 
| 30 | 
> | 
static void memerr(void); | 
| 31 | 
> | 
static void scanfile(void); | 
| 32 | 
> | 
static void flip(void); | 
| 33 | 
> | 
 | 
| 34 | 
> | 
 | 
| 35 | 
> | 
static int | 
| 36 | 
> | 
neworder(void)                  /* figure out new order from old */ | 
| 37 | 
  | 
{ | 
| 38 | 
  | 
        register int  no; | 
| 39 | 
  | 
 | 
| 49 | 
  | 
        return(no); | 
| 50 | 
  | 
} | 
| 51 | 
  | 
 | 
| 52 | 
< | 
 | 
| 53 | 
< | 
main(argc, argv) | 
| 54 | 
< | 
int     argc; | 
| 55 | 
< | 
char    *argv[]; | 
| 52 | 
> | 
int | 
| 53 | 
> | 
main( | 
| 54 | 
> | 
        int     argc, | 
| 55 | 
> | 
        char    *argv[] | 
| 56 | 
> | 
) | 
| 57 | 
  | 
{ | 
| 58 | 
< | 
        int     i; | 
| 59 | 
< | 
 | 
| 58 | 
> | 
        static char     picfmt[LPICFMT+1] = PICFMT; | 
| 59 | 
> | 
        int     i, rval; | 
| 60 | 
> | 
        SET_DEFAULT_BINARY(); | 
| 61 | 
> | 
        SET_FILE_BINARY(stdout); | 
| 62 | 
  | 
        progname = argv[0]; | 
| 63 | 
  | 
 | 
| 64 | 
  | 
        for (i = 1; i < argc; i++) | 
| 76 | 
  | 
                exit(1); | 
| 77 | 
  | 
        } | 
| 78 | 
  | 
        if ((fin = fopen(argv[i], "r")) == NULL) { | 
| 79 | 
< | 
                fprintf(stderr, "%s: cannot open\n", argv[1]); | 
| 79 | 
> | 
                fprintf(stderr, "%s: cannot open\n", argv[i]); | 
| 80 | 
  | 
                exit(1); | 
| 81 | 
  | 
        } | 
| 82 | 
  | 
        if (i < argc-1 && freopen(argv[i+1], "w", stdout) == NULL) { | 
| 84 | 
  | 
                exit(1); | 
| 85 | 
  | 
        } | 
| 86 | 
  | 
                                        /* transfer header */ | 
| 87 | 
< | 
        if (checkheader(fin, COLRFMT, stdout) < 0) { | 
| 87 | 
> | 
        if ((rval = checkheader(fin, picfmt, stdout)) < 0) { | 
| 88 | 
  | 
                fprintf(stderr, "%s: input not a Radiance picture\n", | 
| 89 | 
  | 
                                progname); | 
| 90 | 
  | 
                exit(1); | 
| 91 | 
  | 
        } | 
| 92 | 
+ | 
        if (rval) | 
| 93 | 
+ | 
                fputformat(picfmt, stdout); | 
| 94 | 
  | 
                                        /* add new header info. */ | 
| 95 | 
  | 
        printargs(i, argv, stdout); | 
| 87 | 
– | 
        fputformat(COLRFMT, stdout); | 
| 96 | 
  | 
        putchar('\n'); | 
| 97 | 
  | 
                                        /* get picture size */ | 
| 98 | 
  | 
        if ((order = fgetresolu(&xres, &yres, fin)) < 0) { | 
| 109 | 
  | 
} | 
| 110 | 
  | 
 | 
| 111 | 
  | 
 | 
| 112 | 
< | 
memerr() | 
| 112 | 
> | 
static void | 
| 113 | 
> | 
memerr(void) | 
| 114 | 
  | 
{ | 
| 115 | 
  | 
        fprintf(stderr, "%s: out of memory\n", progname); | 
| 116 | 
  | 
        exit(1); | 
| 117 | 
  | 
} | 
| 118 | 
  | 
 | 
| 119 | 
  | 
 | 
| 120 | 
< | 
scanfile()                              /* scan to the end of file */ | 
| 120 | 
> | 
static void | 
| 121 | 
> | 
scanfile(void)                          /* scan to the end of file */ | 
| 122 | 
  | 
{ | 
| 123 | 
  | 
        extern long     ftell(); | 
| 124 | 
  | 
        COLR    *scanin; | 
| 128 | 
  | 
                memerr(); | 
| 129 | 
  | 
        if ((scanin = (COLR *)malloc(xres*sizeof(COLR))) == NULL) | 
| 130 | 
  | 
                memerr(); | 
| 131 | 
< | 
        for (y = yres-1; y >= 0; y--) { | 
| 131 | 
> | 
        for (y = yres-1; y > 0; y--) { | 
| 132 | 
  | 
                scanpos[y] = ftell(fin); | 
| 133 | 
  | 
                if (freadcolrs(scanin, xres, fin) < 0) { | 
| 134 | 
  | 
                        fprintf(stderr, "%s: read error\n", progname); | 
| 135 | 
  | 
                        exit(1); | 
| 136 | 
  | 
                } | 
| 137 | 
  | 
        } | 
| 138 | 
< | 
        free((char *)scanin); | 
| 138 | 
> | 
        scanpos[0] = ftell(fin); | 
| 139 | 
> | 
        free((void *)scanin); | 
| 140 | 
  | 
} | 
| 141 | 
  | 
 | 
| 142 | 
  | 
 | 
| 143 | 
< | 
flip()                                  /* flip the picture */ | 
| 143 | 
> | 
static void | 
| 144 | 
> | 
flip(void)                                      /* flip the picture */ | 
| 145 | 
  | 
{ | 
| 146 | 
  | 
        COLR    *scanin, *scanout; | 
| 147 | 
  | 
        int     y; | 
| 171 | 
  | 
                        exit(1); | 
| 172 | 
  | 
                } | 
| 173 | 
  | 
        } | 
| 174 | 
< | 
        free((char *)scanin); | 
| 175 | 
< | 
        free((char *)scanout); | 
| 174 | 
> | 
        free((void *)scanin); | 
| 175 | 
> | 
        if (fhoriz) | 
| 176 | 
> | 
                free((void *)scanout); | 
| 177 | 
  | 
} |