| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#include "ppm.h" |
| 14 |
|
| 15 |
#define ROWS 200 |
| 16 |
#define COLS 320 |
| 17 |
#define MAXVAL 7 |
| 18 |
|
| 19 |
static short screen[ROWS*COLS/4]; |
| 20 |
|
| 21 |
int |
| 22 |
main(int argc, char* argv[]) { |
| 23 |
|
| 24 |
FILE* ifp; |
| 25 |
pixel pal[16]; |
| 26 |
short i; |
| 27 |
short j; |
| 28 |
pixel* pixelrow; |
| 29 |
pixel* pP; |
| 30 |
int row, col; |
| 31 |
|
| 32 |
|
| 33 |
ppm_init( &argc, argv ); |
| 34 |
|
| 35 |
|
| 36 |
if ( argc > 2 ) |
| 37 |
pm_usage( "[pi1file]" ); |
| 38 |
|
| 39 |
if ( argc == 2 ) |
| 40 |
ifp = pm_openr( argv[1] ); |
| 41 |
else |
| 42 |
ifp = stdin; |
| 43 |
|
| 44 |
|
| 45 |
(void) pm_readbigshort (ifp, &j); |
| 46 |
if ( j != 0 ) |
| 47 |
pm_error( "not a PI1 file" ); |
| 48 |
|
| 49 |
|
| 50 |
for ( i = 0; i < 16; ++i ) |
| 51 |
{ |
| 52 |
(void) pm_readbigshort (ifp, &j); |
| 53 |
PPM_ASSIGN( pal[i], |
| 54 |
( j & 0x700 ) >> 8, |
| 55 |
( j & 0x070 ) >> 4, |
| 56 |
( j & 0x007 ) ); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
for ( i = 0; i < ROWS*COLS/4; ++i ) |
| 61 |
(void) pm_readbigshort( ifp, &screen[i] ); |
| 62 |
|
| 63 |
pm_close( ifp ); |
| 64 |
|
| 65 |
|
| 66 |
ppm_writeppminit( stdout, COLS, ROWS, (pixval) MAXVAL, 0 ); |
| 67 |
pixelrow = ppm_allocrow( COLS ); |
| 68 |
|
| 69 |
|
| 70 |
for ( row = 0; row < ROWS; ++row ) |
| 71 |
{ |
| 72 |
for ( col = 0, pP = pixelrow; col < COLS; ++col, ++pP ) |
| 73 |
{ |
| 74 |
int c, ind, b, plane; |
| 75 |
|
| 76 |
ind = 80 * row + ( ( col >> 4 ) << 2 ); |
| 77 |
b = 0x8000 >> ( col & 0xf ); |
| 78 |
c = 0; |
| 79 |
for ( plane = 0; plane < 4; ++plane ) |
| 80 |
if ( b & screen[ind+plane] ) |
| 81 |
c |= (1 << plane); |
| 82 |
*pP = pal[c]; |
| 83 |
} |
| 84 |
ppm_writeppmrow( stdout, pixelrow, COLS, (pixval) MAXVAL, 0 ); |
| 85 |
} |
| 86 |
|
| 87 |
pm_close( stdout ); |
| 88 |
|
| 89 |
exit( 0 ); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|