CGPdocs

image_structure

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

module 07_imagesource: image.hpp
An image_structure stores its pixels row by row from the top row of the file, 4 bytes (rgba) or 3 bytes (rgb) per pixel: pixel (x, y) of an rgba image starts at data[4*(x + width*y)].
An image_structure stores its pixels row by row from the top row of the file, 4 bytes (rgba) or 3 bytes (rgb) per pixel: pixel (x, y) of an rgba image starts at data[4*(x + width*y)]. Tap to enlarge.

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 widthNumber of pixels in the horizontal direction.
int heightNumber of pixels in the vertical direction.
image_color_type color_typePixel format of data, rgb (3 bytes per pixel) or rgba (4 bytes per pixel).
numarray<unsigned char> dataPixel 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

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.

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.

CGP - Computer Graphics Programming.