mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-07 23:17:35 -06:00
Thumbnails feature revamp. (#5555)
* Thumbnails feature revamp. Support generating different size/format combinations * misc fix Co-authored-by: Lukas Matena <lukasmatena@seznam.cz>
This commit is contained in:
parent
50d00a1d54
commit
c083541e0a
26 changed files with 1145 additions and 854 deletions
|
@ -528,5 +528,81 @@ int ColPic_EncodeStr(unsigned short* fromcolor16, int picw, int pich, unsigned c
|
|||
outputdata[qty] = 0;
|
||||
return qty;
|
||||
}
|
||||
std::pair<GCodeThumbnailDefinitionsList, ThumbnailErrors> make_and_check_thumbnail_list(const std::string& thumbnails_string, const std::string_view def_ext /*= "PNG"sv*/)
|
||||
{
|
||||
if (thumbnails_string.empty())
|
||||
return {};
|
||||
|
||||
std::istringstream is(thumbnails_string);
|
||||
std::string point_str;
|
||||
|
||||
ThumbnailErrors errors;
|
||||
|
||||
// generate thumbnails data to process it
|
||||
|
||||
GCodeThumbnailDefinitionsList thumbnails_list;
|
||||
while (std::getline(is, point_str, ',')) {
|
||||
Vec2d point(Vec2d::Zero());
|
||||
GCodeThumbnailsFormat format;
|
||||
std::istringstream iss(point_str);
|
||||
std::string coord_str;
|
||||
if (std::getline(iss, coord_str, 'x') && !coord_str.empty()) {
|
||||
std::istringstream(coord_str) >> point(0);
|
||||
if (std::getline(iss, coord_str, '/') && !coord_str.empty()) {
|
||||
std::istringstream(coord_str) >> point(1);
|
||||
|
||||
if (0 < point(0) && point(0) < 1000 && 0 < point(1) && point(1) < 1000) {
|
||||
std::string ext_str;
|
||||
std::getline(iss, ext_str, '/');
|
||||
|
||||
if (ext_str.empty())
|
||||
ext_str = def_ext.empty() ? "PNG"sv : def_ext;
|
||||
|
||||
// check validity of extention
|
||||
boost::to_upper(ext_str);
|
||||
if (!ConfigOptionEnum<GCodeThumbnailsFormat>::from_string(ext_str, format)) {
|
||||
format = GCodeThumbnailsFormat::PNG;
|
||||
errors = enum_bitmask(errors | ThumbnailError::InvalidExt);
|
||||
}
|
||||
|
||||
thumbnails_list.emplace_back(std::make_pair(format, point));
|
||||
}
|
||||
else
|
||||
errors = enum_bitmask(errors | ThumbnailError::OutOfRange);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
errors = enum_bitmask(errors | ThumbnailError::InvalidVal);
|
||||
}
|
||||
|
||||
return std::make_pair(std::move(thumbnails_list), errors);
|
||||
}
|
||||
|
||||
std::pair<GCodeThumbnailDefinitionsList, ThumbnailErrors> make_and_check_thumbnail_list(const ConfigBase& config)
|
||||
{
|
||||
// ??? Unit tests or command line slicing may not define "thumbnails" or "thumbnails_format".
|
||||
// ??? If "thumbnails_format" is not defined, export to PNG.
|
||||
|
||||
// generate thumbnails data to process it
|
||||
|
||||
if (const auto thumbnails_value = config.option<ConfigOptionString>("thumbnails"))
|
||||
return make_and_check_thumbnail_list(thumbnails_value->value);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string get_error_string(const ThumbnailErrors& errors)
|
||||
{
|
||||
std::string error_str;
|
||||
|
||||
if (errors.has(ThumbnailError::InvalidVal))
|
||||
error_str += "\n - " + format("Invalid input format. Expected vector of dimensions in the following format: \"%1%\"", "XxY/EXT, XxY/EXT, ...");
|
||||
if (errors.has(ThumbnailError::OutOfRange))
|
||||
error_str += "\n - Input value is out of range";
|
||||
if (errors.has(ThumbnailError::InvalidExt))
|
||||
error_str += "\n - Some extension in the input is invalid";
|
||||
|
||||
return error_str;
|
||||
}
|
||||
|
||||
} // namespace Slic3r::GCodeThumbnails
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue