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