-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveImage.cpp
More file actions
49 lines (43 loc) · 1.51 KB
/
saveImage.cpp
File metadata and controls
49 lines (43 loc) · 1.51 KB
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
44
45
46
47
48
49
#include <ImageIO/saveImage.h>
#include <ImageIO/thirdparty/lodepng/lodepng.h>
#include <stdexcept>
namespace ImageIO_NS
{
using ::imageview::ContinuousImageView;
using ::imageview::PixelFormatGrayscale8;
using ::imageview::PixelFormatRGB24;
using ::imageview::PixelFormatRGBA32;
void saveImage(ContinuousImageView<PixelFormatGrayscale8> image, const std::filesystem::path& path)
{
unsigned int status = lodepng_encode_file(
path.string().c_str(),
reinterpret_cast<const unsigned char*>(image.data().data()),
image.width(), image.height(), LodePNGColorType::LCT_GREY, 8);
if (status != 0)
{
throw std::runtime_error(lodepng_error_text(status));
}
}
void saveImage(ContinuousImageView<PixelFormatRGB24> image, const std::filesystem::path& path)
{
unsigned int status = lodepng_encode_file(
path.string().c_str(),
reinterpret_cast<const unsigned char*>(image.data().data()),
image.width(), image.height(), LodePNGColorType::LCT_RGB, 8);
if (status != 0)
{
throw std::runtime_error(lodepng_error_text(status));
}
}
void saveImage(ContinuousImageView<PixelFormatRGBA32> image, const std::filesystem::path& path)
{
unsigned int status = lodepng_encode_file(
path.string().c_str(),
reinterpret_cast<const unsigned char*>(image.data().data()),
image.width(), image.height(), LodePNGColorType::LCT_RGBA, 8);
if (status != 0)
{
throw std::runtime_error(lodepng_error_text(status));
}
}
}