#pragma once // Spec: SPEC.md UX-IMG-01. CPU bitmap: straight (non-premultiplied) ARGB8888, one uint32 per pixel. #include #include #include namespace dp::ui { class Bitmap { public: Bitmap(int w, int h) : w_(w), h_(h), px_(static_cast(w) * static_cast(h), 0) {} int width() const { return w_; } int height() const { return h_; } std::uint32_t* data() { return px_.data(); } const std::uint32_t* data() const { return px_.data(); } std::size_t bytes() const { return px_.size() * 4; } std::uint32_t at(int x, int y) const { return px_[static_cast(y) * static_cast(w_) + static_cast(x)]; } // Decode PNG/JPEG/GIF/BMP (stb_image) or SVG (nanosvg) bytes. nullptr when undecodable or over caps. // svgTargetPx: raster size (longest side) for vector sources. static std::shared_ptr decode(const std::string& bytes, int svgTargetPx); static constexpr int kMaxDimension = 8192; static constexpr std::size_t kMaxBytes = 64u * 1024u * 1024u; private: int w_; int h_; std::vector px_; }; using BitmapPtr = std::shared_ptr; } // namespace dp::ui