/* The IMAGE data structure */ struct image { struct header *info; /* Pointer to header */ unsigned char **data; /* Pixel values */ }; typedef struct image * IMAGE; // // Allocates memory for a new image of the specified dimensions. // struct image *image_init (int nc, int nr) { IMAGE x; /* New image */ //unsigned char *ptr; /* new pixel array */ register unsigned int i; if (nr < 0 || nc < 0) { printf ("Error: Bad image size (%d,%d)\n", nc, nr); exit(-1); } // Allocate the image structure x = (struct image *) malloc( sizeof (struct image) ); if (!x) { printf ("Out of storage in NEWIMAGE.\n"); exit(-1); } // Allocate and initialize the header x->info = (struct header *)malloc( sizeof(struct header) ); if (!(x->info)) { printf ("Out of storage in NEWIMAGE.\n"); exit(-1); } x->info->nr = nr; x->info->nc = nc; x->info->oi = x->info->oj = 0; // Allocate the array of rows x->data = (unsigned char **)malloc(sizeof(unsigned char *)*nr); // Pointers to rows if (!(x->data)) { printf ("Out of storage in NEWIMAGE.\n"); exit(-1); } // Allocated the actual rows for (i=0; idata[i] = (unsigned char *)malloc(nc*sizeof(unsigned char)+1); // Hack for CMVision's encodeRuns() to store run terminator if (x->data[i]==0) { printf ("Out of storage. Newimage - row %d\n", i); exit(1); } } return x; }