v0.3.0 API Reference
Image.h
1//
2// Image.h
3// avara3d
4//
5// Created by Morgan Davis on 10/21/16.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_IMAGE_H
10#define AVARA3D_IMAGE_H
11
12#include <filesystem>
13#include <memory>
14
15namespace a3d {
16
17class Buffer;
18
27class Image {
28
29public:
30 // [Public Lifecycle Functions]
31
39 explicit Image(const std::filesystem::path& path, bool flipVertical = true, bool flipHorizontal = false);
40
48 explicit Image(const Buffer& buffer, bool flipVertical = true, bool flipHorizontal = false);
49
60 Image(std::unique_ptr<Buffer> buffer,
61 unsigned width,
62 unsigned height,
63 unsigned bytesPerPixel,
64 bool flipVertical = true,
65 bool flipHorizontal = false);
66
67 Image(const Image& other);
68 Image& operator=(const Image& other);
69
70 Image(Image&& other) noexcept;
71 Image& operator=(Image&& other) noexcept;
72
73 ~Image();
74
75 // [Public Member Functions]
76
78 unsigned width() const;
79
81 unsigned height() const;
82
84 unsigned bytesPerPixel() const;
85
92 std::unique_ptr<Image> inverted() const;
93
95 const Buffer& buffer() const;
96
102 bool writePNG(const std::filesystem::path& path) const;
103
104private:
105 // [Private Member Functions]
106
107 void loadBuffer(const Buffer& buffer, bool flipVertical, bool flipHorizontal);
108 void flipVertical(); // "flip"
109 void flipHorizontal(); // "mirror"
110
111 // [Private Member Variables]
112
113 unsigned _width;
114 unsigned _height;
115 unsigned _bytesPerPixel;
116 std::unique_ptr<Buffer> _buffer;
117};
118
119} // namespace a3d
120
121#endif // AVARA3D_IMAGE_H
Container for a contiguous byte buffer.
Definition: Buffer.h:23
Owns decoded pixel data and its dimensions.
Definition: Image.h:27
unsigned width() const
Returns the image width in pixels.
Image(std::unique_ptr< Buffer > buffer, unsigned width, unsigned height, unsigned bytesPerPixel, bool flipVertical=true, bool flipHorizontal=false)
Takes ownership of an existing pixel buffer and its dimensions.
const Buffer & buffer() const
Returns the Buffer containing the owned pixel data.
std::unique_ptr< Image > inverted() const
Returns a new Image with its color bytes inverted.
Image(const Buffer &buffer, bool flipVertical=true, bool flipHorizontal=false)
Decodes encoded image data from buffer.
Image(const std::filesystem::path &path, bool flipVertical=true, bool flipHorizontal=false)
Loads and decodes an image from path.
unsigned height() const
Returns the image height in pixels.
unsigned bytesPerPixel() const
Returns the number of bytes stored for each pixel.
bool writePNG(const std::filesystem::path &path) const
Writes the image pixels to a PNG file at path.