/* * CS5600 University of Utah * Charles McGarvey * mcgarvey@eng.utah.edu */ #ifndef _RASTER_HH_ #define _RASTER_HH_ #include "color.hh" #include "common.hh" #include "vec.hh" /* * A pixel map for storing and manipulating a 2D grid of color values. */ typedef struct raster raster_t; /* * Create a new raster on the heap. */ raster_t* raster_alloc(int width, int height, color_t fill); /* * Free up the memory associated with the raster. */ void raster_destroy(raster_t* p); /* * Get the color value at a particular point. */ color_t* raster_color(const raster_t* p, int x, int y); /* * Get the color value at the given texture coordinates. */ color_t raster_uv(const raster_t* p, vec_t uv); /* * Get the width of the raster. */ int raster_width(const raster_t* p); /* * Get the height of the raster. */ int raster_height(const raster_t* p); /* * Get a copy of the raw RGBA pixel data of the raster. The returned * buffer is indeed a copy and must be freed when no longer needed. */ void* raster_data(const raster_t* p); /* * Set the viewport rectangle. This effectively sets up a clipping rectangle * where nothing is drawn outside of the rectangle. The default viewport is * [0, 0, width, height], or the entire raster area. */ void raster_viewport(raster_t* p, int x, int y, int width, int height); /* * Save the raster to a PPM file. */ int raster_export_ppm(const raster_t* p, const char* filename); /* * Save the raster to a BMP file. */ int raster_export_bmp(const raster_t* p, const char* filename); /* * Load the raster from an image file. The file extension is used to * determine which importer is actually called. */ raster_t* raster_import(const char* filename); /* * Load the raster from a PPM file. */ raster_t* raster_import_ppm(const char* filename); /* * Load the raster from a BMP file. */ raster_t* raster_import_bmp(const char* filename); /* * Fill the entire raster with a solid color and reset the raster statistics. */ void raster_clear(raster_t* p, color_t fill); #endif // _RASTER_HH_