Source code for /engineering/rendsite/test/source/2XTILE/MASKTILE.COriginal file MASKTILE.C
   1 /*
   2 
   3  MASKTILE utility for the XTile graphics manager
   4 
   5  COPYRIGHT (C) 1992  Erich P Gatejen   All Rights Reserved
   6 
   7 
   8  File: MASKTILE.C    	Written for the Turbo C compiler
   9 
  10 
  11  Will create a mask for a .PIX bitmap ( Mode X image )
  12 
  13  Masks will be created two per byte, with first mask in lower nibble */
  14 
  15 
  16 */
  17 
  18 #include<stdio.h>
  19 #include<conio.h>
  20 #include<alloc.h>
  21 
  22 
  23 FILE 	*in,		*out;
  24 
  25 char		File_NameI[13];          /* Input file name	*/
  26 char		File_NameO[13];          /* Output file name */
  27 
  28 unsigned char		*inbuf,        /* Buffer to hold .VGA picture	*/
  29 				*base,         /* Pointer into inbuf			*/
  30 				*current;		/* Current position in inbuf		*/
  31 
  32 unsigned char		Hold;          /* Mask generator				*/
  33 unsigned char		Mask;		/* Actual mask					*/
  34 
  35 unsigned int		X,
  36 				Y,             /* Inputs for picture size		*/
  37 				Tsize,         /* Size of picture in bytes        */
  38 				Psize;		/* Number of XBlocks in picture    */
  39 
  40 
  41 
  42 int		step, step2;	/* Looping vars	*/
  43 
  44 main () {
  45 
  46 	printf ("File name : ");
  47 	scanf("%8s", File_NameI );	/* Get file name from user	*/
  48 
  49 	printf ("X size : ");
  50 	scanf("%d", &X );			/* Get picture X size		*/
  51 
  52 	printf ("Y size : ");
  53 	scanf("%d", &Y );			/* Get picture Y size		*/
  54 
  55 	do {
  56           File_NameO[ step ] = File_NameI[ step ];
  57 		step++;
  58 
  59 	   } while (File_NameI[ step ] != 0);    /* Pack the file name	*/
  60 
  61 	File_NameI[ step ] = '.';
  62 	File_NameO[ step ] = '.';
  63 	File_NameI[step+1] = 'P';
  64 	File_NameO[step+1] = 'M';
  65 	File_NameI[step+2] = 'I';
  66 	File_NameO[step+2] = 'S';
  67 	File_NameI[step+3] = 'X';
  68 	File_NameO[step+3] = 'K';
  69 	File_NameI[step+4] = 0;
  70 	File_NameO[step+4] = 0;    	/* Add extensions to file names	*/
  71 
  72 	Tsize = X * Y;                /* Calculate the picture size		*/
  73 	Psize = ( X / 4 ) * Y;		/* Calc number of XBlocks		*/
  74 
  75 	in  = fopen( File_NameI, "rb" );
  76 	out = fopen( File_NameO, "wb" );	/* Open files		*/
  77 
  78      inbuf = farmalloc( Tsize );        /* Allocate memory for picture */
  79 
  80 	if (( in == 0 ) || ( out == 0 ) || ( inbuf == NULL)) {
  81 		printf(" ERROR /n");
  82 		exit(1);
  83 		};
  84 
  85 	fread( inbuf, sizeof(char), Tsize, in );   /* Get picture */
  86 
  87 	base = inbuf;
  88 	current = base;
  89 
  90 	/* Loop through the picture and make the mask		*/
  91      /* If byte is 0, then mask it's bit				*/
  92 	for ( step = 1; step <= Tsize; step = step + 4 ) {
  93 
  94 		Hold = 0;    	/* Clear mask holding var		*/
  95 
  96 		if (*current != 0) Hold = Hold + 1; /* Plane 0 */
  97 
  98 		current = current + Psize;
  99 		if (*current != 0) Hold = Hold + 2; /* Plane 1 */
 100 
 101 		current = current + Psize;
 102 		if (*current != 0) Hold = Hold + 4; /* Plane 2 */
 103 
 104 		current = current + Psize;
 105 		if (*current != 0) Hold = Hold + 8; /* Plane 3 */
 106 
 107 		base++; 	/* Goto next XBlock  */
 108 
 109 		current = base;	
 110 
 111 		fputc( Hold, out );  	/* Write mask to the file	*/
 112 
 113 
 114 	};
 115 
 116 
 117 	fclose( in  );
 118 	fclose( out );	/* Close files and done	*/
 119 
 120 	return(0);
 121 };