image_structure
Image stored on the CPU (width, height, RGB/RGBA data).
Fields and methods
Members of the struct image_structure. Most of what you do with a CGP type goes through the free functions listed below.
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. |
Methods
image_structure() | Builds an empty RGB image of size 0x0.2 overloads src |
image_structure(unsigned int width_arg, unsigned int height_arg, image_color_type color_type_arg, numarray<unsigned char> const& data_arg) | Builds an image from its size, color type and pixel bytes, without checking that the size of the data matches. src |
| Returns a copy of the rectangle of pixels [start_h,end_h[ x [start_v,end_v[ of the image, end bounds excluded. src | |
| Returns a copy of the image with the pixel columns reversed (left-right mirror). src | |
| Returns a copy of the image with the pixel rows reversed (top-bottom mirror). src | |
| Returns a copy of the image rotated by 90 degrees, with width and height swapped, where the output pixel (x,y) is the input pixel (width-1-y, x). src | |
| Returns a copy of the image rotated by 90 degrees, with width and height swapped, where the output pixel (x,y) is the input pixel (y, height-1-x). src |
Functions taking a image_structure
Compute 1
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.
Convert 1
I/O 3
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 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.
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 a image_structure
I/O 3
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.
image_structure image_load_jpg(std::string const& filename)Load a JPEG file into an RGB image_structure.
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.
Operators
None.