MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / decodeThumbnailJpeg

Function decodeThumbnailJpeg

pj_scene2D/core/src/thumbnail_codec.cpp:103–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103std::optional<DecodedFrame> decodeThumbnailJpeg(const uint8_t* jpeg, size_t jpeg_size, int width, int height) {
104 if (jpeg == nullptr || jpeg_size == 0 || width <= 0 || height <= 0) {
105 return std::nullopt;
106 }
107 tjhandle tj = tjInitDecompress();
108 if (tj == nullptr) {
109 return std::nullopt;
110 }
111 auto pixels = std::make_shared<std::vector<uint8_t>>(expectedBufferSize(width, height, PixelFormat::kYUV420P));
112 const int rc =
113 tjDecompressToYUV2(tj, jpeg, static_cast<unsigned long>(jpeg_size), pixels->data(), width, 1, height, 0);
114 tjDestroy(tj);
115 if (rc != 0) {
116 return std::nullopt;
117 }
118 DecodedFrame frame;
119 frame.pixels = std::move(pixels);
120 frame.width = width;
121 frame.height = height;
122 frame.format = PixelFormat::kYUV420P;
123 frame.pts = -1;
124 return frame;
125}
126
127} // namespace PJ

Callers 2

lookupMethod · 0.85
TESTFunction · 0.85

Calls 2

expectedBufferSizeFunction · 0.85
dataMethod · 0.45

Tested by 1

TESTFunction · 0.68