forked from taichi-dev/taichi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_reader.cpp
54 lines (46 loc) · 1.54 KB
/
image_reader.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
/*******************************************************************************
Copyright (c) The Taichi Authors (2016- ). All Rights Reserved.
The use of this software is governed by the LICENSE file.
*******************************************************************************/
#include "dcraw.h"
#include <mutex>
#include <taichi/io/image_reader.h>
TC_NAMESPACE_BEGIN
Array2D<Vector4> dcraw_read(const std::string &filepath) {
// Single threaded...
static std::mutex lock;
std::lock_guard<std::mutex> lock_guard(lock);
std::string filepath_non_const = filepath;
std::vector<const char *> argv{"dcraw.exe", "-4", "-T", "-W",
filepath_non_const.c_str()};
DCRawOutput output;
dcraw_main((int)argv.size(), &argv[0], output);
auto img =
Array2D<Vector4>(Vector2i(output.width, output.height), Vector4(0.0_f));
for (auto &ind : img.get_region()) {
for (int i = 0; i < output.channels; i++) {
img[ind][i] =
output.data[output.channels * (ind.j * output.width + ind.i) + i];
}
}
delete[] output.data;
img.flip(1);
TC_P(output.width);
TC_P(output.height);
TC_P(img.get_width());
TC_P(img.get_height());
TC_P(img.get_size());
return img;
}
class RawImageReader final : public ImageReader {
public:
void initialize(const Config &config) override {
}
Array2D<Vector4> read(const std::string &filepath) override {
auto tmp = dcraw_read(filepath);
TC_P("read!!");
return tmp;
}
};
TC_IMPLEMENTATION(ImageReader, RawImageReader, "raw");
TC_NAMESPACE_END