-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimage_merge.cpp
36 lines (30 loc) · 1.24 KB
/
image_merge.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
#include "image_merge.h"
#include "image_encoder.h"
namespace quink {
template <>
std::shared_ptr<Image<float>> ImageMerge::Merge(std::shared_ptr<Image<uint8_t>> imgLow,
std::shared_ptr<Image<uint8_t>> imgHigh) {
if (imgLow->mWidth != imgHigh->mWidth ||
imgLow->mHeight != imgHigh->mHeight ||
imgLow->mGamma != imgHigh->mGamma)
return nullptr;
auto img = std::make_shared<Image<float>>(imgLow->mWidth, imgLow->mHeight, imgLow->mGamma);
int n = img->DataLength();
for (int i = 0; i < n; i++)
img->mData[i] = imgLow->mData[i] / 255.0 + (float)imgHigh->mData[i] / PairEncoder::magic_numer;
return img;
}
template <>
std::shared_ptr<Image<uint16_t>> ImageMerge::Merge(std::shared_ptr<Image<uint8_t>> imgLow,
std::shared_ptr<Image<uint8_t>> imgHigh) {
if (imgLow->mWidth != imgHigh->mWidth ||
imgLow->mHeight != imgHigh->mHeight ||
imgLow->mGamma != imgHigh->mGamma)
return nullptr;
auto img = std::make_shared<Image<uint16_t>>(imgLow->mWidth, imgLow->mHeight, imgLow->mGamma);
int n = img->DataLength();
for (int i = 0; i < n; i++)
img->mData[i] = imgLow->mData[i] + (imgHigh->mData[i] << 8) / PairEncoder::magic_numer;
return img;
}
}