Graphics v0.0.0
A simple abstraction layer for the modern graphics APIs.
载入中...
搜索中...
未找到
Image.h
1// Copyright 2022 ShenMian
2// License(Apache-2.0)
3
4#pragma once
5
6#include <cstdint>
7#include <filesystem>
8#include <math/math.hpp>
9#include <vector>
10
18class Image
19{
20public:
24 Image() = default;
25
31 Image(const std::filesystem::path& path);
32
41 Image(const void* data, size_t sizeBytes, const Vector2i& size, int channels);
42
48 void load(const std::filesystem::path& path);
49
58 void load(const void* data, size_t sizeBytes, const Vector2i& size, int channels);
59
67 void save(const std::filesystem::path& path) const;
68
72 void set_pixel(const Vector4f& color, const Vector2i& pos);
73
77 Vector4f get_pixel(const Vector2i& pos) const;
78
82 void flip_horizontally() noexcept;
83
87 void flip_vertically() noexcept;
88
92 uint8_t* data() noexcept;
93
97 const uint8_t* data() const noexcept;
98
102 size_t size_bytes() const noexcept;
103
107 Vector2i size() const noexcept;
108
112 int channel_count() const noexcept;
113
114private:
115 std::vector<uint8_t> data_;
116 Vector2i size_;
117 int channels_ = 0;
118};
119
图像.
Definition: Image.h:19
int channel_count() const noexcept
获取通道数.
Definition: Image.cpp:159
Vector4f get_pixel(const Vector2i &pos) const
获取指定像素.
Definition: Image.cpp:99
void load(const std::filesystem::path &path)
从文件载入图像.
Image()=default
默认构造函数.
void flip_vertically() noexcept
垂直(上下)翻转.
Definition: Image.cpp:124
Vector2i size() const noexcept
获取图像分辨率.
Definition: Image.cpp:154
void save(const std::filesystem::path &path) const
导出图像到文件.
Definition: Image.cpp:60
Image(const std::filesystem::path &path)
构造函数, 从文件载入图像.
void flip_horizontally() noexcept
水平(左右)翻转.
Definition: Image.cpp:106
size_t size_bytes() const noexcept
获取图像数据大小.
Definition: Image.cpp:149
uint8_t * data() noexcept
获取图像数据.
Definition: Image.cpp:139
void set_pixel(const Vector4f &color, const Vector2i &pos)
获取图像数据.
Definition: Image.cpp:89