diff options
Diffstat (limited to 'src/libslic3r/PNGRead.cpp')
-rw-r--r-- | src/libslic3r/PNGRead.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libslic3r/PNGRead.cpp b/src/libslic3r/PNGRead.cpp index 695ceba3d..5b5b9ffec 100644 --- a/src/libslic3r/PNGRead.cpp +++ b/src/libslic3r/PNGRead.cpp @@ -27,8 +27,18 @@ bool is_png(const ReadBuf &rb) { static const constexpr int PNG_SIG_BYTES = 8; - return rb.sz >= PNG_SIG_BYTES && - !png_sig_cmp(static_cast<png_const_bytep>(rb.buf), 0, PNG_SIG_BYTES); +#if PNG_LIBPNG_VER_MINOR <= 2 + // Earlier libpng versions had png_sig_cmp(png_bytep, ...) which is not + // a const pointer. It is not possible to cast away the const qualifier from + // the input buffer so... yes... life is challenging... + png_byte buf[PNG_SIG_BYTES]; + auto inbuf = static_cast<const std::uint8_t *>(rb.buf); + std::copy(inbuf, inbuf + PNG_SIG_BYTES, buf); +#else + auto buf = static_cast<png_const_bytep>(rb.buf); +#endif + + return rb.sz >= PNG_SIG_BYTES && !png_sig_cmp(buf, 0, PNG_SIG_BYTES); } // A wrapper around ReadBuf to be read repeatedly like a stream. libpng needs |