| 19 | 
  | 
#include "calcomp.h" | 
| 20 | 
  | 
 | 
| 21 | 
  | 
#define MAXINP          32              /* maximum number of input files */ | 
| 22 | 
+ | 
#define WINSIZ          9               /* scanline window size */ | 
| 23 | 
+ | 
#define MIDSCN          4               /* current scan position */ | 
| 24 | 
  | 
 | 
| 25 | 
+ | 
#define BRT             (-1)            /* special index for brightness */ | 
| 26 | 
+ | 
 | 
| 27 | 
  | 
struct { | 
| 28 | 
  | 
        char    *name;          /* file name */ | 
| 29 | 
  | 
        FILE    *fp;            /* stream pointer */ | 
| 30 | 
< | 
        COLOR   *scan;          /* input scanline */ | 
| 30 | 
> | 
        COLOR   *scan[WINSIZ];  /* input scanline window */ | 
| 31 | 
  | 
        COLOR   coef;           /* coefficient */ | 
| 32 | 
  | 
}       input[MAXINP];                  /* input pictures */ | 
| 33 | 
  | 
 | 
| 35 | 
  | 
 | 
| 36 | 
  | 
char    *vcolin[3] = {"ri", "gi", "bi"}; | 
| 37 | 
  | 
char    *vcolout[3] = {"ro", "go", "bo"}; | 
| 38 | 
< | 
#define vbrtin          "li" | 
| 39 | 
< | 
#define vbrtout         "lo" | 
| 38 | 
> | 
char    vbrtin[] = "li"; | 
| 39 | 
> | 
char    vbrtout[] = "lo"; | 
| 40 | 
> | 
char    *vcolcoef[3] = {"rc", "gc", "bc"}; | 
| 41 | 
> | 
char    vbrtcoef[] = "lc"; | 
| 42 | 
  | 
 | 
| 43 | 
  | 
#define vnfiles         "nfiles" | 
| 44 | 
  | 
#define vxres           "xres" | 
| 57 | 
  | 
int     wrongformat = 0; | 
| 58 | 
  | 
 | 
| 59 | 
  | 
 | 
| 54 | 
– | 
tputs(s)                        /* put out string preceded by a tab */ | 
| 55 | 
– | 
char    *s; | 
| 56 | 
– | 
{ | 
| 57 | 
– | 
        char    fmt[32]; | 
| 58 | 
– | 
        double  d; | 
| 59 | 
– | 
        COLOR   ctmp; | 
| 60 | 
– | 
 | 
| 61 | 
– | 
        if (isformat(s)) {                      /* check format */ | 
| 62 | 
– | 
                formatval(fmt, s); | 
| 63 | 
– | 
                wrongformat = strcmp(fmt, COLRFMT); | 
| 64 | 
– | 
        } else if (original && isexpos(s)) {    /* exposure */ | 
| 65 | 
– | 
                d = 1.0/exposval(s); | 
| 66 | 
– | 
                scalecolor(input[nfiles].coef, d); | 
| 67 | 
– | 
        } else if (original && iscolcor(s)) {   /* color correction */ | 
| 68 | 
– | 
                colcorval(ctmp, s); | 
| 69 | 
– | 
                colval(input[nfiles].coef,RED) /= colval(ctmp,RED); | 
| 70 | 
– | 
                colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN); | 
| 71 | 
– | 
                colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU); | 
| 72 | 
– | 
        } else {                                /* echo unaffected line */ | 
| 73 | 
– | 
                putchar('\t'); | 
| 74 | 
– | 
                fputs(s, stdout); | 
| 75 | 
– | 
        } | 
| 76 | 
– | 
 | 
| 77 | 
– | 
} | 
| 78 | 
– | 
 | 
| 79 | 
– | 
 | 
| 60 | 
  | 
main(argc, argv) | 
| 61 | 
  | 
int     argc; | 
| 62 | 
  | 
