Debian Codegraph @

converter/ppm/pi1toppm.c

raw symbols SCIP
1 /* pi1toppm.c - read a Degas PI1 file and produce a portable pixmap
2 **
3 ** Copyright (C) 1991 by Steve Belczyk ([email protected]) and Jef Poskanzer.
4 **
5 ** Permission to use, copy, modify, and distribute this software and its
6 ** documentation for any purpose and without fee is hereby granted, provided
7 ** that the above copyright notice appear in all copies and that both that
8 ** copyright notice and this permission notice appear in supporting
9 ** documentation. This software is provided "as is" without express or
10 ** implied warranty.
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]; /* simulates the Atari's video RAM */
20
21 int
22 main(int argc, char* argv[]) {
23
24 FILE* ifp;
25 pixel pal[16]; /* Degas palette */
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 /* Check args. */
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 /* Check resolution word */
45 (void) pm_readbigshort (ifp, &j);
46 if ( j != 0 )
47 pm_error( "not a PI1 file" );
48
49 /* Read the palette. */
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 /* Read the screen data */
60 for ( i = 0; i < ROWS*COLS/4; ++i )
61 (void) pm_readbigshort( ifp, &screen[i] );
62
63 pm_close( ifp );
64
65 /* Ok, get set for writing PPM. */
66 ppm_writeppminit( stdout, COLS, ROWS, (pixval) MAXVAL, 0 );
67 pixelrow = ppm_allocrow( COLS );
68
69 /* Now do the conversion. */
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