URL: https://graphicscomputing.fr/cgp/reference/image_structure/
Description: Image stored on the CPU (width, height, RGB/RGBA data).

# image_structure

Image stored on the CPU (width, height, RGB/RGBA data).

Fields:

- `int width` - Number of pixels in the horizontal direction.
- `int height` - Number of pixels in the vertical direction.
- `image_color_type color_type` - Pixel format of data, rgb (3 bytes per pixel) or rgba (4 bytes per pixel).
- `numarray<unsigned char> data` - Pixel bytes in [0,255] stored row by row, the component c of pixel (x,y) being at index (x + width*y)*N + c with N = 3 or 4.

Functions taking it:

- `void image_save_png(std::string const& filename, image_structure const& im)` - Save an RGB or RGBA image_structure as a PNG file; exits the program on encoding error.
- `void image_save_jpg(std::string const& filename, image_structure const& im)` - Save an RGB or RGBA image_structure as a JPEG file (the alpha channel is dropped).
- `void convert(image_structure const& in, grid_2D<vec3>& out)` - Convert an RGB or RGBA image into a grid_2D of vec3 colors in [0,1], dropping the alpha channel.
- `std::vector<image_structure> image_split_grid(image_structure const& image_in, int N_horizontal, int N_vertical)` - Split an image into N_horizontal x N_vertical equal sub-images, stored column by column (index k_vertical + N_vertical*k_horizontal); aborts if the size is not divisible.
- `GLuint opengl_load_texture_image(image_structure const& im, GLint wrap_s = GL_CLAMP_TO_EDGE, GLint wrap_t = GL_CLAMP_TO_EDGE)` - Upload an RGB or RGBA image as a new mipmapped 2D OpenGL texture (8 bits per channel) with the given wrap modes, returning its id.

Functions returning it:

- `image_structure image_load_png(std::string const& filename, image_color_type color_type = image_color_type::rgba)` - Load a PNG file into an image_structure, converted to RGBA by default or to RGB; exits the program on decoding error.
- `image_structure image_load_jpg(std::string const& filename)` - Load a JPEG file into an RGB image_structure.
- `image_structure image_load_file(std::string const& filename)` - Load an image file, choosing the PNG (RGBA) or JPEG (RGB) reader from the extension .png, .jpg or .jpeg, in any case.