char    *argv[]; | 
| 63 | 
  | 
{ | 
| 84 | 
– | 
        extern double   l_redin(), l_grnin(), l_bluin(), l_brtin(), atof(); | 
| 64 | 
  | 
        double  f; | 
| 65 | 
< | 
        int     a; | 
| 66 | 
< | 
         | 
| 67 | 
< | 
        funset(vcolin[RED], 1, '=', l_redin); | 
| 89 | 
< | 
        funset(vcolin[GRN], 1, '=', l_grnin); | 
| 90 | 
< | 
        funset(vcolin[BLU], 1, '=', l_bluin); | 
| 91 | 
< | 
        funset(vbrtin, 1, '=', l_brtin); | 
| 92 | 
< | 
         | 
| 93 | 
< | 
        for (a = 1; a < argc; a++) | 
| 65 | 
> | 
        int     a, i; | 
| 66 | 
> | 
                                                /* scan options */ | 
| 67 | 
> | 
        for (a = 1; a < argc; a++) { | 
| 68 | 
  | 
                if (argv[a][0] == '-') | 
| 69 | 
  | 
                        switch (argv[a][1]) { | 
| 96 | 
– | 
                        case '\0': | 
| 97 | 
– | 
                        case 's': | 
| 98 | 
– | 
                        case 'c': | 
| 99 | 
– | 
                                goto getfiles; | 
| 70 | 
  | 
                        case 'x': | 
| 71 | 
  | 
                                xres = atoi(argv[++a]); | 
| 72 | 
< | 
                                break; | 
| 72 | 
> | 
                                continue; | 
| 73 | 
  | 
                        case 'y': | 
| 74 | 
  | 
                                yres = atoi(argv[++a]); | 
| 75 | 
< | 
                                break; | 
| 75 | 
> | 
                                continue; | 
| 76 | 
  | 
                        case 'w': | 
| 77 | 
  | 
                                nowarn = !nowarn; | 
| 78 | 
< | 
                                break; | 
| 78 | 
> | 
                                continue; | 
| 79 | 
  | 
                        case 'o': | 
| 80 | 
  | 
                                original = !original; | 
| 81 | 
< | 
                                break; | 
| 81 | 
> | 
                                continue; | 
| 82 | 
  | 
                        case 'f': | 
| 113 | 
– | 
                                fcompile(argv[++a]); | 
| 114 | 
– | 
                                break; | 
| 83 | 
  | 
                        case 'e': | 
| 84 | 
< | 
                                scompile(argv[++a], NULL, 0); | 
| 85 | 
< | 
                                break; | 
| 118 | 
< | 
                        default: | 
| 119 | 
< | 
                                goto usage; | 
| 84 | 
> | 
                                a++; | 
| 85 | 
> | 
                                continue; | 
| 86 | 
  | 
                        } | 
| 87 | 
< | 
                else | 
| 88 | 
< | 
                        break; | 
| 89 | 
< | 
getfiles: | 
| 87 | 
> | 
                break; | 
| 88 | 
> | 
        } | 
| 89 | 
> | 
                                        /* process files */ | 
| 90 | 
  | 
        for (nfiles = 0; nfiles < MAXINP; nfiles++) | 
| 91 | 
  | 
                setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); | 
| 92 | 
  | 
        nfiles = 0; | 
| 122 | 
  | 
                                quit(1); | 
| 123 | 
  | 
                        } | 
| 124 | 
  | 
                } | 
| 125 | 
< | 
                fputs(input[nfiles].name, stdout); | 
| 160 | 
< | 
                fputs(":\n", stdout); | 
| 161 | 
< | 
                getheader(input[nfiles].fp, tputs, NULL); | 
| 162 | 
< | 
                if (wrongformat) { | 
| 163 | 
< | 
                        eputs(input[nfiles].name); | 
| 164 | 
< | 
                        eputs(": not in Radiance picture format\n"); | 
| 165 | 
< | 
                        quit(1); | 
| 166 | 
< | 
                } | 
| 167 | 
< | 
                if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != | 
| 168 | 
< | 
                                (YMAJOR|YDECR)) { | 
| 169 | 
< | 
                        eputs(input[nfiles].name); | 
| 170 | 
< | 
                        eputs(": bad picture size\n"); | 
| 171 | 
< | 
                        quit(1); | 
| 172 | 
< | 
                } | 
| 173 | 
< | 
                if (xres == 0 && yres == 0) { | 
| 174 | 
< | 
                        xres = xpos; | 
| 175 | 
< | 
                        yres = ypos; | 
| 176 | 
< | 
                } else if (xpos != xres || ypos != yres) { | 
| 177 | 
< | 
                        eputs(argv[0]); | 
| 178 | 
< | 
                        eputs(": resolution mismatch\n"); | 
| 179 | 
< | 
                        quit(1); | 
| 180 | 
< | 
                } | 
| 181 | 
< | 
                input[nfiles].scan = (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 125 | 
> | 
                checkfile(); | 
| 126 | 
  | 
                nfiles++; | 
| 127 | 
  | 
        } | 
