| 101 | } |
| 102 | |
| 103 | std::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 |