6 #include <gempyre_types.h>
21 #define GGEMPYRE_EX __declspec( dllexport )
27 #define gempyre_graphics_assert(b, x) ((b) || GempyreUtils::do_fatal(x, nullptr, __FILE__, __LINE__));
36 using type = Gempyre::dataT;
42 return std::min(FF, r) | (std::min(FF, g) << 8) | (std::min(FF, b) << 16) | (std::min(FF, a) << 24);
48 return r | (g << 8) | (b << 16) | (a << 24);
54 return r | (g << 8) | (b << 16) | (static_cast<type>(0xFF) << 24);
59 static constexpr
inline type r(
type pixel) {
60 return pixel &
static_cast<type>(0xFF);
64 static constexpr
inline type g(
type pixel) {
65 return (pixel &
static_cast<type>(0xFF00)) >> 8;
70 static constexpr
inline type b(
type pixel) {
71 return (pixel &
static_cast<type>(0xFF0000)) >> 16;
76 static constexpr
inline type alpha(
type pixel) {
77 return (pixel & 0xFF000000) >> 24;
82 static inline std::string rgba(
type pixel) {
83 constexpr
auto c =
"0123456789ABCDEF";
84 std::string v(
"#RRGGBBAA");
85 v[1] = c[r(pixel) >> 4];
86 v[2] = c[r(pixel) & 0xF];
87 v[3] = c[g(pixel) >> 4];
88 v[4] = c[g(pixel) & 0xF];
89 v[5] = c[b(pixel) >> 4];
90 v[6] = c[b(pixel) & 0xF];
91 v[7] = c[alpha(pixel) >> 4];
92 v[8] = c[alpha(pixel) & 0xF];
98 static inline std::string rgb(
type pixel) {
99 constexpr
auto c =
"0123456789ABCDEF";
100 std::string v(
"#RRGGBB");
101 v[1] = c[r(pixel) >> 4];
102 v[2] = c[r(pixel) & 0xF];
103 v[3] = c[g(pixel) >> 4];
104 v[4] = c[g(pixel) & 0xF];
105 v[5] = c[b(pixel) >> 4];
106 v[6] = c[b(pixel) & 0xF];
112 static inline std::string to_string(
type r,
type g,
type b,
type a = 0xFF) {
113 return a == 0xFF ? Gempyre::Color::rgb(Gempyre::Color::rgb(r, g, b)) : Gempyre::Color::rgba(Gempyre::Color::rgba(r, g, b, a));
119 return Gempyre::Color::to_string(
120 Gempyre::Color::r(color),
121 Gempyre::Color::g(color),
122 Gempyre::Color::b(color),
123 Gempyre::Color::alpha(color));
127 static constexpr
Color::type Black = Color::rgba(0, 0, 0, 0xFF);
129 static constexpr
Color::type White = Color::rgba(0xFF, 0xFF, 0xFF, 0xFF);
131 static constexpr
Color::type Red = Color::rgba(0xFF, 0, 0, 0xFF);
133 static constexpr
Color::type Green = Color::rgba(0, 0xFF, 0, 0xFF);
135 static constexpr
Color::type Blue = Color::rgba(0, 0, 0xFF, 0xFF);
137 static constexpr
Color::type Cyan = Color::rgba(0, 0xFF, 0xFF, 0xFF);
139 static constexpr
Color::type Magenta = Color::rgba(0xFF, 0, 0xFF, 0xFF);
141 static constexpr
Color::type Yellow = Color::rgba(0xFF, 0xFF, 0, 0xFF);
149 static constexpr
Color::type Transparent = Color::rgba(0, 0, 0, 0);
186 Bitmap(
const std::vector<uint8_t>& image_data);
240 void tile(
int x,
int y,
const Bitmap& other,
int width,
int height);
243 void tile(
int x,
int y,
const Bitmap& other,
int other_x,
int other_y,
int width,
int height);
258 template<
class T, std::enable_if_t<std::is_same_v<
typename T::value_type, Color::type>,
int> = 0>
260 if(bytes.size() + offset > size())
262 std::memcpy(inner_data() + offset *
sizeof(
Color::type), bytes.data(),
sizeof(
Color::type) * bytes.size());
268 void copy_from(
const Bitmap& other);
270 std::size_t size()
const;
274 Gempyre::CanvasDataPtr m_canvas{};
Bitmap for Gempyre Graphics.
Definition: gempyre_bitmap.h:154
bool empty() const
return true if there is not data
void create(int width, int height)
Create bitmap bytes.
void tile(int x, int y, const Bitmap &other, int other_x, int other_y, int width, int height)
Draw a Bitmap withing extents on this bitmap - replace area.
Bitmap clone() const
Deep copy bitmap bytes.
Bitmap clip(const Gempyre::Rect &rect) const
Create a new bitmap from part of bitmap.
std::vector< uint8_t > png_image() const
Convert a bitmap to PNG.
Bitmap(int width, int height)
Constructor - uninitialized data.
int width() const
Get width.
Color::type pixel(int x, int y) const
Get a single pixel.
int height() const
Get height.
void swap(Bitmap &other)
Swap bitmap data with another.
void tile(int x, int y, const Bitmap &other)
Draw a Bitmap on this bitmap - replace area.
Bitmap & operator=(const Bitmap &other)=default
Copy operator does only shallow copy, for deep copy.
void draw_rect(const Gempyre::Rect &rect, Color::type color)
Draw a rect with a color in bitmap.
void merge(int x, int y, const Bitmap &other)
Draw a Bitmap on this bitmap - merge alpha.
Bitmap & operator=(Bitmap &&other)=default
Move operator.
const uint8_t * const_data() const
underlaying data
bool set_data(const T &bytes, size_t offset=0)
Copy pixels into bitmap.
Definition: gempyre_bitmap.h:259
Bitmap(int width, int height, Gempyre::Color::type color)
Constructor - with a single color data.
Bitmap(Bitmap &&other)=default
Move constructor.
void set_pixel(int x, int y, Color::type color)
Set a single pixel.
Bitmap()
Constructor - zero size, use.
static constexpr Color::type pix(Color::type r, Color::type g, Color::type b, Color::type a=0xFF)
Components to pixel type.
Definition: gempyre_bitmap.h:207
void tile(int x, int y, const Bitmap &other, int width, int height)
Draw a Bitmap withing extents on this bitmap - replace area.
void merge(const Bitmap &other)
Draw a Bitmap on this bitmap - merge alpha.
Definition: gempyre_bitmap.h:234
Bitmap(const Bitmap &other)=default
Copy constructor - does not copy the data, for deep copy.
Bitmap(const std::vector< uint8_t > &image_data)
Create bitmap from byte array.
void set_alpha(int x, int y, Color::type alpha)
Set a singe pixel's alpha value.
Graphics element.
Definition: gempyre_graphics.h:39
Gempyre::dataT type
pixel type
Definition: gempyre_bitmap.h:36
Rect.
Definition: gempyre_types.h:24