-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathblurhash2bmp.cpp
43 lines (36 loc) · 1.24 KB
/
blurhash2bmp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "blurhash.hpp"
#include <charconv>
#include <iostream>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
int
main(int argc, char **argv)
{
if (argc != 5) {
std::cerr << "Usage: blurhash2bmp [hash] [width] [height] [output name]"
<< std::endl;
return -2;
}
int height = 0, width = 0;
std::string_view width_str{argv[2]}, height_str{argv[3]};
std::from_chars(height_str.data(), height_str.data() + height_str.size(), height);
if (height <= 0) {
std::cerr << "Invalid height.";
return -2;
}
std::from_chars(width_str.data(), width_str.data() + width_str.size(), width);
if (width <= 0) {
std::cerr << "Invalid width.";
return -2;
}
blurhash::Image image = blurhash::decode(argv[1], width, height);
if (image.image.empty()) {
std::cerr << "Decode failed.";
return -1;
}
if (!stbi_write_bmp(argv[4], image.width, image.height, 3, (void *)image.image.data())) {
std::cerr << "Image write failed.";
return -1;
}
return 0;
}