|
scimesh 0.3.2
Headless CPU-only 3D software renderer for scientific mesh visualization
|
A 2D RGBA image buffer. More...
#include <image.h>
Public Member Functions | |
| Image ()=default | |
| Construct an empty (0×0) image. | |
| Image (int w, int h) | |
| Construct an image of the given size, initialized to transparent black (0, 0, 0, 0). | |
| void | set_pixel (int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t a) |
| Set a single pixel's RGBA value. | |
| void | get_pixel (int x, int y, uint8_t &r, uint8_t &g, uint8_t &b, uint8_t &a) const |
| Get a single pixel's RGBA value. | |
| void | clear (uint8_t r, uint8_t g, uint8_t b, uint8_t a) |
| Fill the entire image with an RGBA color (byte values 0–255). | |
| void | clear_float (float r, float g, float b, float a) |
| Fill the entire image with an RGBA color (float values 0.0–1.0). | |
| Color | sample_bilinear (float u, float v) const |
| Sample the image at texture coordinates (u, v) using bilinear interpolation. | |
| Image | downsample_box (int factor) const |
| Downsample the image by a factor using box filtering. | |
| void | crop (int x, int y, int w, int h) |
| Crop the image to a sub-rectangle. | |
| void | merge (const Image &other, MergeDirection direction) |
| Merge (concatenate) another image onto this one. | |
| void | grow (int top, int bottom, int left, int right, const Color &background) |
| Grow (pad) the image by adding borders. | |
| void | rotate_90 (bool clockwise=true) |
| Rotate the image by 90 degrees in-place. | |
| void | scale (int new_width, int new_height) |
| Scale (resize) the image to new dimensions in-place. | |
| void | crop_to_content (CropContentDirection direction, const Color &background) |
| Crop away uniform borders of a given background color. | |
| void | apply_contrast (float contrast) |
| Apply a contrast adjustment to the image. | |
| bool | write_ppm (const std::string &filename) const |
| Write the image as a PPM file (Portable Pixmap). | |
| bool | write_bmp (const std::string &filename) const |
| Write the image as a BMP file (Windows Bitmap). | |
| bool | write_tga (const std::string &filename, bool use24bit=false) const |
| Write the image as a TGA file (Truevision Targa). | |
| bool | write_png (const std::string &filename) const |
| Write the image as a PNG file. | |
| void | pad_to_size (int target_w, int target_h, const Color &background) |
| Pad the image to a target size, centering the content. | |
Static Public Member Functions | |
| static Image | read_image (const std::string &path) |
| Read an image from a file (PNG, BMP, TGA, JPEG, etc.). | |
Public Attributes | |
| int | width = 0 |
| Image width in pixels. | |
| int | height = 0 |
| Image height in pixels. | |
| std::vector< uint8_t > | pixels |
| Raw pixel data: RGBA bytes, row-major, bottom-left origin. | |
A 2D RGBA image buffer.
The Image class stores pixels as 4 bytes per pixel (red, green, blue, alpha) in row-major order. Pixel (0, 0) is the bottom-left corner (matching OpenGL texture convention).
Images are used both as render targets (the output of the renderer) and as texture sources for textured meshes.
|
default |
Construct an empty (0×0) image.
| scimesh::Image::Image | ( | int | w, |
| int | h | ||
| ) |
| void scimesh::Image::apply_contrast | ( | float | contrast | ) |
Apply a contrast adjustment to the image.
A value of 1.0 means no change. Values > 1.0 increase contrast; values < 1.0 reduce it (0.0 = uniform gray).
| contrast | Contrast multiplier (1.0 = unchanged). |
| void scimesh::Image::clear | ( | uint8_t | r, |
| uint8_t | g, | ||
| uint8_t | b, | ||
| uint8_t | a | ||
| ) |
| void scimesh::Image::clear_float | ( | float | r, |
| float | g, | ||
| float | b, | ||
| float | a | ||
| ) |
| void scimesh::Image::crop | ( | int | x, |
| int | y, | ||
| int | w, | ||
| int | h | ||
| ) |
Crop the image to a sub-rectangle.
The cropped region replaces the image in-place.
| x | Left edge of the crop region. |
| y | Bottom edge of the crop region. |
| w | Width of the crop region. |
| h | Height of the crop region. |
| void scimesh::Image::crop_to_content | ( | CropContentDirection | direction, |
| const Color & | background | ||
| ) |
Crop away uniform borders of a given background color.
Removes rows/columns from the specified edges as long as every pixel in that row/column matches the background color (within tolerance).
| direction | Which edge(s) to crop. |
| background | The color to treat as "empty" border. |
| Image scimesh::Image::downsample_box | ( | int | factor | ) | const |
Downsample the image by a factor using box filtering.
Reduces the image size. Each output pixel is the average of a factor × factor block of input pixels. The width and height must be divisible by factor.
| factor | Downsampling factor (e.g., 2 halves both dimensions). |
| void scimesh::Image::get_pixel | ( | int | x, |
| int | y, | ||
| uint8_t & | r, | ||
| uint8_t & | g, | ||
| uint8_t & | b, | ||
| uint8_t & | a | ||
| ) | const |
| void scimesh::Image::grow | ( | int | top, |
| int | bottom, | ||
| int | left, | ||
| int | right, | ||
| const Color & | background | ||
| ) |
Grow (pad) the image by adding borders.
Adds top, bottom, left, right rows/columns filled with the given background color.
| top | Pixels to add above the image. |
| bottom | Pixels to add below the image. |
| left | Pixels to add left of the image. |
| right | Pixels to add right of the image. |
| background | Fill color for the new border. |
| void scimesh::Image::merge | ( | const Image & | other, |
| MergeDirection | direction | ||
| ) |
Merge (concatenate) another image onto this one.
The two images must have compatible dimensions for the merge direction. For LEFT/RIGHT merges, both images must have the same height. For TOP/BOTTOM merges, both images must have the same width.
| other | The image to attach. |
| direction | Which side to attach to. |
| void scimesh::Image::pad_to_size | ( | int | target_w, |
| int | target_h, | ||
| const Color & | background | ||
| ) |
Pad the image to a target size, centering the content.
Adds borders filled with background so the image reaches target_w × target_h. Content stays pixel-perfect — no scaling. If the image is already at or larger than the target size, this is a no-op.
| target_w | Desired width in pixels. |
| target_h | Desired height in pixels. |
| background | Fill color for the added borders. |
|
static |
Read an image from a file (PNG, BMP, TGA, JPEG, etc.).
Uses stb_image internally, which auto-detects the format from the file header. Returns an empty (0×0) image on failure.
| path | Path to the image file. |
| void scimesh::Image::rotate_90 | ( | bool | clockwise = true | ) |
| Color scimesh::Image::sample_bilinear | ( | float | u, |
| float | v | ||
| ) | const |
Sample the image at texture coordinates (u, v) using bilinear interpolation.
Bilinear sampling blends the four nearest pixels, producing a smooth result when texture coordinates fall between pixel centers.
| u | Horizontal texture coordinate (0.0–1.0, 0 = left). |
| v | Vertical texture coordinate (0.0–1.0, 0 = bottom). |
| void scimesh::Image::scale | ( | int | new_width, |
| int | new_height | ||
| ) |
| void scimesh::Image::set_pixel | ( | int | x, |
| int | y, | ||
| uint8_t | r, | ||
| uint8_t | g, | ||
| uint8_t | b, | ||
| uint8_t | a | ||
| ) |
| bool scimesh::Image::write_bmp | ( | const std::string & | filename | ) | const |
Write the image as a BMP file (Windows Bitmap).
BMP is a simple, uncompressed format. No external libraries needed.
| filename | Output file path (should end with .bmp). |
true on success.| bool scimesh::Image::write_png | ( | const std::string & | filename | ) | const |
Write the image as a PNG file.
PNG is the recommended output format for publication-quality results. Uses stb_image_write internally.
| filename | Output file path (should end with .png). |
true on success.| bool scimesh::Image::write_ppm | ( | const std::string & | filename | ) | const |
Write the image as a PPM file (Portable Pixmap).
PPM is a simple, uncompressed format useful for debugging and testing. No external libraries are needed.
| filename | Output file path (should end with .ppm). |
true on success.| bool scimesh::Image::write_tga | ( | const std::string & | filename, |
| bool | use24bit = false |
||
| ) | const |
Write the image as a TGA file (Truevision Targa).
Writes an uncompressed true-color TGA file (image type 2) using scimesh's own implementation (no external libraries). The header declares a top-left origin, matching the pixel layout produced by the renderer. Pixel data is stored BGR(A) per the TGA spec, so red and blue channels are swapped on write.
| filename | Output file path (should end with .tga). |
| use24bit | If true, write 24-bit RGB (no alpha channel). Default false writes 32-bit RGBA. |
true on success.| std::vector<uint8_t> scimesh::Image::pixels |