diff --git a/.gitignore b/.gitignore index 038a38f..f8a2c05 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,6 @@ mcpppp-log.txt desktop.ini mcpppp-temp/ -x64-Debug/ \ No newline at end of file +x64-Debug/ +/x64/Debug +/bumpversion.exe diff --git a/Source.cpp b/Source.cpp index 07ca0a0..470052b 100644 --- a/Source.cpp +++ b/Source.cpp @@ -4,7 +4,7 @@ //#define GUI -constexpr auto VERSION = "0.5.5"; // MCPPPP version +constexpr auto VERSION = "0.5.6"; // MCPPPP version #ifdef _WIN32 #define NOMINMAX diff --git a/fsb.h b/fsb.h index cdc53b1..ea5280f 100644 --- a/fsb.h +++ b/fsb.h @@ -113,34 +113,42 @@ class fsb // convert black to transparent static void convert(std::vector& image, const unsigned int& w, const unsigned int& h) { - for (long long i = 0; i < (w * 4) / 3; i += 4) + for (long long i = 0; i < w; i += 4) { - for (long long j = 0; j < h / 2; j++) + for (long long j = 0; j < h; j++) { // if completely opaque - if (image.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i + 3)) == 255) + if (image.at(static_cast(w * h - (j + 1) * w + i + 3)) == 255) { - double first = image.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i)); - double second = image.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i + 1)); - double third = image.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i + 2)); + double first = image.at(static_cast(w * h - (j + 1) * w + i)); + double second = image.at(static_cast(w * h - (j + 1) * w + i + 1)); + double third = image.at(static_cast(w * h - (j + 1) * w + i + 2)); rgb2hsv(first, second, third); const double alpha = third * 51 / 20; // convert 0-100 to 0-255 third = 100; hsv2rgb(first, second, third); - image.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i)) = static_cast(first); - image.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i + 1)) = static_cast(second); - image.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i + 2)) = static_cast(third); - image.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i + 3)) = static_cast(alpha); + image.at(static_cast(w * h - (j + 1) * w + i)) = static_cast(first); + image.at(static_cast(w * h - (j + 1) * w + i + 1)) = static_cast(second); + image.at(static_cast(w * h - (j + 1) * w + i + 2)) = static_cast(third); + image.at(static_cast(w * h - (j + 1) * w + i + 3)) = static_cast(alpha); } } } } + static constexpr void checkError(const unsigned int& i) + { + if (i) + { + out(5) << "FSB: png error: " << lodepng_error_text(i) << std::endl; + } + } + // convert optifine image format (1 image for all 6 sides) into fsb image format (1 image per side) static void fsbpng(const std::string& path, const std::string& output, const std::filesystem::directory_entry& png) { out(1) << "FSB: Converting " + png.path().filename().u8string() << std::endl; - unsigned int w, h, error; + unsigned int w, h; std::vector buffer, image, image1, image2, image3, top; // before h/2: bottom (rotate 90 counterclockwise), top (rotate 90 clockwise), south; h/2 to h: west, north, east // rotation: w*h - w + 1, w*h - 2*w + 1, ..., w*h - h*w + 1, w*h - w + 2, w*h - 2*w + 2, ..., w*h - w + w, w*h - 2*w + w, ... std::string filename = png.path().filename().u8string(); @@ -148,145 +156,89 @@ class fsb state.info_raw.colortype = LCT_RGBA; state.info_raw.bitdepth = 8; filename.erase(filename.end() - 4, filename.end()); - error = lodepng::load_file(buffer, png.path().u8string()); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } - error = lodepng::decode(image, w, h, state, buffer); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } + checkError(lodepng::load_file(buffer, png.path().u8string())); + checkError(lodepng::decode(image, w, h, state, buffer)); if (w % 3 != 0 || h % 2 != 0) { - out(5) << "FSB: Wrong dimensions: " << png.path().u8string() << std::endl; - return; + out(4) << "FSB: Wrong dimensions: " << png.path().u8string() << std::endl << "will be cropped to proper dimensions" << std::endl; } image1.reserve(buffer.size() / 6); image2.reserve(buffer.size() / 6); image3.reserve(buffer.size() / 6); - for (size_t i = 0; i < (w * 4) * h / 2; i++) + const unsigned int outw = w / 3 * 4; + const unsigned int outh = h / 2; + for (size_t i = 0; i < (w * 4) * outh; i++) { - if (i % (w * 4) < (w * 4) / 3) + if (i % (w * 4) < outw) { image1.push_back(image.at(i)); } - else if (i % (w * 4) < 2 * (w * 4) / 3) + else if (i % (w * 4) < 2 * outw) { image2.push_back(image.at(i)); } - else + else if (i % (w * 4) < 3 * outw) { image3.push_back(image.at(i)); } } - convert(image1, w, h); - convert(image2, w, h); - convert(image3, w, h); + convert(image1, outw, outh); + convert(image2, outw, outh); + convert(image3, outw, outh); top.reserve(image.size() / 6); - for (long long i = 0; i < (w * 4) / 3; i += 4) + for (long long i = 0; i < outw; i += 4) { - for (long long j = 0; j < h / 2; j++) + for (long long j = 0; j < outh; j++) { - top.push_back(image2.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i))); - top.push_back(image2.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i + 1))); - top.push_back(image2.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i + 2))); - top.push_back(image2.at(static_cast((w * 4) / 3 * h / 2 - (j + 1) * (w * 4) / 3 + i + 3))); + top.push_back(image2.at(static_cast(outw * outh - (j + 1) * outw + i))); + top.push_back(image2.at(static_cast(outw * outh - (j + 1) * outw + i + 1))); + top.push_back(image2.at(static_cast(outw * outh - (j + 1) * outw + i + 2))); + top.push_back(image2.at(static_cast(outw * outh - (j + 1) * outw + i + 3))); } } buffer.clear(); std::filesystem::create_directories(std::filesystem::u8path(path + output)); - error = lodepng::encode(buffer, image1, w / 3, h / 2, state); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } - error = lodepng::save_file(buffer, path + output + filename + "_bottom.png"); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } + checkError(lodepng::encode(buffer, image1, outw / 4, outh, state)); + checkError(lodepng::save_file(buffer, path + output + filename + "_bottom.png")); buffer.clear(); - error = lodepng::encode(buffer, top, h / 2, w / 3, state); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } - error = lodepng::save_file(buffer, path + output + filename + "_top.png"); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } + checkError(lodepng::encode(buffer, top, outh, outw / 4, state)); + checkError(lodepng::save_file(buffer, path + output + filename + "_top.png")); buffer.clear(); - error = lodepng::encode(buffer, image3, w / 3, h / 2, state); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } - error = lodepng::save_file(buffer, path + output + filename + "_south.png"); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } + checkError(lodepng::encode(buffer, image3, outw / 4, outh, state)); + checkError(lodepng::save_file(buffer, path + output + filename + "_south.png")); image1.clear(); image2.clear(); image3.clear(); - for (size_t i = (w * 4) * h / 2; i < (w * 4) * h; i++) + for (size_t i = (w * 4) * outh; i < (w * 4) * 2 * outh; i++) { - if (i % (w * 4) < (w * 4) / 3) + if (i % (w * 4) < outw) { image1.push_back(image.at(i)); } - else if (i % (w * 4) < 2 * (w * 4) / 3) + else if (i % (w * 4) < 2 * outw) { image2.push_back(image.at(i)); } - else + else if(i % (w * 4) < 3 * outw) { image3.push_back(image.at(i)); } } - convert(image1, w, h); - convert(image2, w, h); - convert(image3, w, h); - + convert(image1, outw, outh); + convert(image2, outw, outh); + convert(image3, outw, outh); buffer.clear(); - error = lodepng::encode(buffer, image1, w / 3, h / 2, state); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } - error = lodepng::save_file(buffer, path + output + filename + "_west.png"); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } + checkError(lodepng::encode(buffer, image1, outw / 4, outh, state)); + checkError(lodepng::save_file(buffer, path + output + filename + "_west.png")); buffer.clear(); - error = lodepng::encode(buffer, image2, w / 3, h / 2, state); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } - error = lodepng::save_file(buffer, path + output + filename + "_north.png"); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } + checkError(lodepng::encode(buffer, image2, outw / 4, outh, state)); + checkError(lodepng::save_file(buffer, path + output + filename + "_north.png")); buffer.clear(); - error = lodepng::encode(buffer, image3, w / 3, h / 2, state); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } - error = lodepng::save_file(buffer, path + output + filename + "_east.png"); - if (error != 0) - { - out(5) << "FSB: png error: " << lodepng_error_text(error) << std::endl; - } + checkError(lodepng::encode(buffer, image3, outw / 4, outh, state)); + checkError(lodepng::save_file(buffer, path + output + filename + "_east.png")); } // convert optifine properties files into fsb properties json diff --git a/gradle.properties b/gradle.properties index 6752991..7f8a986 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.11.6 # Mod Properties - mod_version = 0.5.5 + mod_version = 0.5.6 archives_base_name = mcpppp maven_group = com.example