Thu, 08 Jul 2021 09:15:25 +0300
* Bitmap bug fixed
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
1 | #include "Bitmap.h" |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
2 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
3 | #include <fstream> |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
4 | #include <algorithm> |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
5 | #include <numeric> |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
6 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
7 | #include "../Encoding/PNG.h" |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
8 | #include "../Encoding/JPEG.h" |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
9 | #include "../IO/Stream.h" |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
10 | #include "../Utils/Assert.h" |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
11 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
12 | namespace Gorgon { namespace Graphics { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
13 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
14 | void Bitmap::Prepare() { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
15 | if(data) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
16 | Graphics::Texture::Set(*data); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
17 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
18 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
19 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
20 | void Bitmap::Discard() { |
1576 | 21 | delete data; |
22 | data=nullptr; | |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
23 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
24 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
25 | bool Bitmap::Import(const std::string &filename) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
26 | auto dotpos = filename.find_last_of('.'); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
27 | if(dotpos!=-1) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
28 | auto ext = filename.substr(dotpos+1); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
29 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
30 | if(String::ToLower(ext) == "png") { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
31 | return ImportPNG(filename); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
32 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
33 | else if(String::ToLower(ext) == "jpg" || String::ToLower(ext) =="jpeg") { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
34 | return ImportJPEG(filename); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
35 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
36 | else if(String::ToLower(ext) == "bmp") { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
37 | return ImportBMP(filename); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
38 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
39 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
40 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
41 | std::ifstream file(filename, std::ios::binary); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
42 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
43 | static const uint32_t pngsig = 0x474E5089; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
44 | static const uint32_t jpgsig1 = 0xE0FFD8FF; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
45 | static const uint32_t jpgsig2 = 0xE1FFD8FF; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
46 | static const uint32_t bmpsig = 0x4D42; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
47 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
48 | uint32_t sig = IO::ReadUInt32(file); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
49 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
50 | file.close(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
51 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
52 | if(sig == pngsig) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
53 | return ImportPNG(filename); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
54 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
55 | else if(sig == jpgsig1 || sig == jpgsig2) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
56 | return ImportJPEG(filename); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
57 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
58 | else if((sig&0xffff) == bmpsig) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
59 | return ImportBMP(filename); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
60 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
61 | |
1576 | 62 | throw std::runtime_error("Unsupported file format"); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
63 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
64 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
65 | bool Bitmap::Import(std::istream &file) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
66 | static const uint32_t pngsig = 0x474E5089; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
67 | static const uint32_t jpgsig1 = 0xE0FFD8FF; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
68 | static const uint32_t jpgsig2 = 0xE1FFD8FF; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
69 | static const uint32_t bmpsig = 0x4D42; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
70 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
71 | uint32_t sig = IO::ReadUInt32(file); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
72 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
73 | file.seekg(-4, std::ios::cur); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
74 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
75 | if(sig == pngsig) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
76 | return ImportPNG(file); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
77 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
78 | else if(sig == jpgsig1 || sig == jpgsig2) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
79 | return ImportJPEG(file); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
80 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
81 | else if((sig&0xffff) == bmpsig) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
82 | return ImportBMP(file); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
83 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
84 | |
1576 | 85 | throw std::runtime_error("Unsupported file format"); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
86 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
87 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
88 | bool Bitmap::ImportPNG(const std::string &filename) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
89 | std::ifstream file(filename, std::ios::binary); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
90 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
91 | if(!file.is_open() || !file.good()) return false; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
92 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
93 | Destroy(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
94 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
95 | data=new Containers::Image(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
96 | Encoding::Png.Decode(file, *data); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
97 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
98 | return true; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
99 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
100 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
101 | bool Bitmap::ImportJPEG(const std::string &filename) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
102 | std::ifstream file(filename, std::ios::binary); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
103 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
104 | if(!file.is_open() || !file.good()) return false; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
105 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
106 | Destroy(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
107 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
108 | data=new Containers::Image(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
109 | Encoding::Jpg.Decode(file, *data); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
110 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
111 | return true; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
112 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
113 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
114 | bool Bitmap::ImportBMP(const std::string &filename) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
115 | std::ifstream file(filename, std::ios::binary); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
116 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
117 | if(!file.is_open() || !file.good()) return false; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
118 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
119 | Destroy(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
120 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
121 | data=new Containers::Image(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
122 | return data->ImportBMP(filename); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
123 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
124 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
125 | bool Bitmap::ImportPNG(std::istream &file) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
126 | Destroy(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
127 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
128 | data=new Containers::Image(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
129 | Encoding::Png.Decode(file, *data); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
130 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
131 | return true; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
132 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
133 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
134 | bool Bitmap::ImportJPEG(std::istream &file) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
135 | Destroy(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
136 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
137 | data=new Containers::Image(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
138 | Encoding::Jpg.Decode(file, *data); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
139 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
140 | return true; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
141 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
142 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
143 | bool Bitmap::ImportBMP(std::istream &file) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
144 | Destroy(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
145 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
146 | data=new Containers::Image(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
147 | return data->ImportBMP(file); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
148 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
149 | |
1695 | 150 | bool Bitmap::Export(const std::string &filename) const { |
1517
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
151 | auto dotpos = filename.find_last_of('.'); |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
152 | if(dotpos!=-1) { |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
153 | auto ext = filename.substr(dotpos+1); |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
154 | |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
155 | if(String::ToLower(ext) == "png") { |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
156 | return ExportPNG(filename); |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
157 | } |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
158 | else if(String::ToLower(ext) == "jpg" || String::ToLower(ext) =="jpeg") { |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
159 | return ExportJPEG(filename); |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
160 | } |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
161 | else if(String::ToLower(ext) == "bmp") { |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
162 | return ExportBMP(filename); |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
163 | } |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
164 | } |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
165 | |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
166 | return false; |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
167 | } |
868dcba12c8a
* Export function in Bitmap that determines file type from extension
cemkalyoncu
parents:
1318
diff
changeset
|
168 | |
1695 | 169 | bool Bitmap::ExportPNG(const std::string &filename) const { |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
170 | ASSERT(data, "Image data does not exists"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
171 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
172 | if(GetMode()!=Graphics::ColorMode::RGB && |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
173 | GetMode()!=Graphics::ColorMode::RGBA && |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
174 | GetMode()!=Graphics::ColorMode::Grayscale && |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
175 | GetMode()!=Graphics::ColorMode::Grayscale_Alpha && |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
176 | GetMode()!=Graphics::ColorMode::Alpha) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
177 | throw std::runtime_error("Unsupported color mode"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
178 | |
1318
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
179 | if(data->GetSize().Cells() == 0) |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
180 | return false; |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
181 | |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
182 | std::ofstream file(filename, std::ios::binary); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
183 | if(!file.is_open()) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
184 | return false; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
185 | |
1318
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
186 | Encoding::Png.Encode(*data, file); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
187 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
188 | return true; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
189 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
190 | |
1695 | 191 | bool Bitmap::ExportPNG(std::ostream &out) const { |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
192 | ASSERT(data, "Image data does not exists"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
193 | |
1318
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
194 | if(data->GetSize().Cells() == 0) |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
195 | return false; |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
196 | |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
197 | if(GetMode()!=Graphics::ColorMode::RGB && |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
198 | GetMode()!=Graphics::ColorMode::RGBA && |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
199 | GetMode()!=Graphics::ColorMode::Grayscale && |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
200 | GetMode()!=Graphics::ColorMode::Grayscale_Alpha && |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
201 | GetMode()!=Graphics::ColorMode::Alpha) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
202 | throw std::runtime_error("Unsupported color mode"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
203 | |
1318
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
204 | Encoding::Png.Encode(*data, out); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
205 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
206 | return true; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
207 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
208 | |
1695 | 209 | bool Bitmap::ExportBMP(const std::string &filename) const { |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
210 | ASSERT(data, "Image data does not exists"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
211 | |
1318
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
212 | if(data->GetSize().Cells() == 0) |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
213 | return false; |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
214 | |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
215 | return data->ExportBMP(filename); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
216 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
217 | |
1695 | 218 | bool Bitmap::ExportBMP(std::ostream &out) const { |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
219 | ASSERT(data, "Image data does not exists"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
220 | |
1318
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
221 | if(data->GetSize().Cells() == 0) |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
222 | return false; |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
223 | |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
224 | return data->ExportBMP(out); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
225 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
226 | |
1695 | 227 | bool Bitmap::ExportJPEG(const std::string &filename, int quality) const { |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
228 | ASSERT(data, "Image data does not exists"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
229 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
230 | if(GetMode()!=Graphics::ColorMode::RGB && |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
231 | GetMode()!=Graphics::ColorMode::Grayscale) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
232 | throw std::runtime_error("Unsupported color mode"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
233 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
234 | if(quality < 0 || quality > 100) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
235 | throw std::runtime_error("Unsupported quality"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
236 | |
1318
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
237 | if(data->GetSize().Cells() == 0) |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
238 | return false; |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
239 | |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
240 | std::ofstream file(filename, std::ios::binary); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
241 | if(!file.is_open()) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
242 | return false; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
243 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
244 | Encoding::Jpg.Encode(*data, file, quality); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
245 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
246 | return true; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
247 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
248 | |
1695 | 249 | bool Bitmap::ExportJPG(std::ostream &out, int quality) const { |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
250 | ASSERT(data, "Image data does not exists"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
251 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
252 | if(GetMode()!=Graphics::ColorMode::RGB && |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
253 | GetMode()!=Graphics::ColorMode::Grayscale) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
254 | throw std::runtime_error("Unsupported color mode"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
255 | |
1318
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
256 | if(data->GetSize().Cells() == 0) |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
257 | return false; |
6a0e5b41e6b3
* 0x0 bitmap does not cause ExportPNG to crash anymore
cemkalyoncu
parents:
1254
diff
changeset
|
258 | |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
259 | if(quality < 0 || quality > 100) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
260 | throw std::runtime_error("Unsupported quality"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
261 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
262 | Encoding::Jpg.Encode(*data, out, quality); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
263 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
264 | return true; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
265 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
266 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
267 | void Bitmap::StripRGB() { |
1142 | 268 | ASSERT(HasAlpha(), "Unsupported color mode"); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
269 | |
1142 | 270 | int alpha = GetAlphaIndex(); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
271 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
272 | auto &data = *this->data; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
273 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
274 | Containers::Image img(data.GetSize(), ColorMode::Alpha); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
275 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
276 | for(int y=0; y<data.GetHeight(); y++) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
277 | for(int x=0; x<data.GetWidth(); x++) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
278 | img(x, y, 0) = data(x, y, alpha); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
279 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
280 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
281 | |
1704 | 282 | Assume(std::move(img)); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
283 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
284 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
285 | void Bitmap::StripAlpha() { |
1142 | 286 | if(!HasAlpha()) return; |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
287 | |
1142 | 288 | int alpha = GetAlphaIndex(); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
289 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
290 | auto &data = *this->data; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
291 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
292 | Containers::Image img(data.GetSize(), (ColorMode)((int)GetMode()&~(int)ColorMode::Alpha)); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
293 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
294 | for(int y=0; y<data.GetHeight(); y++) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
295 | for(int x=0; x<data.GetWidth(); x++) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
296 | int cc = 0; |
1254
8030f7c9f1c3
* Containers image can now work with different datatypes for channels
cemkalyoncu
parents:
1251
diff
changeset
|
297 | for(int c=0; c<(int)data.GetChannelsPerPixel(); c++) { |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
298 | if(c!=alpha) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
299 | img(x, y, cc++) = data(x, y, c); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
300 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
301 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
302 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
303 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
304 | |
1704 | 305 | Assume(std::move(img)); |
972
40b12ffaea3e
* Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents:
932
diff
changeset
|
306 | } |
40b12ffaea3e
* Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents:
932
diff
changeset
|
307 | |
1204 | 308 | void Bitmap::Grayscale(float ratio, GrayscaleConversionMethod method) { |
309 | mode = GetMode(); | |
310 | ColorMode newmode = mode; | |
311 | bool alpha = HasAlpha(); | |
312 | ||
313 | if(ratio == 1) { | |
314 | if(mode == ColorMode::RGBA || mode == ColorMode::BGRA) { | |
315 | newmode = ColorMode::Grayscale_Alpha; | |
316 | } | |
317 | else if(mode == ColorMode::RGB || mode == ColorMode::BGR) { | |
318 | newmode = ColorMode::Grayscale; | |
1223 | 319 | } |
320 | else if(mode == ColorMode::Grayscale || mode == ColorMode::Grayscale_Alpha) { | |
321 | return; | |
322 | } | |
323 | else if(mode == ColorMode::Alpha) { | |
324 | this->data->ChangeMode(ColorMode::Grayscale); | |
325 | ||
326 | return; | |
327 | } | |
1204 | 328 | else |
329 | throw std::runtime_error("Unsupported color mode"); | |
330 | } | |
331 | ||
332 | ||
333 | auto &data = *this->data; | |
334 | Containers::Image img(data.GetSize(), newmode); | |
335 | ||
336 | std::function<RGBA(int, int)> getcolor; | |
337 | std::function<void(int, int, RGBA)> setcolor; | |
338 | std::function<Byte(RGBA)> convert; | |
339 | ||
340 | if(mode == ColorMode::RGB || mode == ColorMode::RGBA) { | |
341 | getcolor = [&data] (int x, int y) { | |
342 | return RGBA(data(x, y, 0), data(x, y, 1), data(x, y, 2)); | |
343 | }; | |
344 | setcolor = [&img] (int x, int y, RGBA color) { | |
345 | img(x, y, 0) = color.R; | |
346 | img(x, y, 1) = color.G; | |
347 | img(x, y, 2) = color.B; | |
348 | }; | |
349 | } | |
350 | else { | |
351 | getcolor = [&data] (int x, int y) { | |
352 | return RGBA(data(x, y, 2), data(x, y, 1), data(x, y, 0)); | |
353 | }; | |
354 | setcolor = [&img] (int x, int y, RGBA color) { | |
355 | img(x, y, 2) = color.R; | |
356 | img(x, y, 1) = color.G; | |
357 | img(x, y, 0) = color.B; | |
358 | }; | |
359 | } | |
360 | ||
361 | if(method == Luminance) { | |
362 | convert = [](RGBA color) { | |
363 | return color.Luminance(); | |
364 | }; | |
365 | } | |
366 | ||
367 | ||
368 | for(int y=0; y<data.GetHeight(); y++) { | |
369 | for(int x=0; x<data.GetWidth(); x++) { | |
370 | if(ratio == 1) { | |
371 | if(alpha) | |
372 | img(x, y, 1) = data(x, y, 3); | |
373 | ||
374 | img(x, y, 0) = convert(getcolor(x, y)); | |
375 | } | |
376 | else { | |
377 | if(alpha) | |
378 | img(x, y, 3) = data(x, y, 3); | |
379 | ||
380 | RGBA c = getcolor(x, y); | |
1251 | 381 | c.Blend(RGBA(convert(c), Byte(round(ratio*255)))); |
1204 | 382 | |
383 | setcolor(x, y, c); | |
384 | } | |
385 | } | |
386 | } | |
387 | ||
1704 | 388 | Assume(std::move(img)); |
1204 | 389 | } |
390 | ||
1010 | 391 | std::vector<Geometry::Bounds> Bitmap::CreateLinearAtlas(Containers::Collection<const Bitmap> list, AtlasMargin margins) { |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
392 | std::vector<Geometry::Bounds> ret; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
393 | std::map<const Bitmap *, Geometry::Bounds> mapping; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
394 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
395 | int N = list.GetSize(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
396 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
397 | if(N == 0) return ret; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
398 | if(N == 1) return {Geometry::Bounds(0, 0, list[0].GetSize())}; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
399 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
400 | int marginwidth = 0; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
401 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
402 | if(margins == Zero) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
403 | marginwidth = 1; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
404 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
405 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
406 | auto mode = list[0].GetMode(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
407 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
408 | int minw = list[0].GetWidth() + marginwidth; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
409 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
410 | std::vector<const Bitmap *> ordering; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
411 | for(auto &bmp : list) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
412 | ordering.push_back(&bmp); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
413 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
414 | if(minw > bmp.GetWidth() + marginwidth) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
415 | minw = bmp.GetWidth() + marginwidth; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
416 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
417 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
418 | //first height based, so the items with similar heights would be next to each other |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
419 | //second sort criteria is width as wider items should be packed at start. Items |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
420 | //are reverse sorted for performance |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
421 | list.Sort([](const Bitmap &l, const Bitmap &r) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
422 | if(l.GetHeight() == r.GetHeight()) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
423 | return l.GetWidth() < r.GetWidth(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
424 | else |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
425 | return l.GetHeight() > r.GetHeight(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
426 | }); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
427 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
428 | int totalw = std::accumulate(list.begin(), list.end(), 0, [margins](int l, const Bitmap &r) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
429 | return l + r.GetWidth() + (margins == Zero ? 1 : 0); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
430 | }); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
431 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
432 | int avgw = (int)std::ceil(float(totalw) / N); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
433 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
434 | // average line height would be skewed towards high |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
435 | int avgh = list[int(N*2/3)].GetHeight(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
436 | if(margins == Zero) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
437 | avgh += 1; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
438 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
439 | int lines = (int)std::round(std::sqrt(float(N)/avgh*avgw)); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
440 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
441 | int x = 0, y = 0, maxy = 0; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
442 | int w = (int)std::ceil((float)totalw/lines); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
443 | w += minw; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
444 | int maxx = 0; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
445 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
446 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
447 | if(margins == Zero) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
448 | x = marginwidth; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
449 | y = marginwidth; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
450 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
451 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
452 | //build positions |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
453 | for(int i=0; i<N; i++) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
454 | auto &bmp = *list.Last(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
455 | if(x + bmp.GetWidth() + marginwidth < w) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
456 | auto size = bmp.GetSize(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
457 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
458 | mapping[&bmp] = {x, y, size}; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
459 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
460 | x += size.Width + marginwidth; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
461 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
462 | if(size.Height > maxy) maxy = size.Height; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
463 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
464 | list.Remove(list.GetSize()-1); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
465 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
466 | else { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
467 | bool found = false; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
468 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
469 | if(w - x > minw) { //search to find a smaller image |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
470 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
471 | int maxw = w - x - 1 - marginwidth; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
472 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
473 | for(auto it = list.Last(); it.IsValid(); it.Previous()) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
474 | auto size = it->GetSize(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
475 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
476 | if(size.Width <= maxw) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
477 | mapping[it.CurrentPtr()] = {x, y, size}; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
478 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
479 | x += size.Width + marginwidth; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
480 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
481 | if(size.Height > maxy) maxy = size.Height; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
482 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
483 | it.Remove(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
484 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
485 | found = true; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
486 | break; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
487 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
488 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
489 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
490 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
491 | if(!found) { //too small |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
492 | y += maxy + marginwidth; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
493 | maxy = 0; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
494 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
495 | if(maxx < x) maxx = x; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
496 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
497 | if(margins == Zero) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
498 | x = 1; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
499 | else |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
500 | x = 0; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
501 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
502 | i--; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
503 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
504 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
505 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
506 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
507 | if(x) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
508 | y += maxy; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
509 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
510 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
511 | Resize({maxx, y + marginwidth}, mode); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
512 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
513 | if(margins == Zero) { |
1019
c72a1acd9bba
* Drag and drop system is now working, dragsource still needs testing
cemkalyoncu
parents:
1010
diff
changeset
|
514 | data->Clear(); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
515 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
516 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
517 | //channel count |
1254
8030f7c9f1c3
* Containers image can now work with different datatypes for channels
cemkalyoncu
parents:
1251
diff
changeset
|
518 | int C = GetChannelsPerPixel(); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
519 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
520 | for(auto p : mapping) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
521 | auto b = p.second; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
522 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
523 | if(p.first->GetMode() != mode) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
524 | throw std::runtime_error("Color modes are not uniform in atlas generation"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
525 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
526 | for(int y=0; y<b.Height(); y++) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
527 | for(int x=0; x<b.Width(); x++) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
528 | for(int c=0; c<C; c++) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
529 | (*data)(x+b.Left, y+b.Top, c) = (*p.first)(x, y, c); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
530 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
531 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
532 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
533 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
534 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
535 | ret.reserve(N); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
536 | for(int i=0; i<N; i++) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
537 | ret.push_back(mapping[ordering[i]]); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
538 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
539 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
540 | //ExportPNG("atlas.png"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
541 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
542 | return ret; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
543 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
544 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
545 | std::vector<TextureImage> Bitmap::CreateAtlasImages(std::vector<Geometry::Bounds> boundaries) const { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
546 | if(GetID() == 0) throw std::runtime_error("Cannot map atlas from an unprepared image"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
547 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
548 | std::vector<TextureImage> ret; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
549 | ret.reserve(boundaries.size()); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
550 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
551 | for(auto b : boundaries) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
552 | ret.emplace_back(GetID(), GetMode(), GetSize(), b); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
553 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
554 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
555 | return ret; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
556 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
557 | |
1010 | 558 | Geometry::Margin Bitmap::Trim(bool left, bool top, bool right, bool bottom) { |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
559 | ASSERT(data, "Image data does not exists"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
560 | |
1158 | 561 | auto ret = Trim({0, 0, GetSize()}, left, top, right, bottom); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
562 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
563 | auto &data = *this->data; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
564 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
565 | if(ret.TotalX() == 0 && ret.TotalY() == 0) return ret; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
566 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
567 | if(ret.TotalX() >= data.GetWidth() || ret.TotalY() >= data.GetHeight()) |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
568 | return ret; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
569 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
570 | Containers::Image img(data.GetSize() - ret.Total(), GetMode()); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
571 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
572 | int yy=0; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
573 | for(int y=ret.Top; y<data.GetHeight() - ret.Bottom; y++) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
574 | int xx=0; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
575 | for(int x=ret.Left; x<data.GetWidth() - ret.Right; x++) { |
1254
8030f7c9f1c3
* Containers image can now work with different datatypes for channels
cemkalyoncu
parents:
1251
diff
changeset
|
576 | for(int c=0; c<(int)data.GetChannelsPerPixel(); c++) { |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
577 | img(xx, yy, c) = data(x, y, c); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
578 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
579 | xx++; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
580 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
581 | yy++; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
582 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
583 | |
1704 | 584 | Assume(std::move(img)); |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
585 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
586 | return ret; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
587 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
588 | |
1158 | 589 | Geometry::Margin Bitmap::Trim(Geometry::Bounds bounds, bool left, bool top, bool right, bool bottom) { |
590 | ASSERT(data, "Image data does not exists"); | |
591 | ||
592 | Geometry::Margin ret(0, 0, 0, 0); | |
593 | ||
594 | if(!HasAlpha()) | |
595 | return ret; | |
596 | ||
597 | int alpha = GetAlphaIndex(); | |
598 | ||
599 | auto &data = *this->data; | |
600 | ||
601 | if(left) { | |
602 | for(int x=bounds.Left; x<bounds.Right; x++) { | |
603 | bool empty = true; | |
604 | ||
605 | for(int y=bounds.Top; y<bounds.Bottom; y++) { | |
606 | if(data(x, y, alpha) != 0) { | |
607 | empty = false; | |
608 | break; | |
609 | } | |
610 | } | |
611 | ||
612 | if(empty) { | |
613 | ret.Left++; | |
614 | } | |
615 | else { | |
616 | break; | |
617 | } | |
618 | } | |
619 | } | |
620 | ||
621 | if(top) { | |
622 | for(int y=bounds.Top; y<bounds.Bottom; y++) { | |
623 | bool empty = true; | |
624 | ||
625 | for(int x=bounds.Left; x<bounds.Right; x++) { | |
626 | if(data(x, y, alpha) != 0) { | |
627 | empty = false; | |
628 | break; | |
629 | } | |
630 | } | |
631 | ||
632 | if(empty) { | |
633 | ret.Top++; | |
634 | } | |
635 | else { | |
636 | break; | |
637 | } | |
638 | } | |
639 | } | |
640 | ||
641 | if(right) { | |
642 | for(int x=bounds.Right-1; x>=bounds.Left; x--) { | |
643 | bool empty = true; | |
644 | ||
645 | for(int y=bounds.Top; y<bounds.Bottom; y++) { | |
646 | if(data(x, y, alpha) != 0) { | |
647 | empty = false; | |
648 | break; | |
649 | } | |
650 | } | |
651 | ||
652 | if(empty) { | |
653 | ret.Right++; | |
654 | } | |
655 | else { | |
656 | break; | |
657 | } | |
658 | } | |
659 | } | |
660 | ||
661 | if(bottom) { | |
662 | for(int y=bounds.Bottom-1; y>=bounds.Top; y--) { | |
663 | bool empty = true; | |
664 | ||
665 | for(int x=bounds.Left; x<bounds.Right; x++) { | |
666 | if(data(x, y, alpha) != 0) { | |
667 | empty = false; | |
668 | break; | |
669 | } | |
670 | } | |
671 | ||
672 | if(empty) { | |
673 | ret.Bottom++; | |
674 | } | |
675 | else { | |
676 | break; | |
677 | } | |
678 | } | |
679 | } | |
680 | ||
681 | return ret; | |
682 | } | |
683 | ||
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
684 | Containers::Image Bitmap::ReleaseData() { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
685 | if(data==nullptr) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
686 | #ifndef NDEBUG |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
687 | ASSERT_DUMP(false, "No data to release"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
688 | #endif |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
689 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
690 | return { }; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
691 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
692 | else { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
693 | Containers::Image temp=std::move(*data); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
694 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
695 | delete data; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
696 | data=nullptr; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
697 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
698 | return temp; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
699 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
700 | } |
1158 | 701 | |
702 | bool Bitmap::IsEmpty(Geometry::Bounds bounds) const { | |
703 | if(bounds.GetSize().Area() == 0) | |
704 | return true; | |
705 | ||
706 | if(!HasAlpha()) | |
707 | return false; | |
708 | ||
709 | int alpha = GetAlphaIndex(); | |
710 | ||
711 | auto &data = *this->data; | |
712 | ||
713 | for(int y=bounds.Top; y<bounds.Bottom; y++) { | |
714 | for(int x=bounds.Left; x<bounds.Right; x++) { | |
715 | if(data(x, y, alpha) > 0) | |
716 | return false; | |
717 | } | |
718 | } | |
719 | ||
720 | return true; | |
721 | } | |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
722 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
723 | Graphics::Bitmap Bitmap::Rotate90() const { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
724 | ASSERT(data, "Bitmap data is not set"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
725 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
726 | Graphics::Bitmap target(GetHeight(), GetWidth(), GetMode()); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
727 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
728 | int h = target.GetHeight(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
729 | ForAllPixels([&](int x, int y, int c) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
730 | target(y, h - x - 1, c) = (*this)(x, y, c); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
731 | }); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
732 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
733 | return target; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
734 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
735 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
736 | Graphics::Bitmap Bitmap::Rotate180() const { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
737 | ASSERT(data, "Bitmap data is not set"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
738 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
739 | Graphics::Bitmap target(GetSize(), GetMode()); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
740 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
741 | int h = target.GetHeight(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
742 | int w = target.GetWidth(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
743 | ForAllPixels([&](int x, int y, int c) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
744 | target(w - x - 1, h - y - 1, c) = (*this)(x, y, c); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
745 | }); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
746 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
747 | return target; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
748 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
749 | |
1211 | 750 | Graphics::Bitmap Bitmap::Rotate270() const { |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
751 | ASSERT(data, "Bitmap data is not set"); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
752 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
753 | Graphics::Bitmap target(GetHeight(), GetWidth(), GetMode()); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
754 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
755 | int w = target.GetWidth(); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
756 | ForAllPixels([&](int x, int y, int c) { |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
757 | target(w - y - 1, x, c) = (*this)(x, y, c); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
758 | }); |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
759 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
760 | return target; |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
761 | } |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
762 | |
1211 | 763 | Graphics::Bitmap Bitmap::ZoomMultiple(int factor) const { |
764 | ASSERT(data, "Bitmap data is not set"); | |
765 | ||
766 | if(factor <= 0) | |
767 | throw std::runtime_error("Zoom factor is invalid."); | |
768 | ||
1217 | 769 | Graphics::Bitmap target(GetWidth() * factor, GetHeight() * factor, GetMode()); |
1211 | 770 | |
771 | target.ForAllPixels([&](int x, int y, int c) { | |
772 | target(x, y, c) = (*data)(x / factor, y / factor, c); | |
773 | }); | |
774 | ||
775 | return target; | |
776 | } | |
1004
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
777 | |
b6b47ba90e06
* MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents:
986
diff
changeset
|
778 | } } |