diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-11-24 10:07:18 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-11-25 15:57:36 -0800 |
commit | 0c1e378bc9555f6cf826bb38b1a36fa742f8ce9b (patch) | |
tree | 9aec8e4f475ff715645072503b3e0ec78f0573af /include/mbgl/util/image.hpp | |
parent | 2de0a351a0635192bd05116cebdf0103c2638d05 (diff) | |
download | qtlocation-mapboxgl-0c1e378bc9555f6cf826bb38b1a36fa742f8ce9b.tar.gz |
[core] Rewrite image handling
* Consolidate Image and StillImage
* Typecheck unassociated vs premultiplied images
* Rewrite default platform image decoding implementation
Diffstat (limited to 'include/mbgl/util/image.hpp')
-rw-r--r-- | include/mbgl/util/image.hpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp index fc4078501e..0604691dd1 100644 --- a/include/mbgl/util/image.hpp +++ b/include/mbgl/util/image.hpp @@ -5,30 +5,37 @@ #include <memory> namespace mbgl { -namespace util { - -std::string compress_png(size_t width, size_t height, const uint8_t* rgba); +enum ImageAlphaMode { + Unassociated, + Premultiplied +}; +template <ImageAlphaMode Mode> class Image { public: - explicit Image(const std::string& img); + Image() {} - inline const uint8_t* getData() const { return img.get(); } - inline uint32_t getWidth() const { return width; } - inline uint32_t getHeight() const { return height; } - inline operator bool() const { return img && width && height; } + Image(size_t w, size_t h) + : width(w), + height(h), + data(std::make_unique<uint8_t[]>(size())) {} -private: - // loaded image dimensions - uint32_t width = 0, height = 0; + size_t stride() const { return width * 4; } + size_t size() const { return width * height * 4; } - // the raw image data - std::unique_ptr<uint8_t[]> img; + size_t width = 0; + size_t height = 0; + std::unique_ptr<uint8_t[]> data; }; +using UnassociatedImage = Image<ImageAlphaMode::Unassociated>; +using PremultipliedImage = Image<ImageAlphaMode::Premultiplied>; + +// TODO: don't use std::string for binary data. +PremultipliedImage decodeImage(const std::string&); +std::string encodePNG(const UnassociatedImage&); -} } #endif |