summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-09-03 21:12:16 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2020-09-03 21:12:16 +0200
commit8272d00b506a7357b4b127ef63b53586f2aa751f (patch)
tree7e65df18c77e138d2f3a83e1b21882d0f3871ca4
parent5bafc77ecee2448b41ae7e3c06f8035ae36d226d (diff)
Allow different byte per pixel values
-rw-r--r--blurhash.cpp10
-rw-r--r--blurhash.hpp2
2 files changed, 9 insertions, 3 deletions
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 <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <stdexcept>
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
#ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest.h>
#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<unsigned char>(linearToSrgb(c.r)));
i.image.push_back(static_cast<unsigned char>(linearToSrgb(c.g)));
i.image.push_back(static_cast<unsigned char>(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