Files
MapLibreParticleLab/include/mbgl/util/image.hpp
John Firebaugh 1d33790dc0 [core] Fix image type of Map::renderStill
It's a premultiplied image. This implies that we were misusing encodePNG
in most cases, as we were passing premultiplied pixels which were then
interpreted as unmultiplied. I changed encodePNG to accept premultipled
pixels, and unpremultiply in the implementations.
2015-11-25 15:57:37 -08:00

42 lines
842 B
C++

#ifndef MBGL_UTIL_IMAGE
#define MBGL_UTIL_IMAGE
#include <string>
#include <memory>
namespace mbgl {
enum ImageAlphaMode {
Unassociated,
Premultiplied
};
template <ImageAlphaMode Mode>
class Image {
public:
Image() {}
Image(size_t w, size_t h)
: width(w),
height(h),
data(std::make_unique<uint8_t[]>(size())) {}
size_t stride() const { return width * 4; }
size_t size() const { return width * height * 4; }
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 PremultipliedImage&);
}
#endif