#include #include #define DEBUG 0 #define bound(a) ((a) < 0.0 ? 0 : ((a)>255.0? 255 : a)) #define IMAGE_TYPE unsigned char /* may be different in some applications */ IMAGE_TYPE **image; /* various function declarations to keep compiler warnings away. ANSI */ /* prototypes can go here, for the hearty. */ char *malloc(); char *strcpy(); /* The following #define allocates an hsize x vsize matrix of type TYPE */ #define matrix_allocate(matrix, TYPE) {\ TYPE *imptr; \ int _i; \ matrix = (TYPE **)malloc((256)*sizeof(TYPE *));\ imptr = (TYPE*)malloc((long)(256)*(long)(256)*sizeof(TYPE));\ /* if (imptr == NULL) \ fatal("\nNo memory in matrix allocate."); */ \ for (_i = 0; _i<256; ++_i, imptr += 256) \ matrix[_i] = imptr; \ } main() { char inputfilename[200]; FILE *input; int i; strcpy(inputfilename, "lenna.dat"); input = fopen(inputfilename, "r"); matrix_allocate(image,IMAGE_TYPE); /* skip the first stripchar matrix_allocate chars */ fseek(input, 0, 0); i = fread(image[0], sizeof(IMAGE_TYPE), 65536, input); fclose(input); printf("%\n %d \n",i); }