| 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 |
+ |
#include <time.h> |
| 12 |
|
|
| 13 |
+ |
#include "platform.h" |
| 14 |
|
#include "color.h" |
| 15 |
+ |
#include "resolu.h" |
| 16 |
|
|
| 17 |
< |
#define NCOLS 1440 /* 8" at 180 dpi */ |
| 17 |
> |
#define NCOLS 1440 /* 8" at 180 dpi */ |
| 18 |
|
|
| 19 |
|
|
| 20 |
|
main(argc, argv) |
| 22 |
|
char *argv[]; |
| 23 |
|
{ |
| 24 |
|
int i, status = 0; |
| 25 |
< |
|
| 25 |
> |
SET_DEFAULT_BINARY(); |
| 26 |
> |
SET_FILE_BINARY(stdin); |
| 27 |
> |
SET_FILE_BINARY(stdout); |
| 28 |
|
if (argc < 2) |
| 29 |
|
status = printp(NULL) == -1; |
| 30 |
|
else |
| 39 |
|
{ |
| 40 |
|
FILE *input; |
| 41 |
|
int xres, yres; |
| 42 |
< |
COLOR scanline[NCOLS]; |
| 42 |
> |
COLR scanline[NCOLS]; |
| 43 |
|
int i; |
| 44 |
|
|
| 45 |
|
if (fname == NULL) { |
| 50 |
|
return(-1); |
| 51 |
|
} |
| 52 |
|
/* discard header */ |
| 53 |
< |
getheader(input, NULL); |
| 53 |
> |
if (checkheader(input, COLRFMT, NULL) < 0) { |
| 54 |
> |
fprintf(stderr, "%s: not a Radiance picture\n", fname); |
| 55 |
> |
return(-1); |
| 56 |
> |
} |
| 57 |
|
/* get picture dimensions */ |
| 58 |
< |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
| 58 |
> |
if (fgetresolu(&xres, &yres, input) < 0) { |
| 59 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
| 60 |
|
return(-1); |
| 61 |
|
} |
| 70 |
|
((NCOLS-xres)>>4)<<5, xres); |
| 71 |
|
|
| 72 |
|
for (i = yres-1; i >= 0; i--) { |
| 73 |
< |
if (freadscan(scanline, xres, input) < 0) |
| 73 |
> |
if (freadcolrs(scanline, xres, input) < 0) |
| 74 |
|
return(-1); |
| 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 |
|
{ |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
colbit(col, x, a) /* determine bit value for primary at x */ |
| 112 |
< |
COLOR col; |
| 112 |
> |
COLR col; |
| 113 |
|
register int x; |
| 114 |
|
register int a; |
| 115 |
|
{ |
| 116 |
< |
static float cerr[NCOLS][3]; |
| 117 |
< |
static double err[3]; |
| 118 |
< |
double b; |
| 116 |
> |
static int cerr[NCOLS][3]; |
| 117 |
> |
static int err[3]; |
| 118 |
> |
int b, errp; |
| 119 |
|
register int ison; |
| 120 |
|
|
| 121 |
< |
b = colval(col,a); |
| 122 |
< |
if (b > 1.0) b = 1.0; |
| 121 |
> |
b = col[a]; |
| 122 |
> |
errp = err[a]; |
| 123 |
|
err[a] += b + cerr[x][a]; |
| 124 |
< |
ison = err[a] > 0.5; |
| 125 |
< |
if (ison) err[a] -= 1.0; |
| 126 |
< |
cerr[x][a] = err[a] *= 0.5; |
| 124 |
> |
ison = err[a] > 128; |
| 125 |
> |
if (ison) err[a] -= 256; |
| 126 |
> |
err[a] /= 3; |
| 127 |
> |
cerr[x][a] = err[a] + errp; |
| 128 |
|
return(ison); |
| 129 |
|
} |