Photon 1.0.0
Loading...
Searching...
No Matches
Bitmap.h
Go to the documentation of this file.
1#pragma once
2#include <litehtml.h>
3using namespace litehtml;
4using rect = position;
5namespace canvas_ity { class canvas; }
6using namespace canvas_ity;
7
8// color != web_color because sizeof(web_color) != 4
9struct color
10{
11 byte r, g, b, a;
12
13 color() : r(0), g(0), b(0), a(0) {}
14 color(byte r, byte g, byte b, byte a) : r(r), g(g), b(b), a(a) {}
15 color(web_color c) : r(c.red), g(c.green), b(c.blue), a(c.alpha) {}
16
17 bool operator==(color c) const { return r == c.r && g == c.g && b == c.b && a == c.a; }
18 bool operator!=(color c) const { return !(*this == c); }
19};
20const color white(255,255,255,255);
21const color black(0,0,0,255);
22const color transparent(0,0,0,0);
23
24class Bitmap
25{
26public:
27 int width = 0;
28 int height = 0;
29 vector<color> data;
30
31 Bitmap() {}
33 {
34 data.resize(width * height, color);
35 }
36 Bitmap(string filename)
37 {
38 load(filename);
39 }
41
42 bool operator==(const Bitmap& bmp) const { return width == bmp.width && height == bmp.height && data == bmp.data; }
43 bool operator!=(const Bitmap& bmp) const { return !(*this == bmp); }
44 operator bool() const { return width != 0 && height != 0; }
45
46 color get_pixel(int x, int y) const;
47 void set_pixel(int x, int y, color color);
48 void draw_line(int x0, int y0, int x1, int y1, color color);
49 void draw_rect(int x, int y, int width, int height, color color);
51 void replace_color(color original, color replacement);
52
53 rect find_picture(color bgcolor = white);
54 void load(string filename);
55 void save(string filename);
56};
57
58byte max_color_diff(const Bitmap& a, const Bitmap& b);
byte max_color_diff(const Bitmap &a, const Bitmap &b)
Definition Bitmap.cpp:119
const color transparent(0, 0, 0, 0)
Definition Bitmap.h:25
int height
Definition Bitmap.h:28
void draw_rect(int x, int y, int width, int height, color color)
Definition Bitmap.cpp:45
Bitmap(string filename)
Definition Bitmap.h:36
bool operator==(const Bitmap &bmp) const
Definition Bitmap.h:42
void set_pixel(int x, int y, color color)
Definition Bitmap.cpp:19
rect find_picture(color bgcolor=white)
Definition Bitmap.cpp:70
void fill_rect(rect rect, color color)
Definition Bitmap.cpp:53
void draw_line(int x0, int y0, int x1, int y1, color color)
Definition Bitmap.cpp:27
int width
Definition Bitmap.h:27
bool operator!=(const Bitmap &bmp) const
Definition Bitmap.h:43
void replace_color(color original, color replacement)
Definition Bitmap.cpp:60
Bitmap()
Definition Bitmap.h:31
color get_pixel(int x, int y) const
Definition Bitmap.cpp:11
Bitmap(int width, int height, color color=white)
Definition Bitmap.h:32
void save(string filename)
Definition Bitmap.cpp:113
vector< color > data
Definition Bitmap.h:29
void load(string filename)
Definition Bitmap.cpp:100
Definition canvas_ity.hpp:276
Definition Bitmap.h:5
Definition background.h:12
Definition Bitmap.h:10
byte a
Definition Bitmap.h:11
bool operator==(color c) const
Definition Bitmap.h:17
byte b
Definition Bitmap.h:11
color()
Definition Bitmap.h:13
color(web_color c)
Definition Bitmap.h:15
color(byte r, byte g, byte b, byte a)
Definition Bitmap.h:14
bool operator!=(color c) const
Definition Bitmap.h:18
byte r
Definition Bitmap.h:11
byte g
Definition Bitmap.h:11
Definition format.h:1901
Definition types.h:103
Definition web_color.h:9
b
Definition tag_strings.h:61
a
Definition tag_strings.h:43