diff --git a/blurhash.cpp b/blurhash.cpp index 56a9e6fa..03ec39c3 100644 --- a/blurhash.cpp +++ b/blurhash.cpp @@ -1,12 +1,15 @@ #include "blurhash.hpp" -#define _USE_MATH_DEFINES #include #include #include #include #include +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + #ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include #endif @@ -248,7 +251,7 @@ multiplyBasisFunction(Components components, int width, int height, unsigned cha namespace blurhash { Image -decode(std::string_view blurhash, size_t width, size_t height) +decode(std::string_view blurhash, size_t width, size_t height, size_t bytesPerPixel) { Image i{}; @@ -292,6 +295,9 @@ decode(std::string_view blurhash, size_t width, size_t height) i.image.push_back(static_cast(linearToSrgb(c.r))); i.image.push_back(static_cast(linearToSrgb(c.g))); i.image.push_back(static_cast(linearToSrgb(c.b))); + + for (size_t p = 3; p < bytesPerPixel; p++) + i.image.push_back(255); } } diff --git a/blurhash.hpp b/blurhash.hpp index 5077f0d5..e01b9b3f 100644 --- a/blurhash.hpp +++ b/blurhash.hpp @@ -13,7 +13,7 @@ struct Image // Decode a blurhash to an image with size width*height Image -decode(std::string_view blurhash, size_t width, size_t height); +decode(std::string_view blurhash, size_t width, size_t height, size_t bytesPerPixel = 3); // Encode an image of rgb pixels (without padding) with size width*height into a blurhash with x*y // components