home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- /*
- * pi1toppm.c - Reads a Degas PI1 file on stdin and
- * writes a portable pixmap (ppm) file on stdout.
- *
- * Copyright (C) 1990, Steve Belczyk
- */
-
- /* Remove the following definition if you don't want raw ppm files */
- #define RAWBITS
-
- char *progname;
-
- int pal[16][3]; /* Degas palettes */
- short screen[16000]; /* Simulates the Atari's video RAM */
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- int x, y;
-
- progname = argv[0];
-
- /* Check for bogus arguments */
- if (argc > 1)
- {
- fprintf (stderr, "usage: %s <pi1file >ppmfile\n",
- progname);
- exit (-1);
- }
-
- /* Read the PI1 file */
- ReadPI1();
-
- /* Write PPM header */
- #ifdef RAWBITS
- printf ("P6\n320 200\n255\n"); /* Magic, resolution, max pixel */
- #else
- printf ("P3\n320 200\n255\n");
- #endif
-
- /* Convert and write */
- for (y=0; y<200; y++)
- {
- for (x=0; x<320; x++)
- {
- DoPixel (x, y);
- }
- }
- }
-
- ReadPI1 ()
- {
- int i, j;
-
- /* Check resolution word */
- i = GetWord();
- if (i != 0)
- {
- fprintf (stderr, "%s: Not a PI1 file\n", progname);
- exit (-1);
- }
-
- /* Read the palette */
- for (i=0; i<16; i++)
- {
- j = GetWord();
- pal[i][0] = (0x700 & j) >> 3;
- pal[i][1] = (0x070 & j) << 1;
- pal[i][2] = (0x007 & j) << 5;
- }
-
- /* Read the screen data */
- for (i=0; i<16000; i++)
- {
- screen[i] = GetWord();
- }
- }
-
- int GetWord()
- {
- int w;
-
- w = (0xff & getchar()) << 8;
- w |= 0xff & getchar();
-
- return (w);
- }
-
- DoPixel (x, y)
- int x, y;
- {
- int c;
-
- c = GetPixel (x, y);
-
- #ifdef RAWBITS
- putchar (0xff & pal[c][0]);
- putchar (0xff & pal[c][1]);
- putchar (0xff & pal[c][2]);
- #else
- printf ("%d %d %d\n", (0xff & pal[c][0]),
- (0xff & pal[c][1]),
- (0xff & pal[c][2]));
- #endif
- }
-
- int GetPixel (x, y)
- int x, y;
- {
- int c, index, bit, plane;
-
- c = 0;
-
- /* index = (80*y) + 4*(x/16); */
- index = (y << 6) + (y << 4) + ((x >> 4) << 2);
-
- /* bit = 0x8000 >> (x % 16); */
- bit = 0x8000 >> (x & 0x0f);
-
- for (plane=0; plane<4; plane++)
- {
- if (bit & screen[index+plane])
- {
- c |= (1 << plane);
- }
- }
- return (c);
- }
-
-