#pragma once #include #include #include #include #include #include #include namespace anm2ed::resource::image { constexpr auto CHANNELS = 4; constexpr auto SVG_EXTENSION = "svg"; constexpr auto PNG_EXTENSION = "png"; } namespace anm2ed::resource { class Image; // A block of an image placed at `destination`, for composing images. struct ImagePart { const Image* image{}; glm::ivec2 source{}; glm::ivec2 size{}; glm::ivec2 destination{}; }; // CPU-side RGBA pixels. uid changes whenever the pixels do, so GPU copies can be cached by it. A vector image keeps // its SVG and is drawn at `scale` pixels per SVG unit; it can be drawn again at any scale, and isn't edited. class Image { public: glm::ivec2 size{}; std::vector pixels{}; bool isLinear{}; std::uint64_t uid{}; std::shared_ptr svg{}; float scale{1.0f}; Image() = default; Image(const uint8_t*, glm::ivec2, bool = false); Image(const unsigned char*, size_t); Image(const std::filesystem::path&); bool is_valid() const; bool is_vector() const; glm::vec2 unit_size_get() const; Image vector_render(float) const; size_t pixel_size_get() const; bool write_png(const std::filesystem::path&) const; static bool write_pixels_png(const std::filesystem::path&, glm::ivec2, const uint8_t*); bool write(const std::filesystem::path&) const; static Image compose(const std::vector&, glm::ivec2, bool); void paste(const Image&, glm::ivec2); Image region_get(glm::ivec2, glm::ivec2) const; glm::vec4 pixel_read(glm::vec2) const; void pixel_set(glm::ivec2, glm::vec4); void pixel_line(glm::ivec2, glm::ivec2, glm::vec4); }; }