-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageReader.h
More file actions
108 lines (88 loc) · 2.67 KB
/
ImageReader.h
File metadata and controls
108 lines (88 loc) · 2.67 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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Copyright [2024] [Yao Yao]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include <cstdint>
#include <vector>
#include <array>
#include "macros.h"
#include <memory>
namespace Exiv2
{
class XmpData;
class ExifData;
}
namespace cudapp
{
template <typename T = std::array<uint8_t, 3>>
class ImageT
{
public:
using Pixel = T;
ImageT(std::vector<T> data, uint32_t width_, uint32_t height_) : mWidth{width_}, mHeight{height_}, mData{std::move(data)}{
ASSERT(width() * height() == mData.size());
}
ImageT(uint32_t width_, uint32_t height_) : mWidth{width_}, mHeight{height_}{
mData.resize(width() * height());
}
bool empty() const {
assert((width() == 0 || height() == 0) == mData.empty());
return mData.empty();
}
const T* data() const {return mData.data();}
T* data() {return mData.data();}
uint32_t width() const {return mWidth;}
uint32_t height() const {return mHeight;}
const T& operator()(uint32_t h, uint32_t w) const {return mData[width() * h + w];}
T& operator()(uint32_t h, uint32_t w) {return mData[width() * h + w];}
Pixel* begin() {return &mData[0];}
Pixel* end() {return begin() + mData.size();}
const Pixel* begin() const {return &mData[0];}
const Pixel* end() const {return begin() + mData.size();}
private:
uint32_t mWidth;
uint32_t mHeight;
std::vector<T> mData;
};
struct Shape2D
{
uint32_t width;
uint32_t height;
};
enum ImageFileType : int8_t
{
kJPEG,
kAVIF,
kHEIF
//@fixme: Add HEIC and JXL in the future
};
Shape2D getImageSize(const char* filename);
using Image8UC3 = ImageT<std::array<uint8_t, 3>>;
using Image8U = ImageT<uint8_t>;
Image8U rgbToGray(const Image8UC3& src);
// This image reader ignores transforms for getWidth()/getHeight()/decode*()
class IImageReader
{
public:
virtual ~IImageReader();
virtual void setFile(const char* filename) = 0;
virtual void setFile(const char* filename, ImageFileType type) = 0;
// this ignores transforms
virtual uint32_t getWidth() const = 0;
virtual uint32_t getHeight() const = 0;
virtual Exiv2::XmpData getXmpData() const = 0;
virtual Exiv2::ExifData getExifData() const = 0;
virtual Image8UC3 decodeTo8UC3() const = 0;
};
void initXmpParserOnce();
std::unique_ptr<IImageReader> createImageReader();
}