[core] replace encodePNG() with a version that doesn't use libpng
rationale: encodePNG is only used in tests + sample apps, but shouldn't actually be part of the core library. In #7828, we're removing the libpng dependency for Android, and using a libpng-free version of encodePNG allows us to run the core unit tests on Android without pulling in libpng just for the test suite. In a next step, we should remove encodePNG() from the image.hpp header, which is a public header.
This commit is contained in:
@@ -11,6 +11,24 @@ extern "C"
|
||||
#include <png.h>
|
||||
}
|
||||
|
||||
template<size_t max, typename... Args>
|
||||
static std::string sprintf(const char *msg, Args... args) {
|
||||
char res[max];
|
||||
int len = snprintf(res, sizeof(res), msg, args...);
|
||||
return std::string(res, len);
|
||||
}
|
||||
|
||||
const static bool png_version_check __attribute__((unused)) = []() {
|
||||
const png_uint_32 version = png_access_version_number();
|
||||
if (version != PNG_LIBPNG_VER) {
|
||||
throw std::runtime_error(sprintf<96>(
|
||||
"libpng version mismatch: headers report %d.%d.%d, but library reports %d.%d.%d",
|
||||
PNG_LIBPNG_VER / 10000, (PNG_LIBPNG_VER / 100) % 100, PNG_LIBPNG_VER % 100,
|
||||
version / 10000, (version / 100) % 100, version % 100));
|
||||
}
|
||||
return true;
|
||||
}();
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
static void user_error_fn(png_structp, png_const_charp error_msg) {
|
||||
|
||||
Reference in New Issue
Block a user