mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-06 23:31:19 +00:00
Fix colour textures loading upside down and crashes on damaged PNGs
Colour height maps now displace the same way up as grayscale ones. A truncated or corrupt PNG in the texture folder or a project file now loads as an empty texture instead of aborting the app, and a 16-bit colour PNG is converted on load rather than displacing as noise.
This commit is contained in:
@@ -153,8 +153,8 @@ std::vector<unsigned char> read_file_bytes(const std::string &path)
|
||||
}
|
||||
|
||||
// True if these bytes are a PNG libslic3r can decode, i.e. can be stored on a layer as-is. Mirrors
|
||||
// exactly what decode_height_texture() accepts: 8-bit grayscale, or colour (whose luminance is the
|
||||
// height and whose RGB is available to colour the model).
|
||||
// exactly what decode_height_texture() accepts: 8-bit grayscale, or 8-bit colour (whose luminance is
|
||||
// the height and whose RGB is available to colour the model). Anything else is converted on load.
|
||||
bool is_supported_height_map(const std::vector<unsigned char> &bytes)
|
||||
{
|
||||
if (bytes.empty())
|
||||
@@ -167,7 +167,8 @@ bool is_supported_height_map(const std::vector<unsigned char> &bytes)
|
||||
return true;
|
||||
png::ImageColorscale color;
|
||||
return png::decode_colored_png(rbuf, color) && color.cols > 0 && color.rows > 0 &&
|
||||
color.bytes_per_pixel >= 3;
|
||||
color.bytes_per_pixel >= 3 &&
|
||||
color.buf.size() == color.cols * color.rows * size_t(color.bytes_per_pixel);
|
||||
}
|
||||
|
||||
std::vector<TextureLibraryEntry> g_library;
|
||||
|
||||
Reference in New Issue
Block a user