Simple Canvas
|
A simple library for 2D drawing in C++, by Chris Tralie. More...
#include <simplecanvas.h>
Public Member Functions | |
SimpleCanvas (std::string fname) | |
Construct a new image object from a file. More... | |
SimpleCanvas (int32_t width, int32_t height) | |
Instantiate an image object of a particular dimension. More... | |
~SimpleCanvas () | |
Destroy the Simple Image object by de-allocating the pixel data. | |
void | read (std::string fname) |
Read in a ppm file. Use ffmpeg to convert the file to a temporary .ppm file if it has a non ppm extension. More... | |
void | write (std::string fname) |
void | setPixel (int x, int y, uint8_t R, uint8_t G, uint8_t B) |
Set the color of a particular pixel. More... | |
void | fillRect (int x0, int y0, int w, int h, uint8_t R, uint8_t G, uint8_t B) |
Fill a solid rectangle with a color. More... | |
void | clearRect (uint8_t R, uint8_t G, uint8_t B) |
Clear the entire canvas to be one color. More... | |
void | drawRect (int x0, int y0, int w, int h, uint8_t R, uint8_t G, uint8_t B, uint8_t line_w) |
Draw the outline of a rectangle with a particular color. More... | |
void | drawLine (int x0, int y0, int x1, int y1, uint8_t R, uint8_t G, uint8_t B) |
Draw a thin line from one point to another. More... | |
void | drawLine (int x0, int y0, int x1, int y1, int thickness, uint8_t R, uint8_t G, uint8_t B) |
Draw a thick line from one point to another. More... | |
void | fillCircle (int cx, int cy, double r, uint8_t R, uint8_t G, uint8_t B) |
Fill in a solid disc of a particular color. More... | |
void | drawString (std::string s, int x0, int y0, std::string relpath) |
Draw a character at a string at a position. More... | |
Public Attributes | |
int | width |
int | height |
uint8_t *** | data |
A simple library for 2D drawing in C++, by Chris Tralie.
SimpleCanvas::SimpleCanvas | ( | std::string | fname | ) |
Construct a new image object from a file.
fname | Path to file |
SimpleCanvas::SimpleCanvas | ( | int32_t | width, |
int32_t | height | ||
) |
Instantiate an image object of a particular dimension.
width | Width of image |
height | Height of image |
void SimpleCanvas::clearRect | ( | uint8_t | R, |
uint8_t | G, | ||
uint8_t | B | ||
) |
Clear the entire canvas to be one color.
R | Red channel |
G | Green channel |
B | Blue channel |
void SimpleCanvas::drawLine | ( | int | x0, |
int | y0, | ||
int | x1, | ||
int | y1, | ||
int | thickness, | ||
uint8_t | R, | ||
uint8_t | G, | ||
uint8_t | B | ||
) |
Draw a thick line from one point to another.
x0 | X coordinate of first point |
y0 | Y coordinate of first point |
x1 | X coordinate of second point |
y1 | Y coordinate of second point |
thickness | Thickness of line |
R | Red channel |
G | Green channel |
B | Blue channel |
void SimpleCanvas::drawLine | ( | int | x0, |
int | y0, | ||
int | x1, | ||
int | y1, | ||
uint8_t | R, | ||
uint8_t | G, | ||
uint8_t | B | ||
) |
Draw a thin line from one point to another.
x0 | X coordinate of first point |
y0 | Y coordinate of first point |
x1 | X coordinate of second point |
y1 | Y coordinate of second point |
R | Red channel |
G | Green channel |
B | Blue channel |
void SimpleCanvas::drawRect | ( | int | x0, |
int | y0, | ||
int | w, | ||
int | h, | ||
uint8_t | R, | ||
uint8_t | G, | ||
uint8_t | B, | ||
uint8_t | line_w | ||
) |
Draw the outline of a rectangle with a particular color.
x0 | Left of rectangle |
y0 | Top of rectangle |
w | Width of rectangle |
h | Height of rectangle |
R | Red channel |
G | Green channel |
B | Blue channel |
line_w | Width of rectangle |
void SimpleCanvas::drawString | ( | std::string | s, |
int | x0, | ||
int | y0, | ||
std::string | relpath | ||
) |
Draw a character at a string at a position.
s | The string to draw |
x | x location of lower left corner of the string |
y | y location of lower left corner of the string |
relpath | Relative path to directory containing the fonts |
void SimpleCanvas::fillCircle | ( | int | cx, |
int | cy, | ||
double | r, | ||
uint8_t | R, | ||
uint8_t | G, | ||
uint8_t | B | ||
) |
Fill in a solid disc of a particular color.
cx | X coordinate of center of disc |
cy | Y coordinate of center of disc |
r | Radius of disc |
R | Red channel |
G | Green channel |
B | Blue channel |
void SimpleCanvas::fillRect | ( | int | x0, |
int | y0, | ||
int | w, | ||
int | h, | ||
uint8_t | R, | ||
uint8_t | G, | ||
uint8_t | B | ||
) |
Fill a solid rectangle with a color.
x0 | Left of rectangle |
y0 | Top of rectangle |
w | Width of rectangle |
h | Height of rectangle |
R | Red channel |
G | Green channel |
B | Blue channel |
void SimpleCanvas::read | ( | std::string | fname | ) |
Read in a ppm file. Use ffmpeg to convert the file to a temporary .ppm file if it has a non ppm extension.
fname | Path to file |
void SimpleCanvas::setPixel | ( | int | x, |
int | y, | ||
uint8_t | R, | ||
uint8_t | G, | ||
uint8_t | B | ||
) |
Set the color of a particular pixel.
x | X coordinate of pixel |
y | Y coordinate of pixel |
R | Red channel |
G | Green channel |
B | Blue channel |
void SimpleCanvas::write | ( | std::string | fname | ) |
Write the image to a file If the filename ends with an extension other than ppm, write it to a temporary ppm file, and use ffmpeg to convert it to the desired name
fname | Name of the file |