ENABLE_THUMBNAIL_GENERATOR -> Export thumbnails to gcode: max length of gcode lines set to 80 characters
This commit is contained in:
parent
3d450df680
commit
64d5ac0d20
@ -957,6 +957,8 @@ void GCode::_do_export(Print &print, FILE *file)
|
||||
// Write thumbnails using base64 encoding
|
||||
if (thumbnail_data != nullptr)
|
||||
{
|
||||
const unsigned int max_row_length = 78;
|
||||
|
||||
for (const ThumbnailData& data : *thumbnail_data)
|
||||
{
|
||||
if (data.is_valid())
|
||||
@ -966,10 +968,26 @@ void GCode::_do_export(Print &print, FILE *file)
|
||||
size_t row_size = 4 * data.width;
|
||||
for (int r = (int)data.height - 1; r >= 0; --r)
|
||||
{
|
||||
_write_format(file, "; %s\n", boost::beast::detail::base64_encode((const std::uint8_t*)(data.pixels.data() + r * row_size), row_size).c_str());
|
||||
std::string encoded = boost::beast::detail::base64_encode((const std::uint8_t*)(data.pixels.data() + r * row_size), row_size);
|
||||
unsigned int row_count = 0;
|
||||
while (encoded.length() > max_row_length)
|
||||
{
|
||||
if (row_count == 0)
|
||||
_write_format(file, "; %s\n", encoded.substr(0, max_row_length).c_str());
|
||||
else
|
||||
_write_format(file, ";>%s\n", encoded.substr(0, max_row_length).c_str());
|
||||
|
||||
encoded = encoded.substr(max_row_length);
|
||||
++row_count;
|
||||
}
|
||||
|
||||
if (row_count == 0)
|
||||
_write_format(file, "; %s\n", encoded.c_str());
|
||||
else
|
||||
_write_format(file, ";>%s\n", encoded.c_str());
|
||||
}
|
||||
|
||||
_write(file, "; thumbnail end\n;\n\n");
|
||||
_write(file, "; thumbnail end\n;\n");
|
||||
}
|
||||
print.throw_if_canceled();
|
||||
}
|
||||
|
@ -1106,6 +1106,7 @@ void GUI_App::gcode_thumbnails_debug()
|
||||
|
||||
boost::nowide::ifstream file(in_filename.c_str());
|
||||
std::vector<std::string> rows;
|
||||
std::string row;
|
||||
if (file.good())
|
||||
{
|
||||
while (std::getline(file, gcode_line))
|
||||
@ -1121,9 +1122,16 @@ void GUI_App::gcode_thumbnails_debug()
|
||||
width = (unsigned int)::atoi(width_str.c_str());
|
||||
std::string height_str = gcode_line.substr(x_pos + 1);
|
||||
height = (unsigned int)::atoi(height_str.c_str());
|
||||
row.clear();
|
||||
}
|
||||
else if (reading_image && boost::starts_with(gcode_line, END_MASK))
|
||||
{
|
||||
if (!row.empty())
|
||||
{
|
||||
rows.push_back(row);
|
||||
row.clear();
|
||||
}
|
||||
|
||||
if ((unsigned int)rows.size() == height)
|
||||
{
|
||||
std::vector<unsigned char> thumbnail(4 * width * height, 0);
|
||||
@ -1160,7 +1168,15 @@ void GUI_App::gcode_thumbnails_debug()
|
||||
rows.clear();
|
||||
}
|
||||
else if (reading_image)
|
||||
rows.push_back(gcode_line.substr(2));
|
||||
{
|
||||
if (!row.empty() && (gcode_line[1] == ' '))
|
||||
{
|
||||
rows.push_back(row);
|
||||
row.clear();
|
||||
}
|
||||
|
||||
row += gcode_line.substr(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user