1 |
– |
/* Copyright (c) 1986 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 |
|
* mt160r.c - program to dump pixel file to Mannesman-Tally 160. |
6 |
|
* |
8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdio.h> |
11 |
+ |
#include <time.h> |
12 |
|
|
13 |
+ |
#include "platform.h" |
14 |
|
#include "color.h" |
15 |
+ |
#include "resolu.h" |
16 |
|
|
17 |
< |
#define NCOLS 880 /* for wide carriage */ |
17 |
> |
#define NCOLS 880 /* for wide carriage */ |
18 |
|
|
19 |
|
|
20 |
|
main(argc, argv) |
23 |
|
{ |
24 |
|
int i; |
25 |
|
int status = 0; |
26 |
< |
|
26 |
> |
SET_DEFAULT_BINARY(); |
27 |
> |
SET_FILE_BINARY(stdin); |
28 |
> |
SET_FILE_BINARY(stdout); |
29 |
|
if (argc < 2) |
30 |
|
status += printp(NULL) == -1; |
31 |
|
else |
40 |
|
{ |
41 |
|
FILE *input; |
42 |
|
int xres, yres; |
43 |
< |
COLOR scanline[NCOLS]; |
42 |
< |
char sbuf[256]; |
43 |
> |
COLR scanline[NCOLS]; |
44 |
|
int i; |
45 |
< |
|
45 |
> |
|
46 |
|
if (fname == NULL) { |
47 |
|
input = stdin; |
48 |
|
fname = "<stdin>"; |
51 |
|
return(-1); |
52 |
|
} |
53 |
|
/* discard header */ |
54 |
< |
while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n') |
55 |
< |
; |
54 |
> |
if (checkheader(input, COLRFMT, NULL) < 0) { |
55 |
> |
fprintf(stderr, "%s: not a Radiance picture\n", fname); |
56 |
> |
return(-1); |
57 |
> |
} |
58 |
|
/* get picture dimensions */ |
59 |
< |
if (fgets(sbuf, sizeof(sbuf), input) == NULL || |
57 |
< |
sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) { |
59 |
> |
if (fgetresolu(&xres, &yres, input) < 0) { |
60 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
61 |
|
return(-1); |
62 |
|
} |
68 |
|
fputs("\033[6~\033[7z", stdout); |
69 |
|
|
70 |
|
for (i = yres-1; i >= 0; i--) { |
71 |
< |
if (freadscan(scanline, xres, input) < 0) { |
71 |
> |
if (freadcolrs(scanline, xres, input) < 0) { |
72 |
|
fprintf(stderr, "%s: read error (y=%d)\n", fname, i); |
73 |
|
return(-1); |
74 |
|
} |
75 |
+ |
normcolrs(scanline, xres, 0); |
76 |
|
plotscan(scanline, xres, i); |
77 |
|
} |
78 |
|
|
85 |
|
|
86 |
|
|
87 |
|
plotscan(scan, len, y) /* plot a scanline */ |
88 |
< |
COLOR scan[]; |
88 |
> |
COLR scan[]; |
89 |
|
int len; |
90 |
|
int y; |
91 |
|
{ |
111 |
|
} |
112 |
|
putchar('\r'); |
113 |
|
putchar('\n'); |
114 |
+ |
fflush(stdout); |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
< |
bit(col, x) /* return bit for color at x */ |
120 |
< |
COLOR col; |
119 |
> |
bit(clr, x) /* return bit for color at x */ |
120 |
> |
COLR clr; |
121 |
|
register int x; |
122 |
|
{ |
123 |
< |
static float cerr[NCOLS]; |
124 |
< |
static double err; |
125 |
< |
double b; |
123 |
> |
static int cerr[NCOLS]; |
124 |
> |
static int err; |
125 |
> |
int b, errp; |
126 |
|
register int isblack; |
127 |
|
|
128 |
< |
b = bright(col); |
129 |
< |
if (b > 1.0) b = 1.0; |
128 |
> |
b = normbright(clr); |
129 |
> |
errp = err; |
130 |
|
err += b + cerr[x]; |
131 |
< |
isblack = err < 0.5; |
132 |
< |
if (!isblack) err -= 1.0; |
133 |
< |
cerr[x] = err *= 0.5; |
131 |
> |
isblack = err < 128; |
132 |
> |
if (!isblack) err -= 256; |
133 |
> |
err /= 3; |
134 |
> |
cerr[x] = err + errp; |
135 |
|
return(isblack); |
136 |
|
} |