-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimage_decoder.cpp
53 lines (43 loc) · 1.76 KB
/
image_decoder.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
#include "image_decoder.h"
#include <algorithm>
#include "log.h"
#include "hdr_decoder.h"
#include "ldr_decoder.h"
#include "pfm_decoder.h"
#include "openexr_decoder.h"
namespace quink {
ImageWrapper ImageLoader::LoadImage(const std::string &file) {
const ImageDecoderFactoryListType &CreatorList = GetImageDecoderFactoryList();
using CreatorScorePair = std::pair<std::shared_ptr<ImageDecoderFactory>, int>;
std::vector<CreatorScorePair> creatorScore;
for (const auto &creator : CreatorList) {
int n = creator->Probe(file);
if (n == ImageDecoderFactory::SCORE_DEFINITELY) {
ALOGD("create %s", creator->GetDecoderName().c_str());
auto decoder = creator->Create();
return decoder->Decode(file);
} else if (n > ImageDecoderFactory::SCORE_UNSUPPORT) {
creatorScore.push_back(CreatorScorePair(creator, n));
}
}
if (creatorScore.empty())
return ImageWrapper();
std::sort(creatorScore.begin(), creatorScore.end(),
[](const CreatorScorePair &a, const CreatorScorePair &b)
{
return a.second < b.second;
});
ALOGD("create %s", creatorScore.back().first->GetDecoderName().c_str());
auto decoder = creatorScore.back().first->Create();
return decoder->Decode(file);
}
const ImageLoader::ImageDecoderFactoryListType &ImageLoader::GetImageDecoderFactoryList() {
static ImageDecoderFactoryListType CreatorList{
std::shared_ptr<ImageDecoderFactory>(new PfmDecoderFactory),
std::shared_ptr<ImageDecoderFactory>(new OpenEXRDecoderFactory),
std::shared_ptr<ImageDecoderFactory>(new HdrDecoderFactory),
std::shared_ptr<ImageDecoderFactory>(new LdrDecoderFactory),
};
return CreatorList;
}
}