Container for picture data. Data are stored as unsigned char [0,255]. More...
Public Member Functions | |
image () | |
empty constructor | |
image (const unsigned int &N) | |
create square picture of size NxN | |
image (const unsigned int &Nx, const unsigned int &Ny) | |
create picture of size Nx x Ny | |
image (const std::string &filename) | |
import pre-existing picture from file filename | |
const unsigned int & | get_Nx () const |
get the picture width in pixel | |
const unsigned int & | get_Ny () const |
get the picture height in pixel | |
void | resize (const unsigned int &N) |
resize the picture to a square of size NxN | |
void | resize (const unsigned int &Nx, const unsigned int &Ny) |
resize the picture to a square of size Nx x Ny | |
void | reshape (const unsigned int &Nx2) |
try to reshape the picture to a new size | |
bool | check_position (const p2d &u) const |
check if a given pixel (kx,ky) is within the size of the picture | |
void | set_pixel (const p2d &u, const color &c) |
set a given pixel with (r,g,b) color | |
void | get_pixel (const p2d &u, color *c) const |
get the current color from a given pixel | |
const unsigned char & | get_r (const p2d &u) const |
get the current red color for pixel (kx,ky) | |
const unsigned char & | get_g (const p2d &u) const |
get the current green color for pixel (kx,ky) | |
const unsigned char & | get_b (const p2d &u) const |
get the current blue color for pixel (kx,ky) | |
const std::vector< unsigned char > & | get_data () const |
get internal data format | |
std::vector< unsigned char > & | get_data () |
get internal data format | |
void | fill (const color &c) |
fill the entire picture with a given (r,g,b) color | |
void | fill_rectangle (const p2d &u1, const p2d &u2, const color &c) |
fill a rectangle ((x1,y1);(x2,y2)) with a given (r,g,b) color | |
void | export_ppm (const std::string &filename) |
Export the picture into ppm format (ascii). | |
Protected Member Functions | |
int | coordinate_to_index (const p2d &u) const |
transform coordinate u=(kx,ky) to index in vector data | |
Static Private Member Functions | |
static image | read_ppm (const std::string &filename) |
read a ppm picture format | |
Private Attributes | |
std::vector< unsigned char > | internal_data |
internal data storage as std::vector of unsigned char | |
unsigned int | internal_Nx |
storage of picture width | |
unsigned int | internal_Ny |
storage of picture height |
Container for picture data. Data are stored as unsigned char [0,255].
cpe::image::image | ( | ) |
empty constructor
Referenced by resize().
cpe::image::image | ( | const unsigned int & | N | ) |
create square picture of size NxN
unsigned | int N: size (width & height) of the picture |
References internal_data.
cpe::image::image | ( | const unsigned int & | Nx, | |
const unsigned int & | Ny | |||
) |
create picture of size Nx x Ny
unsigned | int Nx: picture width | |
unsigned | int Ny: picture height |
References internal_data.
cpe::image::image | ( | const std::string & | filename | ) |
import pre-existing picture from file filename
std::string | filename: path to the file to load |
References read_ppm().
bool cpe::image::check_position | ( | const p2d & | u | ) | const [inline] |
check if a given pixel (kx,ky) is within the size of the picture
p2d | u: current (kx,ky)-coordinate |
References internal_Nx, internal_Ny, cpe::p2d::x(), and cpe::p2d::y().
Referenced by fill_rectangle(), get_b(), get_g(), get_pixel(), get_r(), cpe::image_drawable_zbuffer::line(), cpe::image_drawable::line(), and set_pixel().
int cpe::image::coordinate_to_index | ( | const p2d & | u | ) | const [protected] |
transform coordinate u=(kx,ky) to index in vector data
References internal_Nx, cpe::p2d::x(), and cpe::p2d::y().
void cpe::image::export_ppm | ( | const std::string & | filename | ) |
Export the picture into ppm format (ascii).
std::string | filename: file to store the picture |
References internal_data, internal_Nx, and internal_Ny.
Referenced by main().
void cpe::image::fill | ( | const color & | c | ) |
fill the entire picture with a given (r,g,b) color
color | c: (red,green,blue) value |
References cpe::color::b(), cpe::color::g(), internal_data, internal_Nx, internal_Ny, and cpe::color::r().
Referenced by main().
fill a rectangle ((x1,y1);(x2,y2)) with a given (r,g,b) color
p2d | u1: (x,y)-coordinate of starting point | |
p2d | u2: (x,y)-coordinate of ending point | |
color | c: (r,g,b) value |
References cpe::color::b(), check_position(), cpe::color::g(), internal_data, internal_Nx, internal_Ny, cpe::color::r(), cpe::p2d::x(), and cpe::p2d::y().
const unsigned char & cpe::image::get_b | ( | const p2d & | u | ) | const |
get the current blue color for pixel (kx,ky)
p2d | u: current (x,y)-coordinate |
References check_position(), internal_data, internal_Nx, internal_Ny, cpe::p2d::x(), and cpe::p2d::y().
std::vector< unsigned char > & cpe::image::get_data | ( | ) |
get internal data format
References internal_data.
const std::vector< unsigned char > & cpe::image::get_data | ( | ) | const |
const unsigned char & cpe::image::get_g | ( | const p2d & | u | ) | const |
get the current green color for pixel (kx,ky)
p2d | u: current (x,y)-coordinate |
References check_position(), internal_data, internal_Nx, internal_Ny, cpe::p2d::x(), and cpe::p2d::y().
const unsigned int & cpe::image::get_Nx | ( | ) | const |
get the picture width in pixel
References internal_Nx.
Referenced by cpe::image_drawable_zbuffer::image_drawable_zbuffer(), and cpe::render_engine::render_triangle().
const unsigned int & cpe::image::get_Ny | ( | ) | const |
get the picture height in pixel
References internal_Ny.
Referenced by cpe::image_drawable_zbuffer::image_drawable_zbuffer().
get the current color from a given pixel
p2d | u: current (x,y)-coordinate | |
color* | c: (r,g,b) color value (pointer) |
References cpe::color::b(), check_position(), cpe::color::g(), internal_data, internal_Nx, internal_Ny, cpe::color::r(), cpe::p2d::x(), and cpe::p2d::y().
const unsigned char & cpe::image::get_r | ( | const p2d & | u | ) | const |
get the current red color for pixel (kx,ky)
p2d | u: current (x,y)-coordinate |
References check_position(), internal_data, internal_Nx, internal_Ny, cpe::p2d::x(), and cpe::p2d::y().
image cpe::image::read_ppm | ( | const std::string & | filename | ) | [static, private] |
read a ppm picture format
std::string | filename: path of the file to read |
References get_data().
Referenced by image().
void cpe::image::reshape | ( | const unsigned int & | Nx2 | ) |
try to reshape the picture to a new size
unsigned | int Nx: the new picture width |
References internal_Nx, and internal_Ny.
void cpe::image::resize | ( | const unsigned int & | Nx, | |
const unsigned int & | Ny | |||
) |
resize the picture to a square of size Nx x Ny
unsigned | int Nx: new picture width | |
unsigned | Ny: new picture height |
References image().
void cpe::image::resize | ( | const unsigned int & | N | ) |
resize the picture to a square of size NxN
unsigned | int N: new picture width and height |
References image().
set a given pixel with (r,g,b) color
p2d | u: current (x,y)-coordinate | |
color | c: (r,g,b) color value |
References cpe::color::b(), check_position(), cpe::color::g(), internal_data, internal_Nx, internal_Ny, cpe::color::r(), cpe::p2d::x(), and cpe::p2d::y().
Referenced by cpe::image_drawable_zbuffer::line(), and cpe::image_drawable::line().
std::vector<unsigned char> cpe::image::internal_data [private] |
internal data storage as std::vector of unsigned char
Picture is stored as (r0,b0,g0,a0 , r1,b1,g1,a1 , ...) vector size is therefore 4 Nx Ny
Referenced by export_ppm(), fill(), fill_rectangle(), get_b(), get_data(), get_g(), get_pixel(), get_r(), image(), and set_pixel().
unsigned int cpe::image::internal_Nx [private] |
storage of picture width
Referenced by check_position(), coordinate_to_index(), export_ppm(), fill(), fill_rectangle(), get_b(), get_g(), get_Nx(), get_pixel(), get_r(), reshape(), and set_pixel().
unsigned int cpe::image::internal_Ny [private] |
storage of picture height
Referenced by check_position(), export_ppm(), fill(), fill_rectangle(), get_b(), get_g(), get_Ny(), get_pixel(), get_r(), reshape(), and set_pixel().