tomato/src/image_loader.hpp

44 lines
1020 B
C++
Raw Normal View History

2023-07-30 16:00:55 +02:00
#pragma once
#include <cstdint>
2023-10-06 02:01:31 +02:00
#include <map>
2023-07-30 16:00:55 +02:00
#include <vector>
2023-10-06 02:01:31 +02:00
#include <string>
2023-07-30 16:00:55 +02:00
struct ImageLoaderI {
virtual ~ImageLoaderI(void) {}
struct ImageInfo final {
2023-07-30 16:00:55 +02:00
uint32_t width {0};
uint32_t height {0};
const char* file_ext {nullptr};
2023-07-30 16:00:55 +02:00
};
virtual ImageInfo loadInfoFromMemory(const uint8_t* data, uint64_t data_size) = 0;
struct ImageResult final {
2023-07-30 16:00:55 +02:00
uint32_t width {0};
uint32_t height {0};
struct Frame {
int32_t ms {0};
std::vector<uint8_t> data;
};
std::vector<Frame> frames;
const char* file_ext {nullptr};
// only positive values are valid
ImageResult crop(int32_t c_x, int32_t c_y, int32_t c_w, int32_t c_h) const;
2024-07-16 15:02:52 +02:00
// TODO: scale
2023-07-30 16:00:55 +02:00
};
virtual ImageResult loadFromMemoryRGBA(const uint8_t* data, uint64_t data_size) = 0;
};
2023-10-06 02:01:31 +02:00
struct ImageEncoderI {
virtual ~ImageEncoderI(void) {}
using ImageResult = ImageLoaderI::ImageResult;
2023-10-06 13:16:45 +02:00
virtual std::vector<uint8_t> encodeToMemoryRGBA(const ImageResult& input_image, const std::map<std::string, float>& extra_options = {}) = 0;
2023-10-06 02:01:31 +02:00
};