1 |
– |
/* Copyright (c) 1989 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 |
|
* paintjet.c - program to dump pixel file to HP PaintJet color printer. |
6 |
|
* |
8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdio.h> |
11 |
+ |
#ifdef MSDOS |
12 |
+ |
#include <fcntl.h> |
13 |
+ |
#endif |
14 |
+ |
#include <time.h> |
15 |
|
|
16 |
|
#include "color.h" |
17 |
+ |
#include "resolu.h" |
18 |
|
|
19 |
< |
#define NCOLS 1440 /* 8" at 180 dpi */ |
19 |
> |
#define NCOLS 1440 /* 8" at 180 dpi */ |
20 |
|
|
21 |
|
|
22 |
|
main(argc, argv) |
24 |
|
char *argv[]; |
25 |
|
{ |
26 |
|
int i, status = 0; |
27 |
< |
|
27 |
> |
#ifdef MSDOS |
28 |
> |
extern int _fmode; |
29 |
> |
_fmode = O_BINARY; |
30 |
> |
setmode(fileno(stdin), O_BINARY); |
31 |
> |
setmode(fileno(stdout), O_BINARY); |
32 |
> |
#endif |
33 |
|
if (argc < 2) |
34 |
|
status = printp(NULL) == -1; |
35 |
|
else |
44 |
|
{ |
45 |
|
FILE *input; |
46 |
|
int xres, yres; |
47 |
< |
COLOR scanline[NCOLS]; |
47 |
> |
COLR scanline[NCOLS]; |
48 |
|
int i; |
49 |
|
|
50 |
|
if (fname == NULL) { |
55 |
|
return(-1); |
56 |
|
} |
57 |
|
/* discard header */ |
58 |
< |
getheader(input, NULL); |
58 |
> |
if (checkheader(input, COLRFMT, NULL) < 0) { |
59 |
> |
fprintf(stderr, "%s: not a Radiance picture\n", fname); |
60 |
> |
return(-1); |
61 |
> |
} |
62 |
|
/* get picture dimensions */ |
63 |
< |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
63 |
> |
if (fgetresolu(&xres, &yres, input) < 0) { |
64 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
65 |
|
return(-1); |
66 |
|
} |
75 |
|
((NCOLS-xres)>>4)<<5, xres); |
76 |
|
|
77 |
|
for (i = yres-1; i >= 0; i--) { |
78 |
< |
if (freadscan(scanline, xres, input) < 0) |
78 |
> |
if (freadcolrs(scanline, xres, input) < 0) |
79 |
|
return(-1); |
80 |
+ |
normcolrs(scanline, xres, 0); |
81 |
|
plotscan(scanline, xres, i); |
82 |
|
} |
83 |
|
|
90 |
|
|
91 |
|
|
92 |
|
plotscan(scan, len, y) /* plot a scanline */ |
93 |
< |
COLOR scan[]; |
93 |
> |
COLR scan[]; |
94 |
|
int len; |
95 |
|
int y; |
96 |
|
{ |
114 |
|
|
115 |
|
|
116 |
|
colbit(col, x, a) /* determine bit value for primary at x */ |
117 |
< |
COLOR col; |
117 |
> |
COLR col; |
118 |
|
register int x; |
119 |
|
register int a; |
120 |
|
{ |
121 |
< |
static float cerr[NCOLS][3]; |
122 |
< |
static double err[3]; |
123 |
< |
double b; |
121 |
> |
static int cerr[NCOLS][3]; |
122 |
> |
static int err[3]; |
123 |
> |
int b, errp; |
124 |
|
register int ison; |
125 |
|
|
126 |
< |
b = colval(col,a); |
127 |
< |
if (b > 1.0) b = 1.0; |
126 |
> |
b = col[a]; |
127 |
> |
errp = err[a]; |
128 |
|
err[a] += b + cerr[x][a]; |
129 |
< |
ison = err[a] > 0.5; |
130 |
< |
if (ison) err[a] -= 1.0; |
131 |
< |
cerr[x][a] = err[a] *= 0.5; |
129 |
> |
ison = err[a] > 128; |
130 |
> |
if (ison) err[a] -= 256; |
131 |
> |
err[a] /= 3; |
132 |
> |
cerr[x][a] = err[a] + errp; |
133 |
|
return(ison); |
134 |
|
} |