| 128 | 
+ | 
        init();                         /* set constant expressions */ | 
| 129 | 
+ | 
                                        /* go back and get expressions */ | 
| 130 | 
+ | 
        for (a = 1; a < argc; a++) { | 
| 131 | 
+ | 
                if (argv[a][0] == '-') | 
| 132 | 
+ | 
                        switch (argv[a][1]) { | 
| 133 | 
+ | 
                        case 'x': | 
| 134 | 
+ | 
                        case 'y': | 
| 135 | 
+ | 
                                a++; | 
| 136 | 
+ | 
                                continue; | 
| 137 | 
+ | 
                        case 'w': | 
| 138 | 
+ | 
                        case 'o': | 
| 139 | 
+ | 
                                continue; | 
| 140 | 
+ | 
                        case 'f': | 
| 141 | 
+ | 
                                fcompile(argv[++a]); | 
| 142 | 
+ | 
                                continue; | 
| 143 | 
+ | 
                        case 'e': | 
| 144 | 
+ | 
                                scompile(argv[++a], NULL, 0); | 
| 145 | 
+ | 
                                continue; | 
| 146 | 
+ | 
                        } | 
| 147 | 
+ | 
                break; | 
| 148 | 
+ | 
        } | 
| 149 | 
+ | 
                                                /* complete header */ | 
| 150 | 
  | 
        printargs(argc, argv, stdout); | 
| 151 | 
  | 
        fputformat(COLRFMT, stdout); | 
| 152 | 
  | 
        putchar('\n'); | 
| 153 | 
  | 
        fputresolu(YMAJOR|YDECR, xres, yres, stdout); | 
| 154 | 
+ | 
                                                /* combine pictures */ | 
| 155 | 
  | 
        combine(); | 
| 156 | 
  | 
        quit(0); | 
| 157 | 
  | 
usage: | 
| 163 | 
  | 
} | 
| 164 | 
  | 
 | 
| 165 | 
  | 
 | 
| 166 | 
+ | 
tputs(s)                        /* put out string preceded by a tab */ | 
| 167 | 
+ | 
char    *s; | 
| 168 | 
+ | 
{ | 
| 169 | 
+ | 
        char    fmt[32]; | 
| 170 | 
+ | 
        double  d; | 
| 171 | 
+ | 
        COLOR   ctmp; | 
| 172 | 
+ | 
 | 
| 173 | 
+ | 
        if (isformat(s)) {                      /* check format */ | 
| 174 | 
+ | 
                formatval(fmt, s); | 
| 175 | 
+ | 
                wrongformat = strcmp(fmt, COLRFMT); | 
| 176 | 
+ | 
        } else if (original && isexpos(s)) {    /* exposure */ | 
| 177 | 
+ | 
                d = 1.0/exposval(s); | 
| 178 | 
+ | 
                scalecolor(input[nfiles].coef, d); | 
| 179 | 
+ | 
        } else if (original && iscolcor(s)) {   /* color correction */ | 
| 180 | 
+ | 
                colcorval(ctmp, s); | 
| 181 | 
+ | 
                colval(input[nfiles].coef,RED) /= colval(ctmp,RED); | 
| 182 | 
+ | 
                colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN); | 
| 183 | 
+ | 
                colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU); | 
| 184 | 
+ | 
        } else {                                /* echo unaffected line */ | 
| 185 | 
+ | 
                putchar('\t'); | 
| 186 | 
+ | 
                fputs(s, stdout); | 
| 187 | 
+ | 
        } | 
| 188 | 
+ | 
} | 
| 189 | 
+ | 
 | 
| 190 | 
+ | 
 | 
| 191 | 
+ | 
checkfile()                     /* ready a file */ | 
| 192 | 
+ | 
{ | 
| 193 | 
+ | 
        register int    i; | 
| 194 | 
+ | 
                                        /* process header */ | 
| 195 | 
+ | 
        fputs(input[nfiles].name, stdout); | 
| 196 | 
+ | 
        fputs(":\n", stdout); | 
| 197 | 
+ | 
        getheader(input[nfiles].fp, tputs, NULL); | 
| 198 | 
+ | 
        if (wrongformat) { | 
| 199 | 
+ | 
                eputs(input[nfiles].name); | 
| 200 | 
+ | 
                eputs(": not in Radiance picture format\n"); | 
| 201 | 
+ | 
                quit(1); | 
| 202 | 
+ | 
        } | 
| 203 | 
+ | 
        if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != (YMAJOR|YDECR)) { | 
| 204 | 
+ | 
                eputs(input[nfiles].name); | 
| 205 | 
+ | 
                eputs(": bad picture size\n"); | 
| 206 | 
+ | 
                quit(1); | 
| 207 | 
+ | 
        } | 
