#3175 - Fixed compatibility with boost v 1.71

This commit is contained in:
Enrico Turri 2019-11-11 11:21:08 +01:00
parent 49175c3112
commit 621b8426d3
2 changed files with 23 additions and 12 deletions

View file

@ -961,7 +961,7 @@ void GCode::_do_export(Print &print, FILE *file)
// Write thumbnails using base64 encoding // Write thumbnails using base64 encoding
if (thumbnail_data != nullptr) if (thumbnail_data != nullptr)
{ {
const unsigned int max_row_length = 78; const size_t max_row_length = 78;
for (const ThumbnailData& data : *thumbnail_data) for (const ThumbnailData& data : *thumbnail_data)
{ {
@ -972,19 +972,21 @@ void GCode::_do_export(Print &print, FILE *file)
void* png_data = tdefl_write_image_to_png_file_in_memory_ex((const void*)data.pixels.data(), data.width, data.height, 4, &png_size, MZ_DEFAULT_LEVEL, 1); void* png_data = tdefl_write_image_to_png_file_in_memory_ex((const void*)data.pixels.data(), data.width, data.height, 4, &png_size, MZ_DEFAULT_LEVEL, 1);
if (png_data != nullptr) if (png_data != nullptr)
{ {
_write_format(file, "\n;\n; thumbnail begin %dx%d\n", data.width, data.height); std::string encoded;
encoded.resize(boost::beast::detail::base64::encoded_size(png_size));
encoded.resize(boost::beast::detail::base64::encode((void*)&encoded[0], (const void*)png_data, png_size));
std::string encoded = boost::beast::detail::base64_encode((const std::uint8_t*)png_data, png_size); _write_format(file, "\n;\n; thumbnail begin %dx%d %d\n", data.width, data.height, encoded.size());
unsigned int row_count = 0; unsigned int row_count = 0;
while (encoded.length() > max_row_length) while (encoded.size() > max_row_length)
{ {
_write_format(file, "; %s\n", encoded.substr(0, max_row_length).c_str()); _write_format(file, "; %s\n", encoded.substr(0, max_row_length).c_str());
encoded = encoded.substr(max_row_length); encoded = encoded.substr(max_row_length);
++row_count; ++row_count;
} }
if (encoded.length() > 0) if (encoded.size() > 0)
_write_format(file, "; %s\n", encoded.c_str()); _write_format(file, "; %s\n", encoded.c_str());
_write(file, "; thumbnail end\n;\n"); _write(file, "; thumbnail end\n;\n");
@ -997,9 +999,12 @@ void GCode::_do_export(Print &print, FILE *file)
size_t row_size = 4 * data.width; size_t row_size = 4 * data.width;
for (int r = (int)data.height - 1; r >= 0; --r) for (int r = (int)data.height - 1; r >= 0; --r)
{ {
std::string encoded = boost::beast::detail::base64_encode((const std::uint8_t*)(data.pixels.data() + r * row_size), row_size); std::string encoded;
encoded.resize(boost::beast::detail::base64::encoded_size(row_size));
encoded.resize(boost::beast::detail::base64::encode((void*)&encoded[0], (const void*)(data.pixels.data() + r * row_size), row_size));
unsigned int row_count = 0; unsigned int row_count = 0;
while (encoded.length() > max_row_length) while (encoded.size() > max_row_length)
{ {
if (row_count == 0) if (row_count == 0)
_write_format(file, "; %s\n", encoded.substr(0, max_row_length).c_str()); _write_format(file, "; %s\n", encoded.substr(0, max_row_length).c_str());
@ -1010,7 +1015,7 @@ void GCode::_do_export(Print &print, FILE *file)
++row_count; ++row_count;
} }
if (encoded.length() > 0) if (encoded.size() > 0)
{ {
if (row_count == 0) if (row_count == 0)
_write_format(file, "; %s\n", encoded.c_str()); _write_format(file, "; %s\n", encoded.c_str());

View file

@ -1131,8 +1131,11 @@ void GUI_App::gcode_thumbnails_debug()
boost::nowide::ofstream out_file(out_filename.c_str(), std::ios::binary); boost::nowide::ofstream out_file(out_filename.c_str(), std::ios::binary);
if (out_file.good()) if (out_file.good())
{ {
std::string decoded = boost::beast::detail::base64_decode(row); std::string decoded;
out_file.write(decoded.c_str(), decoded.length()); decoded.resize(boost::beast::detail::base64::decoded_size(row.size()));
decoded.resize(boost::beast::detail::base64::decode((void*)&decoded[0], row.data(), row.size()).first);
out_file.write(decoded.c_str(), decoded.size());
out_file.close(); out_file.close();
} }
#else #else
@ -1147,8 +1150,11 @@ void GUI_App::gcode_thumbnails_debug()
std::vector<unsigned char> thumbnail(4 * width * height, 0); std::vector<unsigned char> thumbnail(4 * width * height, 0);
for (unsigned int r = 0; r < (unsigned int)rows.size(); ++r) for (unsigned int r = 0; r < (unsigned int)rows.size(); ++r)
{ {
std::string decoded_row = boost::beast::detail::base64_decode(rows[r]); std::string decoded_row;
if ((unsigned int)decoded_row.length() == width * 4) decoded_row.resize(boost::beast::detail::base64::decoded_size(rows[r].size()));
decoded_row.resize(boost::beast::detail::base64::decode((void*)&decoded_row[0], rows[r].data(), rows[r].size()).first);
if ((unsigned int)decoded_row.size() == width * 4)
{ {
void* image_ptr = (void*)(thumbnail.data() + r * width * 4); void* image_ptr = (void*)(thumbnail.data() + r * width * 4);
::memcpy(image_ptr, (const void*)decoded_row.c_str(), width * 4); ::memcpy(image_ptr, (const void*)decoded_row.c_str(), width * 4);