MCPcopy Create free account
hub / github.com/Tencent/tgfx / MakeFrom

Method MakeFrom

src/core/ImageCodec.cpp:50–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50std::shared_ptr<ImageCodec> ImageCodec::MakeFrom(const std::string& filePath) {
51 static WeakMap<std::string, ImageCodec> imageCodecMap = {};
52 if (filePath.empty()) {
53 return nullptr;
54 }
55 if (auto cached = imageCodecMap.find(filePath)) {
56 return cached;
57 }
58 std::shared_ptr<ImageCodec> codec = nullptr;
59 auto stream = Stream::MakeFromFile(filePath);
60 if (stream && stream->size() > 14) {
61 Buffer buffer(14);
62 if (stream->read(buffer.data(), 14) == 14) {
63 auto data = buffer.release();
64#ifdef TGFX_USE_WEBP_DECODE
65 if (WebpCodec::IsWebp(data)) {
66 codec = WebpCodec::MakeFrom(filePath);
67 }
68#endif
69
70#ifdef TGFX_USE_PNG_DECODE
71 if (codec == nullptr && PngCodec::IsPng(data)) {
72 codec = PngCodec::MakeFrom(filePath);
73 }
74#endif
75
76#ifdef TGFX_USE_JPEG_DECODE
77 if (codec == nullptr && JpegCodec::IsJpeg(data)) {
78 codec = JpegCodec::MakeFrom(filePath);
79 }
80#endif
81 }
82 }
83 if (codec == nullptr) {
84 codec = MakeNativeCodec(filePath);
85 }
86 if (codec && !ImageInfo::IsValidSize(codec->width(), codec->height())) {
87 codec = nullptr;
88 }
89 if (codec) {
90 imageCodecMap.insert(filePath, codec);
91 }
92 return codec;
93}
94
95std::shared_ptr<ImageCodec> ImageCodec::MakeFrom(std::shared_ptr<Data> imageBytes) {
96 if (imageBytes == nullptr || imageBytes->size() == 0) {

Callers

nothing calls this directly

Calls 13

IsWebpFunction · 0.85
IsPngFunction · 0.85
IsJpegFunction · 0.85
MakeNativeCodecFunction · 0.85
emptyMethod · 0.45
findMethod · 0.45
sizeMethod · 0.45
readMethod · 0.45
dataMethod · 0.45
releaseMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected