Source/Gorgon/Graphics/Bitmap.cpp

Thu, 08 Jul 2021 09:15:25 +0300

author
cemkalyoncu
date
Thu, 08 Jul 2021 09:15:25 +0300
branch
4.x-dev
changeset 1704
a0fdf33ceefe
parent 1695
accb75196605
permissions
-rw-r--r--

* 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
32c50698f078 * A wave export bug is found and fixed
cemkalyoncu
parents: 1517
diff changeset
21 delete data;
32c50698f078 * A wave export bug is found and fixed
cemkalyoncu
parents: 1517
diff changeset
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
32c50698f078 * A wave export bug is found and fixed
cemkalyoncu
parents: 1517
diff changeset
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
32c50698f078 * A wave export bug is found and fixed
cemkalyoncu
parents: 1517
diff changeset
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
accb75196605 * Icon label bg & spacing fix
cemkalyoncu
parents: 1576
diff changeset
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
accb75196605 * Icon label bg & spacing fix
cemkalyoncu
parents: 1576
diff changeset
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
accb75196605 * Icon label bg & spacing fix
cemkalyoncu
parents: 1576
diff changeset
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
accb75196605 * Icon label bg & spacing fix
cemkalyoncu
parents: 1576
diff changeset
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
accb75196605 * Icon label bg & spacing fix
cemkalyoncu
parents: 1576
diff changeset
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
accb75196605 * Icon label bg & spacing fix
cemkalyoncu
parents: 1576
diff changeset
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
accb75196605 * Icon label bg & spacing fix
cemkalyoncu
parents: 1576
diff changeset
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
96e2582cca52 * Auto kerning support for bitmap fonts
cemkalyoncu
parents: 1124
diff changeset
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
96e2582cca52 * Auto kerning support for bitmap fonts
cemkalyoncu
parents: 1124
diff changeset
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
a0fdf33ceefe * Bitmap bug fixed
cemkalyoncu
parents: 1695
diff changeset
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
96e2582cca52 * Auto kerning support for bitmap fonts
cemkalyoncu
parents: 1124
diff changeset
286 if(!HasAlpha()) return;
1004
b6b47ba90e06 * MaskedObject now can work with different animation types, not perfect,
cemkalyoncu
parents: 986
diff changeset
287
1142
96e2582cca52 * Auto kerning support for bitmap fonts
cemkalyoncu
parents: 1124
diff changeset
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
a0fdf33ceefe * Bitmap bug fixed
cemkalyoncu
parents: 1695
diff changeset
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
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
308 void Bitmap::Grayscale(float ratio, GrayscaleConversionMethod method) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
309 mode = GetMode();
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
310 ColorMode newmode = mode;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
311 bool alpha = HasAlpha();
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
312
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
313 if(ratio == 1) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
314 if(mode == ColorMode::RGBA || mode == ColorMode::BGRA) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
315 newmode = ColorMode::Grayscale_Alpha;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
316 }
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
317 else if(mode == ColorMode::RGB || mode == ColorMode::BGR) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
318 newmode = ColorMode::Grayscale;
1223
c2760fd2d427 * Missing template parameter
cemkalyoncu
parents: 1217
diff changeset
319 }
c2760fd2d427 * Missing template parameter
cemkalyoncu
parents: 1217
diff changeset
320 else if(mode == ColorMode::Grayscale || mode == ColorMode::Grayscale_Alpha) {
c2760fd2d427 * Missing template parameter
cemkalyoncu
parents: 1217
diff changeset
321 return;
c2760fd2d427 * Missing template parameter
cemkalyoncu
parents: 1217
diff changeset
322 }
c2760fd2d427 * Missing template parameter
cemkalyoncu
parents: 1217
diff changeset
323 else if(mode == ColorMode::Alpha) {
c2760fd2d427 * Missing template parameter
cemkalyoncu
parents: 1217
diff changeset
324 this->data->ChangeMode(ColorMode::Grayscale);
c2760fd2d427 * Missing template parameter
cemkalyoncu
parents: 1217
diff changeset
325
c2760fd2d427 * Missing template parameter
cemkalyoncu
parents: 1217
diff changeset
326 return;
c2760fd2d427 * Missing template parameter
cemkalyoncu
parents: 1217
diff changeset
327 }
1204
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
328 else
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
329 throw std::runtime_error("Unsupported color mode");
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
330 }
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
331
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
332
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
333 auto &data = *this->data;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
334 Containers::Image img(data.GetSize(), newmode);
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
335
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
336 std::function<RGBA(int, int)> getcolor;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
337 std::function<void(int, int, RGBA)> setcolor;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
338 std::function<Byte(RGBA)> convert;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
339
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
340 if(mode == ColorMode::RGB || mode == ColorMode::RGBA) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
341 getcolor = [&data] (int x, int y) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
342 return RGBA(data(x, y, 0), data(x, y, 1), data(x, y, 2));
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
343 };
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
344 setcolor = [&img] (int x, int y, RGBA color) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
345 img(x, y, 0) = color.R;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
346 img(x, y, 1) = color.G;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
347 img(x, y, 2) = color.B;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
348 };
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
349 }
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
350 else {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
351 getcolor = [&data] (int x, int y) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
352 return RGBA(data(x, y, 2), data(x, y, 1), data(x, y, 0));
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
353 };
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
354 setcolor = [&img] (int x, int y, RGBA color) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
355 img(x, y, 2) = color.R;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
356 img(x, y, 1) = color.G;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
357 img(x, y, 0) = color.B;
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
358 };
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
359 }
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
360
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
361 if(method == Luminance) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
362 convert = [](RGBA color) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
363 return color.Luminance();
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
364 };
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
365 }
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
366
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
367
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
368 for(int y=0; y<data.GetHeight(); y++) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
369 for(int x=0; x<data.GetWidth(); x++) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
370 if(ratio == 1) {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
371 if(alpha)
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
372 img(x, y, 1) = data(x, y, 3);
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
373
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
374 img(x, y, 0) = convert(getcolor(x, y));
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
375 }
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
376 else {
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
377 if(alpha)
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
378 img(x, y, 3) = data(x, y, 3);
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
379
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
380 RGBA c = getcolor(x, y);
1251
b0655bf8d5c7 * Automatic UI generation framework
cemkalyoncu
parents: 1223
diff changeset
381 c.Blend(RGBA(convert(c), Byte(round(ratio*255))));
1204
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
382
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
383 setcolor(x, y, c);
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
384 }
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
385 }
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
386 }
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
387
1704
a0fdf33ceefe * Bitmap bug fixed
cemkalyoncu
parents: 1695
diff changeset
388 Assume(std::move(img));
1204
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
389 }
3be959ecb7a2 * Color bitmap to grayscale conversion
cemkalyoncu
parents: 1158
diff changeset
390
1010
267a3b0a3005 * Initial design on UI components
cemkalyoncu
parents: 1004
diff changeset
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
267a3b0a3005 * Initial design on UI components
cemkalyoncu
parents: 1004
diff changeset
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
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
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
a0fdf33ceefe * Bitmap bug fixed
cemkalyoncu
parents: 1695
diff changeset
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
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
589 Geometry::Margin Bitmap::Trim(Geometry::Bounds bounds, bool left, bool top, bool right, bool bottom) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
590 ASSERT(data, "Image data does not exists");
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
591
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
592 Geometry::Margin ret(0, 0, 0, 0);
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
593
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
594 if(!HasAlpha())
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
595 return ret;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
596
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
597 int alpha = GetAlphaIndex();
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
598
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
599 auto &data = *this->data;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
600
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
601 if(left) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
602 for(int x=bounds.Left; x<bounds.Right; x++) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
603 bool empty = true;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
604
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
605 for(int y=bounds.Top; y<bounds.Bottom; y++) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
606 if(data(x, y, alpha) != 0) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
607 empty = false;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
608 break;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
609 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
610 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
611
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
612 if(empty) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
613 ret.Left++;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
614 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
615 else {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
616 break;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
617 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
618 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
619 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
620
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
621 if(top) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
622 for(int y=bounds.Top; y<bounds.Bottom; y++) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
623 bool empty = true;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
624
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
625 for(int x=bounds.Left; x<bounds.Right; x++) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
626 if(data(x, y, alpha) != 0) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
627 empty = false;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
628 break;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
629 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
630 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
631
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
632 if(empty) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
633 ret.Top++;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
634 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
635 else {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
636 break;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
637 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
638 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
639 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
640
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
641 if(right) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
642 for(int x=bounds.Right-1; x>=bounds.Left; x--) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
643 bool empty = true;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
644
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
645 for(int y=bounds.Top; y<bounds.Bottom; y++) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
646 if(data(x, y, alpha) != 0) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
647 empty = false;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
648 break;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
649 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
650 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
651
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
652 if(empty) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
653 ret.Right++;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
654 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
655 else {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
656 break;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
657 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
658 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
659 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
660
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
661 if(bottom) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
662 for(int y=bounds.Bottom-1; y>=bounds.Top; y--) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
663 bool empty = true;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
664
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
665 for(int x=bounds.Left; x<bounds.Right; x++) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
666 if(data(x, y, alpha) != 0) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
667 empty = false;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
668 break;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
669 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
670 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
671
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
672 if(empty) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
673 ret.Bottom++;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
674 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
675 else {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
676 break;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
677 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
678 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
679 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
680
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
681 return ret;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
682 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
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
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
701
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
702 bool Bitmap::IsEmpty(Geometry::Bounds bounds) const {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
703 if(bounds.GetSize().Area() == 0)
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
704 return true;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
705
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
706 if(!HasAlpha())
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
707 return false;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
708
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
709 int alpha = GetAlphaIndex();
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
710
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
711 auto &data = *this->data;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
712
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
713 for(int y=bounds.Top; y<bounds.Bottom; y++) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
714 for(int x=bounds.Left; x<bounds.Right; x++) {
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
715 if(data(x, y, alpha) > 0)
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
716 return false;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
717 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
718 }
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
719
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
720 return true;
952f9cebfc6e * Importing fixed grid font atlases
cemkalyoncu
parents: 1142
diff changeset
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
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
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
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
763 Graphics::Bitmap Bitmap::ZoomMultiple(int factor) const {
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
764 ASSERT(data, "Bitmap data is not set");
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
765
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
766 if(factor <= 0)
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
767 throw std::runtime_error("Zoom factor is invalid.");
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
768
1217
258ef03f3cc9 * Bug fixes:
cemkalyoncu
parents: 1211
diff changeset
769 Graphics::Bitmap target(GetWidth() * factor, GetHeight() * factor, GetMode());
1211
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
770
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
771 target.ForAllPixels([&](int x, int y, int c) {
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
772 target(x, y, c) = (*data)(x / factor, y / factor, c);
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
773 });
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
774
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
775 return target;
e459d58f6dc6 * CGI framework
cemkalyoncu
parents: 1204
diff changeset
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 } }

mercurial