MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / ImageReader

Class ImageReader

src/include/image/image_reader.hpp:35–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33};
34
35class ImageReader {
36public:
37 explicit ImageReader(size_t max_cached_per_size = 16);
38 ~ImageReader();
39
40 bool load_image(const std::string& filename, image_data_t& out_image);
41 bool load_image_base64(const std::string& base64_string, image_data_t& out_image);
42 bool resize_image(const image_data_t& input, int target_width, int target_height, image_data_t& output);
43 bool reorder_hwc_to_chw(const image_data_t& input, image_data_t& output);
44 bool save_png(const std::string& filename, const image_data_t& image);
45
46 void recycle(image_data_t& image);
47
48private:
49 static void initialize_ffmpeg();
50 static bool parse_image_header(const uint8_t* data, size_t size, int& codec_id);
51 bool decode_bytes(const uint8_t* data, size_t size, image_data_t& out_image);
52 bool ensure_decode_resources(int codec_id);
53 void reset_decode_resources();
54
55 ImageMemoryPool memory_pool_;
56
57 struct AVCodecContext* codec_ctx_ = nullptr;
58 struct AVPacket* packet_ = nullptr;
59 struct AVFrame* frame_ = nullptr;
60 struct AVFrame* rgb_frame_ = nullptr;
61 struct SwsContext* sws_ctx_ = nullptr;
62
63 int cached_codec_id_ = -1;
64 int sws_src_w_ = 0;
65 int sws_src_h_ = 0;
66 int sws_src_fmt_ = -1;
67 int sws_src_range_ = -1;
68};
69
70bool save_image(const std::string& filename, const bytes& image);
71

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected