paradiso-win/src/lib/include/paradiso/bitmap.hpp

67 lines
2.2 KiB
C++
Raw Normal View History

2023-06-30 22:55:59 +02:00
/*
* Copyright 2023 Hartmut Seichter
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#ifndef PARADISO_BITMAP_HPP
#define PARADISO_BITMAP_HPP
2023-06-30 22:55:59 +02:00
#include <paradiso/globals.hpp>
#include <paradiso/geometry.hpp>
#include <paradiso/rgba.hpp>
namespace paradiso {
struct Bitmap final {
2023-06-30 22:05:23 +02:00
constexpr static Bitmap empty(Size size) noexcept {
return {.size = size, .data = std::vector<RGBA>{size.area()}};
}
2023-06-30 22:05:23 +02:00
template <typename... Arguments>
static constexpr Bitmap from_data(Size size, Arguments... values) noexcept {
assert(sizeof...(Arguments) == size.height * size.width);
return {
.size = size,
.data = {values...}
};
}
constexpr auto fill(const RGBA& color) noexcept {
std::fill(data.begin(), data.end(), color);
return *this;
}
constexpr RGBA& pixel(std::integral auto x, std::integral auto y) {
return data[y * size.width + x];
}
constexpr const RGBA& pixel(std::integral auto x,
std::integral auto y) const {
return data[y * size.width + x];
}
Size size{.width = 0, .height = 0};
std::vector<RGBA> data{};
};
} // namespace paradiso
#endif