Debian Codegraph @

converter/ppm/neotoppm.c

raw symbols SCIP
1 /* neotoppm.c - read a Neochrome NEO file and produce a portable pixmap
2 **
3 ** Copyright (C) 2001 by Teemu Hukkanen <[email protected]>
4 ** Based on pi1toppm by Steve Belczyk ([email protected]) and Jef Poskanzer.
5 **
6 ** Permission to use, copy, modify, and distribute this software and its
7 ** documentation for any purpose and without fee is hereby granted, provided
8 ** that the above copyright notice appear in all copies and that both that
9 ** copyright notice and this permission notice appear in supporting
10 ** documentation. This software is provided "as is" without express or
11 ** implied warranty.
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]; /* simulates the Atari's video RAM */
21
22 int
23 main( int argc, char * argv[] ) {
24 FILE* ifp;
25 pixel pal[16]; /* Degas palette */
26 pixel* pixelrow;
27 int row;
28
29 ppm_init( &argc, argv );
30
31 /* Check args. */
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 /* Check header */
41 {
42 /* Flag */
43 short j;
44 pm_readbigshort (ifp, &j);
45 if ( j != 0 )
46 pm_error( "not a NEO file" );
47 }
48 {
49 /* Check resolution word */
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 /* Read the palette. */
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 /* Skip rest of header */
70 fseek(ifp, 128, SEEK_SET);
71
72 {
73 /* Read the screen data */
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 /* Ok, get set for writing PPM. */
81 ppm_writeppminit( stdout, COLS, ROWS, MAXVAL, 0 );
82 pixelrow = ppm_allocrow( COLS );
83
84 /* Now do the conversion. */
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