#include "stdio.h" #include "stdlib.h" #include "math.h" /* Experiment with texture tiling. Assume 256x256 square textures in "raw" format. Apply radial and linear masks. Write out intermediate files for checking/illustrative purposes. */ typedef struct { unsigned char r,g,b; } COLOUR; #define MAX(x,y) (x < y ? y : x) #define MIN(x,y) (x > y ? y : x) #define N 256 /* The mask type */ #define LINEAR 'l' #define RADIAL 'r' int masktype = LINEAR; int main(int argc,char **argv) { int i,j,r,g,b; double a1,a2,d; COLOUR image[N][N],diagonal[N][N],tile[N][N]; unsigned char mask[N][N]; char fname[128]; FILE *fptr; /* Check command line arguments */ if (argc < 3) { fprintf(stderr,"Usage: %s rawtexturefilename masktype[r,l]\n",argv[0]); exit(-1); } if (argv[2][0] == RADIAL) masktype = RADIAL; else if (argv[2][0] == LINEAR) masktype = LINEAR; /* Read the image and form the diagonal swapped image */ if ((fptr = fopen(argv[1],"r")) == NULL) { fprintf(stderr,"Unable to read texture file\n"); exit(-1); } for (j=0;j 255) d = 255; /* Form the mask in each quadrant */ mask[ i][ j] = d; mask[ i][N-1-j] = d; mask[N-1-i][ j] = d; mask[N-1-i][N-1-j] = d; } } /* Save the mask as a grey scale raw image */ sprintf(fname,"mask_%c.raw",masktype); if ((fptr = fopen(fname,"w")) != NULL) { for (j=0;j