-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
46 lines (41 loc) · 1.71 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <Windows.h>
#include "images2onefile.h"
std::string get_current_path() {
char buffer[MAX_PATH];
GetModuleFileNameA(NULL, buffer, MAX_PATH);
std::string::size_type pos = std::string(buffer).find_last_of("\\/");
return std::string(buffer).substr(0, pos);
}
int main(int argc, const char* argv[]) {
/* target image paths here */
std::vector<std::string> img_paths = {
"image1.png",
"image2.jpg"
};
/* target data file path here */
std::string target_path = get_current_path() + "\\output.data";
// compress images to one file
std::vector<ImageData> input_images;
for (const auto& path : img_paths) {
ImageData img;
if (load_image(get_current_path() + "\\" + path, path.c_str(), img)) input_images.push_back(img);
else std::cout << "failed to load image : " << path << "\n";
}
if (!compress_images(input_images, target_path)) {
std::cout << "failed to compress images" << "\n";
}
// decompress images from one file
std::vector<ImageData> output_images;
if (decompress_images(target_path, output_images) == false)
std::cerr << "failed to decompress images" << "\n";
// re-write the image files (only supports .png and .jpg)
for (size_t i = 0; i < output_images.size(); ++i) {
const auto& img = output_images[i];
std::string new_output_path = get_current_path() + "\\" + img.name;
if (img.channels == 3) {
stbi_write_jpg(new_output_path.c_str(), img.width, img.height, img.channels, img.data.data(), 100);
continue;
}
stbi_write_png(new_output_path.c_str(), img.width, img.height, img.channels, img.data.data(), img.width * img.channels);
}
}