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