/* 
 * This is the constructor for the struct PPMImage. this_prt is passed 
 * to the constructer as NULL when a new instance of IMMImage needs to 
 * be declared on the heap. this_ptr contains a valid pointer if the 
 * memory for the object has already been allocated. May be called 
 * with only this_ptr or can be called using a filename as the second 
 * parameter in which case the imge will be loaded.
*/
PPMImage* ppm_image_constructor(const char * filename)
{
   //Allocate memeory for a new object on the heap
   PPMImage* this_ptr = (PPMImage *) malloc(sizeof(PPMImage));
   if(!this_ptr)
   {
		fprintf(ERROR_OUT, "ERROR %d: Unable to allocate memeory of PPMImage Object\nPress Enter To Exit...", errno);
		//char c = getc(stdin);
        exit(10);
   }
   
   //If memeory has been allocated initilaize the memeber variables
   if(this_ptr)
   {
      this_ptr->p = '\0';
      this_ptr->width = 0;
      this_ptr->height = 0;
      this_ptr->maxValue = 0;
      this_ptr->size = 0;
      this_ptr->filename[0] = '\0';            
   } 
   
   //If file name was specified then load the image
   if(filename)
   {
      this_ptr = load_ppm_image(this_ptr, filename, NEW_ALLOC);               
   }
   
        
return this_ptr;
}
Ejemplo n.º 2
0
/**
 * @brief Loads an image from the disk.
 * Currently only PPM format is supported.
 *
 * @param path image file path
 *
 * @return pointer to the new image
 */
struct Image* image_load(const char * path)
{
	struct Image* imagep = malloc(sizeof(struct Image));
	load_ppm_image(path, &imagep->width, &imagep->height, &imagep->data);
	return imagep;
}