mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 04:28:49 +03:00
Allow different byte per pixel values
This commit is contained in:
parent
5bafc77ece
commit
8272d00b50
2 changed files with 9 additions and 3 deletions
10
blurhash.cpp
10
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue