back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/img_handler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'img_handler.cpp')
-rw-r--r--img_handler.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/img_handler.cpp b/img_handler.cpp
index 921f639..6c62728 100644
--- a/img_handler.cpp
+++ b/img_handler.cpp
@@ -1,3 +1,8 @@
+/*
+ * Processing of images uploaded by the user
+ * (resizing, cropping, saving)
+ */
+
#include "img_handler.hpp"
#include "puzzle.hpp"
@@ -14,7 +19,7 @@
#include <iostream>
#include <string>
-ImageHandler::ImageHandler(const char *p) : path_to_file(p) {
+ImageHandler::ImageHandler(const char *p) : source_path(p) {
img_data = nullptr;
resized_data = nullptr;
/*
@@ -25,24 +30,24 @@ ImageHandler::ImageHandler(const char *p) : path_to_file(p) {
std::filesystem::create_directory(res_path);
#if defined(_WIN32)
- auto it = path_to_file.find_last_of('\\');
+ auto it = source_path.find_last_of('\\');
#else
- auto it = path_to_file.find_last_of('/');
+ auto it = source_path.find_last_of('/');
#endif
- std::string file_name = path_to_file.substr(it + 1);
+ std::string file_name = source_path.substr(it + 1);
std::string fn_withot_ext =
file_name.substr(0, file_name.find_first_of('.'));
#if defined(_WIN32)
- path_to_save = "resources\\" + fn_withot_ext + "\\";
+ destination_directory = "resources\\" + fn_withot_ext + "\\";
#else
- path_to_save = "resources/" + fn_withot_ext + '/';
+ destination_directory = "resources/" + fn_withot_ext + '/';
#endif
- std::filesystem::create_directory(path_to_save);
+ std::filesystem::create_directory(destination_directory);
}
void ImageHandler::load_img()
{
- img_data = stbi_load(path_to_file.c_str(), &in_width, &in_height,
+ img_data = stbi_load(source_path.c_str(), &in_width, &in_height,
&channel, 0);
}
@@ -62,11 +67,11 @@ void ImageHandler::save_img()
for(j = 0; j < puzzles_per_side; ++j, ++k) {
x = i * puzzle_size;
y = j * puzzle_size;
- std::string tmp_name =
- path_to_save +
+ std::string tmp_path =
+ destination_directory +
std::to_string(k / puzzles_per_side) +
std::to_string(k % puzzles_per_side) + ".png";
- stbi_write_png(tmp_name.c_str(), puzzle_size, puzzle_size, channel,
+ stbi_write_png(tmp_path.c_str(), puzzle_size, puzzle_size, channel,
resized_data + channel * (x + y * width),
width * channel);
}