diff --git a/sys/amiga/xpm2iff.c b/sys/amiga/xpm2iff.c new file mode 100644 index 000000000..82bbb0193 --- /dev/null +++ b/sys/amiga/xpm2iff.c @@ -0,0 +1,353 @@ +/* SCCS Id: @(#)xpm2iff.c 3.2 95/08/04 */ +/* Copyright (c) 1995 by Gregg Wonderly, Naperville, Illinois */ +/* NetHack may be freely redistributed. See license for details. */ + +#include + +#include "config.h" +#include "tile.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef _DCC +# include +# include +# include +#endif + +struct xpmscreen { + int Width; + int Height; + int Colors; + int ColorResolution; + int Background; + int AspectRatio; + int Interlace; + int BytesPerRow; +} XpmScreen; + +/* translation table from xpm characters to RGB and colormap slots */ +struct Ttable { + char flag; + char r,g,b; + int slot; /* output colortable index */ +}ttable[256]; + +pixval ColorMap[3][MAXCOLORMAPSIZE]; +int colorsinmap; + +/* + * We are using a hybrid form of our own design which we call a BMAP (for + * bitmap) form. It is an ILBM with the bitmaps already deinterleaved, + * completely uncompressed. + * This speeds the loading of the images from the games point of view because it + * does not have to deinterleave and uncompress them. + */ +#define ID_BMAP MAKE_ID( 'B', 'M', 'A', 'P' ) /* instead of ILBM */ +#define ID_BMHD MAKE_ID( 'B', 'M', 'H', 'D' ) /* Same as ILBM */ +#define ID_CAMG MAKE_ID( 'C', 'A', 'M', 'G' ) /* Same as ILBM */ +#define ID_CMAP MAKE_ID( 'C', 'M', 'A', 'P' ) /* Same as ILBM */ +#define ID_PDAT MAKE_ID( 'P', 'D', 'A', 'T' ) /* Extra data describing plane + * size due to graphics.library + * rounding requirements. + */ +#define ID_PLNE MAKE_ID( 'P', 'L', 'N', 'E' ) /* The planes of the image */ + +int nplanes; + +/* BMHD from IFF documentation */ +typedef struct { + UWORD w, h; + WORD x, y; + UBYTE nPlanes; + UBYTE masking; + UBYTE compression; + UBYTE reserved1; + UWORD transparentColor; + UBYTE xAspect, yAspect; + WORD pageWidth, pageHeight; +} BitMapHeader; + +typedef struct { + UBYTE r, g, b; +} AmiColorMap; + +pixel pixels[TILE_Y][TILE_X]; +AmiColorMap *cmap; + +void +error( char *str ) +{ + fprintf( stderr, "ERROR: %s\n", str ); +} + +char **planes; + +main( int argc, char **argv ) +{ + int colors; + struct { + long nplanes; + long pbytes; + long across; + long down; + long npics; + long xsize; + long ysize; + } pdat; + long pbytes; /* Bytes of data in a plane */ + int i, cnt; + BitMapHeader bmhd; + struct IFFHandle *iff; + long camg = HIRES|LACE; + int tiles=0; + int index; + +#if defined(_DCC) || defined (__GNUC__) + IFFParseBase = OpenLibrary( "iffparse.library", 0 ); + if( !IFFParseBase ) { + error( "unable to open iffparse.library" ); + exit( 1 ); + } +#endif + + if( fopen_xpm_file( argv[1], "r" ) != TRUE ) + { + perror( argv[1] ); + return( 1 ); + } + + nplanes = 0; + i = XpmScreen.Colors - 1; + while( i != 0 ) + { + nplanes++; + i >>= 1; + } + + planes = malloc( nplanes * sizeof( char * ) ); + if( planes == 0 ) + { + error( "can not allocate planes pointer" ); + exit( 1 ); + } + + XpmScreen.BytesPerRow = ((XpmScreen.Width + 15)/16)*2; + pbytes = XpmScreen.BytesPerRow * XpmScreen.Height; + for( i = 0; i < nplanes; ++i ) + { + planes[ i ] = malloc( pbytes ); + if( planes[ i ] == 0 ) + { + error( "can not allocate planes pointer" ); + exit( 1 ); + } + memset( planes[i], 0, pbytes ); + } + + iff = AllocIFF(); + if( !iff ) + { + error( "Can not allocate IFFHandle" ); + return( 1 ); + } + + iff->iff_Stream = Open( argv[2], MODE_NEWFILE ); + if( !iff->iff_Stream ) + { + error( "Can not open output file" ); + return( 1 ); + } + + InitIFFasDOS( iff ); + OpenIFF( iff, IFFF_WRITE ); + + PushChunk( iff, ID_BMAP, ID_FORM, IFFSIZE_UNKNOWN ); + + bmhd.w = XpmScreen.Width; + bmhd.h = XpmScreen.Height; + bmhd.x = 0; + bmhd.y = 0; + bmhd.nPlanes = nplanes; + bmhd.masking = 0; + bmhd.compression = 0; + bmhd.reserved1 = 0; + bmhd.transparentColor = 0; + bmhd.xAspect = 100; + bmhd.yAspect = 100; + bmhd.pageWidth = 0; /* not needed for this program */ + bmhd.pageHeight = 0; /* not needed for this program */ + + PushChunk( iff, ID_BMAP, ID_BMHD, sizeof( bmhd ) ); + WriteChunkBytes( iff, &bmhd, sizeof( bmhd ) ); + PopChunk( iff ); + + PushChunk( iff, ID_BMAP, ID_CAMG, sizeof( camg ) ); + WriteChunkBytes( iff, &camg, sizeof( camg ) ); + PopChunk( iff ); + +#define SCALE(x) (x) + cmap = malloc( (colors = (1L<iff_Stream ); + FreeIFF( iff ); + +#if defined(_DCC) || defined (__GNUC__) + CloseLibrary( IFFParseBase ); +#endif + exit( 0 ); +} + +#define SETBIT(Plane, Plane_offset, Col, Value) \ + if(Value){ \ + planes[Plane][Plane_offset + (Col/8)] |= 1<<(7-(Col & 7)); \ + } + +conv_image(){ + int row, col, planeno; + + for(row = 0;row if any */ + for(bp = buf;*bp;bp++); + bp--; + while(isspace(*bp))bp--; + if(*bp==',')bp--; + if(*bp=='"')bp--; + bp++; + *bp = '\0'; + + return &buf[1]; +}