-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimage.cpp
76 lines (67 loc) · 2.42 KB
/
image.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "image.h"
namespace quink {
ImageWrapper::ImageDataType ImageWrapper::GetDataType() {
if (mImgFloat)
return DataTypeFloat;
else if (mImgUInt8)
return DataTypeUInt8;
else if (mImgUInt16)
return DataTypeUInt16;
else
return DataTypeFloat;
}
template <>
std::shared_ptr<Image<float>> ImageWrapper::GetImg() {
std::shared_ptr<Image<float>> img;
if (mImgFloat) {
img = mImgFloat;
} else if (mImgUInt8) {
img = std::make_shared<Image<float>>(mImgUInt8->mWidth, mImgUInt8->mHeight, mImgUInt8->mGamma);
int n = img->DataLength();
for (int i = 0; i < n; i++)
img->mData[i] = mImgUInt8->mData[i] / 255.0f;
} else if (mImgUInt16) {
img = std::make_shared<Image<float>>(mImgUInt16->mWidth, mImgUInt16->mHeight, mImgUInt16->mHeight);
int n = img->DataLength();
for (int i = 0; i < n; i++)
img->mData[i] = mImgUInt16->mData[i] / 255.0f;
}
return img;
}
template <>
std::shared_ptr<Image<uint8_t>> ImageWrapper::GetImg() {
std::shared_ptr<Image<uint8_t>> img;
if (mImgFloat) {
img = std::make_shared<Image<uint8_t>>(mImgFloat->mWidth, mImgFloat->mHeight, mImgFloat->mGamma);
int n = img->DataLength();
for (int i = 0; i < n; i++)
img->mData[i] = std::min<float>(mImgFloat->mData[i] * 255, 255);
} else if (mImgUInt8) {
img = mImgUInt8;
} else if (mImgUInt16) {
img = std::make_shared<Image<uint8_t>>(mImgUInt16->mWidth, mImgUInt16->mHeight, mImgUInt16->mGamma);
int n = img->DataLength();
for (int i = 0; i < n; i++)
img->mData[i] = std::min<uint16_t>(mImgUInt16->mData[i], 255);
}
return img;
}
template <>
std::shared_ptr<Image<uint16_t>> ImageWrapper::GetImg() {
std::shared_ptr<Image<uint16_t>> img;
if (mImgFloat) {
img = std::make_shared<Image<uint16_t>>(mImgFloat->mWidth, mImgFloat->mHeight, mImgFloat->mGamma);
int n = img->DataLength();
for (int i = 0; i < n; i++)
img->mData[i] = std::min<float>(mImgFloat->mData[i] * 255, 65535);
} else if (mImgUInt8) {
img = std::make_shared<Image<uint16_t>>(mImgUInt8->mWidth, mImgUInt8->mHeight, mImgUInt8->mGamma);
int n = img->DataLength();
for (int i = 0; i < n; i++)
img->mData[i] = mImgUInt8->mData[i];
} else if (mImgUInt16) {
img = mImgUInt16;
}
return img;
}
}