| 208 | 
+ | 
        if (xres == 0 && yres == 0) { | 
| 209 | 
+ | 
                xres = xpos; | 
| 210 | 
+ | 
                yres = ypos; | 
| 211 | 
+ | 
        } else if (xpos != xres || ypos != yres) { | 
| 212 | 
+ | 
                eputs(input[nfiles].name); | 
| 213 | 
+ | 
                eputs(": resolution mismatch\n"); | 
| 214 | 
+ | 
                quit(1); | 
| 215 | 
+ | 
        } | 
| 216 | 
+ | 
                                        /* allocate scanlines */ | 
| 217 | 
+ | 
        for (i = 0; i < WINSIZ; i++) | 
| 218 | 
+ | 
                input[nfiles].scan[i] = (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 219 | 
+ | 
} | 
| 220 | 
+ | 
 | 
| 221 | 
+ | 
 | 
| 222 | 
+ | 
init()                          /* perform final setup */ | 
| 223 | 
+ | 
{ | 
| 224 | 
+ | 
        double  l_colin(), l_coef(); | 
| 225 | 
+ | 
        register int    i; | 
| 226 | 
+ | 
                                                /* prime input */ | 
| 227 | 
+ | 
        for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--) | 
| 228 | 
+ | 
                advance(); | 
| 229 | 
+ | 
                                                /* define constants */ | 
| 230 | 
+ | 
        varset(vnfiles, ':', (double)nfiles); | 
| 231 | 
+ | 
        varset(vxres, ':', (double)xres); | 
| 232 | 
+ | 
        varset(vyres, ':', (double)yres); | 
| 233 | 
+ | 
                                                /* set functions */ | 
| 234 | 
+ | 
        for (i = 0; i < 3; i++) { | 
| 235 | 
+ | 
                funset(vcolcoef[i], 1, ':', l_coef); | 
| 236 | 
+ | 
                funset(vcolin[i], 1, '=', l_colin); | 
| 237 | 
+ | 
        } | 
| 238 | 
+ | 
        funset(vbrtcoef, 1, ':', l_coef); | 
| 239 | 
+ | 
        funset(vbrtin, 1, '=', l_colin); | 
| 240 | 
+ | 
} | 
| 241 | 
+ | 
 | 
| 242 | 
+ | 
 | 
| 243 | 
  | 
