Avara3D 0.2.0
C++ 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
17 class Buffer;
18
27 class Image {
28
29 public:
30 // [Public Lifecycle Functions]
31
39 explicit Image(const std::filesystem::path& path,
40 bool flipVertical = true,
41 bool flipHorizontal = false);
42
50 explicit Image(const Buffer& buffer, bool flipVertical = true, bool flipHorizontal = false);
51
62 Image(std::unique_ptr<Buffer> buffer,
63 unsigned width,
64 unsigned height,
65 unsigned bytesPerPixel,
66 bool flipVertical = true,
67 bool flipHorizontal = false);
68
69 Image(const Image& other);
70 Image& operator=(const Image& other);
71
72 Image(Image&& other) noexcept;
73 Image& operator=(Image&& other) noexcept;
74
75 ~Image();
76
77 // [Public Member Functions]
78
80 unsigned width() const;
81
83 unsigned height() const;
84
86 unsigned bytesPerPixel() const;
87
94 std::unique_ptr<Image> inverted() const;
95
97 const Buffer& buffer() const;
98
104 bool writePNG(const std::filesystem::path& path) const;
105
106 private:
107 // [Private Member Functions]
108
109 void loadBuffer(const Buffer& buffer, bool flipVertical, bool flipHorizontal);
110 void flipVertical(); // "flip"
111 void flipHorizontal(); // "mirror"
112
113 // [Private Member Variables]
114
115 unsigned _width;
116 unsigned _height;
117 unsigned _bytesPerPixel;
118 std::unique_ptr<Buffer> _buffer;
119 };
120
121}
122
123#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.