Source code for /engineering/rendsite/test/source/2XTILE/VGA2PIX.COriginal file VGA2PIX.C
   1 /*
   2 
   3  VGA2PIX utility for the XTile graphics manager
   4 
   5  COPYRIGHT (C) 1992  Erich P Gatejen   All Rights Reserved
   6 
   7 
   8  File: VGA2PIX.C    	Written for the Turbo C compiler
   9 
  10 
  11  This will convert .VGA bitmaps to .PIX ( Mode X image )
  12 
  13 
  14  MUST BE COMPILED IN LARGE MODEL !!!
  15 
  16 */
  17 
  18 #include<stdio.h>
  19 #include<conio.h>
  20 #include<string.h>
  21 #include<alloc.h>
  22 
  23 
  24 
  25 FILE 	*in,		*out;
  26 char		*inb,     *outb,	/* Base pointers to input and output pic buffers */
  27 		*BufI,	*BufO;	/* Pointers into buffers	*/
  28 
  29 char		File_NameI[80];
  30 char		File_NameO[80];     /* File name buffers	*/
  31 
  32 unsigned int	Xsize, Ysize, Totalsize;		/* X,Y size and Picture size	*/
  33 
  34 int		step, step2, XBlocks;	/* Loop vars and number of XBlocks		*/
  35 
  36 main ( int argn, char* argc[] ) {
  37 
  38 	int	step = 0;
  39 
  40 	if ( argn < 2 ) {
  41 		puts("  !!ERROR!!  File name not specified.\n");
  42 		exit(1);
  43 
  44 	}
  45 
  46 	strcpy ( File_NameI, argc[1] );
  47 	strcpy ( File_NameO, argc[1] );
  48 
  49 	strcat ( File_NameI, ".VGA" );
  50 	strcat ( File_NameO, ".PIX" );
  51 
  52 	in  = fopen( File_NameI, "rb" );
  53 	out = fopen( File_NameO, "wb" );	/* open files */
  54 
  55 	if ( (in == NULL)||(out == NULL) ) {
  56 		puts("  !!ERROR!!  File(s) cannot be opened.\n");
  57 		exit(1);
  58 
  59 	}
  60 
  61 	fread( &Xsize, sizeof( int ), 1, in );
  62 	fread( &Ysize, sizeof( int ), 1, in );  /* Read X,Y size from .VGA file */
  63 
  64 	Xsize++;
  65 	Ysize++;	/* Count pixels from 1 instead of 0	*/
  66 
  67 	Totalsize = Xsize * Ysize;	/* Calc total pic size in bytes	*/
  68 	XBlocks   = Totalsize / 4;    /* Calc number of XBlocks		*/
  69 
  70 	inb  = farmalloc( Totalsize );
  71 	outb = farmalloc( Totalsize ); 	/* Create buffers			*/
  72 
  73 	if (( in == NULL ) || ( out == NULL ) || ( outb == NULL)) exit(1);
  74 
  75 	fread( inb, sizeof(char), Totalsize, in );   /* Get pic */
  76 
  77 	BufO = outb;
  78 
  79 
  80 	/* Translate and place pic in output buffer			*/
  81 	for ( step = 0; step < 4; step++ ) {
  82 
  83 		BufI = inb + step;
  84 
  85 		for ( step2 = 0; step2 < XBlocks; step2++ ) {
  86 
  87 			*BufO = *BufI;
  88 			BufI  = BufI + 4;	/* Plane at a time, so move every 4th pixel*/
  89 			BufO++;
  90 
  91 		};
  92 
  93 
  94      }; /* end transfer */
  95 
  96 
  97 	fwrite( outb, sizeof( char ), Totalsize, out ); /* Write output buffer */
  98 
  99 	fclose( in  );
 100 	fclose( out );	/* Close files	*/
 101 
 102 	return(0);
 103 };