combine()                       /* combine pictures */ | 
| 244 | 
  | 
{ | 
| 245 | 
  | 
        EPNODE  *coldef[3], *brtdef; | 
| 257 | 
  | 
                brtdef = eparse(vbrtout); | 
| 258 | 
  | 
        else | 
| 259 | 
  | 
                brtdef = NULL; | 
| 216 | 
– | 
                                                /* predefine variables */ | 
| 217 | 
– | 
        varset(vnfiles, '=', (double)nfiles); | 
| 218 | 
– | 
        varset(vxres, '=', (double)xres); | 
| 219 | 
– | 
        varset(vyres, '=', (double)yres); | 
| 260 | 
  | 
                                                /* allocate scanline */ | 
| 261 | 
  | 
        scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 262 | 
  | 
                                                /* combine files */ | 
| 263 | 
  | 
        for (ypos = yres-1; ypos >= 0; ypos--) { | 
| 264 | 
< | 
            for (i = 0; i < nfiles; i++) | 
| 225 | 
< | 
                    if (freadscan(input[i].scan, xres, input[i].fp) < 0) { | 
| 226 | 
< | 
                            eputs(input[i].name); | 
| 227 | 
< | 
                            eputs(": read error\n"); | 
| 228 | 
< | 
                            quit(1); | 
| 229 | 
< | 
                    } | 
| 264 | 
> | 
            advance(); | 
| 265 | 
  | 
            varset(vypos, '=', (double)ypos); | 
| 266 | 
  | 
            for (xpos = 0; xpos < xres; xpos++) { | 
| 232 | 
– | 
                for (i = 0; i < nfiles; i++) | 
| 233 | 
– | 
                        multcolor(input[i].scan[xpos],input[i].coef); | 
| 267 | 
  | 
                varset(vxpos, '=', (double)xpos); | 
| 268 | 
  | 
                eclock++; | 
| 269 | 
  | 
                if (brtdef != NULL) { | 
| 278 | 
  | 
                        } else { | 
| 279 | 
  | 
                            d = 0.0; | 
| 280 | 
  | 
                            for (i = 0; i < nfiles; i++) | 
| 281 | 
< | 
                                d += colval(input[i].scan[xpos],j); | 
| 281 | 
> | 
                                d += colval(input[i].scan[MIDSCN][xpos],j); | 
| 282 | 
  | 
                        } | 
| 283 | 
  | 
                        if (d < 0.0) | 
| 284 | 
  | 
                            d = 0.0; | 
| 295 | 
  | 
} | 
| 296 | 
  | 
 | 
| 297 | 
  | 
 | 
| 298 | 
< | 
double | 
| 266 | 
< | 
colin(fn, ci)                   /* return color value for picture */ | 
| 267 | 
< | 
register int    fn, ci; | 
| 298 | 
> | 
advance()                       /* read in next scanline */ | 
| 299 | 
  | 
{ | 
| 300 | 
< | 
        if (fn == 0) | 
| 301 | 
< | 
                return((double)nfiles); | 
| 302 | 
< | 
        if (fn < 1 || fn > nfiles) { | 
| 303 | 
< | 
                errno = EDOM; | 
| 304 | 
< | 
                return(0.0); | 
| 300 | 
> | 
        register COLOR  *st; | 
| 301 | 
> | 
        register int    i, j; | 
| 302 | 
> | 
 | 
| 303 | 
> | 
        for (i = 0; i < nfiles; i++) { | 
| 304 | 
> | 
                st = input[i].scan[WINSIZ-1]; | 
| 305 | 
> | 
                for (j = WINSIZ-1; j > 0; j--)  /* rotate window */ | 
| 306 | 
> | 
                        input[i].scan[j] = input[i].scan[j-1]; | 
| 307 | 
> | 
                input[i].scan[0] = st; | 
| 308 | 
> | 
                if (ypos < MIDSCN)              /* hit bottom */ | 
| 309 | 
> | 
                        continue; | 
| 310 | 
> | 
                if (freadscan(st, xres, input[i].fp) < 0) { | 
| 311 | 
> | 
                        eputs(input[i].name); | 
| 312 | 
> | 
                        eputs(": read error\n"); | 
| 313 | 
> | 
                        quit(1); | 
| 314 | 
> | 
                } | 
| 315 | 
> | 
                for (j = 0; j < xres; j++)      /* adjust color */ | 
| 316 | 
> | 
                        multcolor(st[j], input[i].coef); | 
| 317 | 
  | 
        } | 
| 275 | 
– | 
        return(colval(input[fn-1].scan[xpos],ci)); | 
| 318 | 
  | 
} | 
| 319 | 
  | 
 | 
| 320 | 
  | 
 | 
| 321 | 
  | 
double | 
| 322 | 
< | 
l_redin()                       /* get red color */ | 
| 322 | 
> | 
l_coef(nam)                     /* return picture coefficients */ | 
| 323 | 
> | 
register char   *nam; | 
| 324 | 
  | 
{ | 
| 325 | 
< | 
        return(colin((int)(argument(1)+.5), RED)); | 
| 326 | 
< | 
} | 
| 325 | 
> | 
        register int    fn, n; | 
| 326 | 
> | 
        double  d; | 
| 327 | 
  | 
 | 
| 328 | 
< | 
 | 
| 329 | 
< | 
double | 
| 330 | 
< | 
l_grnin()                       /* get green color */ | 
| 331 | 
< | 
{ | 
| 332 | 
< | 
        return(colin((int)(argument(1)+.5), GRN)); | 
| 328 | 
> | 
        d = argument(1); | 
| 329 | 
> | 
        if (d > -.5 && d < .5) | 
| 330 | 
> | 
                return((double)nfiles); | 
| 331 | 
> | 
        fn = d - .5; | 
| 332 | 
> | 
        if (fn < 0 || fn >= nfiles) { | 
| 333 | 
> | 
                errno = EDOM; | 
| 334 | 
> | 
                return(0.0); | 
| 335 | 
> | 
        } | 
| 336 | 
> | 
        if (nam == vbrtcoef) | 
| 337 | 
> | 
                return(bright(input[fn].coef)); | 
| 338 | 
> | 
        n = 3; | 
| 339 | 
> | 
        while (n--) | 
| 340 | 
> | 
                if (nam == vcolcoef[n]) | 
| 341 | 
> | 
                        return(colval(input[fn].coef,n)); | 
| 342 | 
> | 
        eputs("Bad call to l_coef()!\n"); | 
| 343 | 
> | 
        quit(1); | 
| 344 | 
  | 
} | 
| 345 | 
  | 
 | 
| 346 | 
  | 
 | 
| 347 | 
  | 
double | 
| 348 | 
< | 
l_bluin()                       /* get blue color */ | 
| 348 | 
> | 
l_colin(nam)                    /* return color value for picture */ | 
| 349 | 
> | 
register char   *nam; | 
| 350 | 
  | 
{ | 
| 351 | 
< | 
        return(colin((int)(argument(1)+.5), BLU)); | 
| 352 | 
< | 
} | 
| 351 | 
> | 
        int     fn; | 
| 352 | 
> | 
        register int    n, xoff, yoff; | 
| 353 | 
> | 
        double  d; | 
| 354 | 
  | 
 | 
| 355 | 
< | 
 | 
| 356 | 
< | 
double | 
| 301 | 
< | 
l_brtin()                       /* get brightness value */ | 
| 302 | 
< | 
{ | 
| 303 | 
< | 
        register int    fn; | 
| 304 | 
< | 
 | 
| 305 | 
< | 
        fn = argument(1)+.5; | 
| 306 | 
< | 
        if (fn == 0) | 
| 355 | 
> | 
        d = argument(1); | 
| 356 | 
> | 
        if (d > -.5 && d < .5) | 
| 357 | 
  | 
                return((double)nfiles); | 
| 358 | 
< | 
        if (fn < 1 || fn > nfiles) { | 
| 358 | 
> | 
        fn = d - .5; | 
| 359 | 
> | 
        if (fn < 0 || fn >= nfiles) { | 
| 360 | 
  | 
                errno = EDOM; | 
| 361 | 
  | 
                return(0.0); | 
| 362 | 
  | 
        } | 
| 363 | 
< | 
        return(bright(input[fn-1].scan[xpos])); | 
| 363 | 
> | 
        xoff = yoff = 0; | 
| 364 | 
> | 
        n = nargum(); | 
| 365 | 
> | 
        if (n >= 2) { | 
| 366 | 
> | 
                d = argument(2); | 
| 367 | 
> | 
                if (d < 0.0) { | 
| 368 | 
> | 
                        xoff = d-.5; | 
| 369 | 
> | 
                        if (xpos+xoff < 0) | 
| 370 | 
> | 
                                xoff = -xpos; | 
| 371 | 
> | 
                } else { | 
| 372 | 
> | 
                        xoff = d+.5; | 
| 373 | 
> | 
                        if (xpos+xoff >= xres) | 
| 374 | 
> | 
                                xoff = xres-1-xpos; | 
| 375 | 
> | 
                } | 
| 376 | 
> | 
        } | 
| 377 | 
> | 
        if (n >= 3) { | 
| 378 | 
> | 
                d = argument(3); | 
| 379 | 
> | 
                if (d < 0.0) { | 
| 380 | 
> | 
                        yoff = d-.5; | 
| 381 | 
> | 
                        if (yoff+MIDSCN < 0) | 
| 382 | 
> | 
                                yoff = -MIDSCN; | 
| 383 | 
> | 
                        if (ypos+yoff < 0) | 
| 384 | 
> | 
                                yoff = -ypos; | 
| 385 | 
> | 
                } else { | 
| 386 | 
> | 
                        yoff = d+.5; | 
| 387 | 
> | 
                        if (yoff+MIDSCN >= WINSIZ) | 
| 388 | 
> | 
                                yoff = WINSIZ-1-MIDSCN; | 
| 389 | 
> | 
                        if (ypos+yoff >= yres) | 
| 390 | 
> | 
                                yoff = yres-1-ypos; | 
| 391 | 
> | 
                } | 
| 392 | 
> | 
        } | 
| 393 | 
> | 
        if (nam == vbrtin) | 
| 394 | 
> | 
                return(bright(input[fn].scan[MIDSCN+yoff][xpos+xoff])); | 
| 395 | 
> | 
        n = 3; | 
| 396 | 
> | 
        while (n--) | 
| 397 | 
> | 
            if (nam == vcolin[n]) | 
| 398 | 
> | 
                return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],n)); | 
| 399 | 
> | 
        eputs("Bad call to l_colin()!\n"); | 
| 400 | 
> | 
        quit(1); | 
| 401 | 
  | 
} | 
| 402 | 
  | 
 | 
| 403 | 
  | 
 |