about summary refs log tree commit diff
path: root/converter/ppm/pi1toppm.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-08-19 03:12:28 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-08-19 03:12:28 +0000
commit1fd361a1ea06e44286c213ca1f814f49306fdc43 (patch)
tree64c8c96cf54d8718847339a403e5e67b922e8c3f /converter/ppm/pi1toppm.c
downloadnetpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.gz
netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.xz
netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.zip
Create Subversion repository
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/ppm/pi1toppm.c')
-rw-r--r--converter/ppm/pi1toppm.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/converter/ppm/pi1toppm.c b/converter/ppm/pi1toppm.c
new file mode 100644
index 00000000..69b99863
--- /dev/null
+++ b/converter/ppm/pi1toppm.c
@@ -0,0 +1,92 @@
+/* pi1toppm.c - read a Degas PI1 file and produce a portable pixmap
+**
+** Copyright (C) 1991 by Steve Belczyk (seb3@gte.com) and Jef Poskanzer.
+**
+** Permission to use, copy, modify, and distribute this software and its
+** documentation for any purpose and without fee is hereby granted, provided
+** that the above copyright notice appear in all copies and that both that
+** copyright notice and this permission notice appear in supporting
+** documentation.  This software is provided "as is" without express or
+** implied warranty.
+*/
+
+#include "ppm.h"
+
+#define ROWS 200
+#define COLS 320
+#define MAXVAL 7
+
+static short screen[ROWS*COLS/4];          /* simulates the Atari's video RAM */
+
+int
+main( argc, argv )
+    int argc;
+    char* argv[];
+    {
+    FILE* ifp;
+    pixel pal[16];                      /* Degas palette */
+    short i;
+    short j;
+    pixel* pixelrow;
+    register pixel* pP;
+    int row, col;
+
+
+    ppm_init( &argc, argv );
+
+    /* Check args. */
+    if ( argc > 2 )
+        pm_usage( "[pi1file]" );
+
+    if ( argc == 2 )
+        ifp = pm_openr( argv[1] );
+    else
+        ifp = stdin;
+
+    /* Check resolution word */
+    (void) pm_readbigshort (ifp, &j);
+    if ( j != 0 )
+        pm_error( "not a PI1 file" );
+
+    /* Read the palette. */
+    for ( i = 0; i < 16; ++i )
+        {
+        (void) pm_readbigshort (ifp, &j);
+        PPM_ASSIGN( pal[i],
+            ( j & 0x700 ) >> 8,
+            ( j & 0x070 ) >> 4,
+            ( j & 0x007 ) );
+        }
+
+    /* Read the screen data */
+    for ( i = 0; i < ROWS*COLS/4; ++i )
+        (void) pm_readbigshort( ifp, &screen[i] );
+
+    pm_close( ifp );
+
+    /* Ok, get set for writing PPM. */
+    ppm_writeppminit( stdout, COLS, ROWS, (pixval) MAXVAL, 0 );
+    pixelrow = ppm_allocrow( COLS );
+
+    /* Now do the conversion. */
+    for ( row = 0; row < ROWS; ++row )
+        {
+        for ( col = 0, pP = pixelrow; col < COLS; ++col, ++pP )
+            {
+            register int c, ind, b, plane;
+
+            ind = 80 * row + ( ( col >> 4 ) << 2 );
+            b = 0x8000 >> ( col & 0xf );
+            c = 0;
+            for ( plane = 0; plane < 4; ++plane )
+                if ( b & screen[ind+plane] )
+                    c |= (1 << plane);
+            *pP = pal[c];
+            }
+        ppm_writeppmrow( stdout, pixelrow, COLS, (pixval) MAXVAL, 0 );
+        }
+
+    pm_close( stdout );
+
+    exit( 0 );
+    }