diff --git a/include/mbgl/map/still_image.hpp b/include/mbgl/map/still_image.hpp index b9ce0620f..36922fe95 100644 --- a/include/mbgl/map/still_image.hpp +++ b/include/mbgl/map/still_image.hpp @@ -3,17 +3,15 @@ #include -#include #include namespace mbgl { class StillImage : util::noncopyable { public: - uint16_t width = 0; - uint16_t height = 0; - using Pixel = uint32_t; - std::unique_ptr pixels; + size_t width = 0; + size_t height = 0; + std::unique_ptr pixels; }; } diff --git a/include/mbgl/platform/default/image_reader.hpp b/include/mbgl/platform/default/image_reader.hpp index 52a67a283..8e293d8be 100644 --- a/include/mbgl/platform/default/image_reader.hpp +++ b/include/mbgl/platform/default/image_reader.hpp @@ -31,11 +31,11 @@ struct ImageReader : private noncopyable virtual unsigned height() const=0; virtual bool hasAlpha() const=0; virtual bool premultipliedAlpha() const=0; - virtual void read(unsigned x,unsigned y, unsigned width, unsigned height, char* image)=0; + virtual void read(unsigned x, unsigned y, unsigned width, unsigned height, uint8_t* image)=0; virtual ~ImageReader() {} }; -std::unique_ptr getImageReader(char const* data, size_t size); +std::unique_ptr getImageReader(const uint8_t* data, size_t size); }} diff --git a/include/mbgl/platform/default/jpeg_reader.hpp b/include/mbgl/platform/default/jpeg_reader.hpp index 3e64ce291..d87700535 100644 --- a/include/mbgl/platform/default/jpeg_reader.hpp +++ b/include/mbgl/platform/default/jpeg_reader.hpp @@ -51,13 +51,13 @@ private: unsigned width_; unsigned height_; public: - JpegReader(char const* data, size_t size); + JpegReader(const uint8_t* data, size_t size); ~JpegReader(); unsigned width() const; unsigned height() const; inline bool hasAlpha() const { return false; } inline bool premultipliedAlpha() const { return true; } - void read(unsigned x,unsigned y, unsigned w, unsigned h, char *image); + void read(unsigned x, unsigned y, unsigned w, unsigned h, uint8_t* image); private: void init(); static void on_error(j_common_ptr cinfo); diff --git a/include/mbgl/platform/default/png_reader.hpp b/include/mbgl/platform/default/png_reader.hpp index 5cbbc51e7..9d6af91da 100644 --- a/include/mbgl/platform/default/png_reader.hpp +++ b/include/mbgl/platform/default/png_reader.hpp @@ -49,13 +49,13 @@ private: int color_type_; bool has_alpha_; public: - PngReader(char const* data, std::size_t size); + PngReader(const uint8_t* data, std::size_t size); ~PngReader(); unsigned width() const; unsigned height() const; inline bool hasAlpha() const { return has_alpha_; } bool premultipliedAlpha() const { return true; } // png_set_alpha_mode(png, PNG_ALPHA_PREMULTIPLIED, 2.2) - void read(unsigned x,unsigned y, unsigned width, unsigned height, char * image); + void read(unsigned x,unsigned y, unsigned width, unsigned height, uint8_t* image); private: void init(); static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length); diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp index f58c2c098..fc4078501 100644 --- a/include/mbgl/util/image.hpp +++ b/include/mbgl/util/image.hpp @@ -7,14 +7,14 @@ namespace mbgl { namespace util { -std::string compress_png(int width, int height, const void *rgba); +std::string compress_png(size_t width, size_t height, const uint8_t* rgba); class Image { public: - explicit Image(const std::string &img); + explicit Image(const std::string& img); - inline const char *getData() const { return img.get(); } + 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; } @@ -24,7 +24,7 @@ private: uint32_t width = 0, height = 0; // the raw image data - std::unique_ptr img; + std::unique_ptr img; }; diff --git a/platform/darwin/image.mm b/platform/darwin/image.mm index 31373e9d1..8965f1ea9 100644 --- a/platform/darwin/image.mm +++ b/platform/darwin/image.mm @@ -11,7 +11,7 @@ namespace mbgl { namespace util { -std::string compress_png(int width, int height, const void *rgba) { +std::string compress_png(size_t width, size_t height, const uint8_t* rgba) { CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, rgba, width * height * 4, NULL); if (!provider) { return ""; @@ -97,7 +97,7 @@ Image::Image(const std::string &source_data) { height = uint32_t(CGImageGetHeight(image)); CGRect rect = {{ 0, 0 }, { static_cast(width), static_cast(height) }}; - img = std::make_unique(width * height * 4); + img = std::make_unique(width * height * 4); CGContextRef context = CGBitmapContextCreate(img.get(), width, height, 8, width * 4, color_space, kCGImageAlphaPremultipliedLast); if (!context) { diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index 0587f5f38..fa83f6596 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -179,7 +179,7 @@ std::unique_ptr HeadlessView::readStillImage() { auto image = std::make_unique(); image->width = w; image->height = h; - image->pixels = std::make_unique(w * h); + image->pixels = std::make_unique(w * h * 4); MBGL_CHECK_ERROR(glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels.get())); diff --git a/platform/default/image.cpp b/platform/default/image.cpp index 1562a06b7..bbd5d02b6 100644 --- a/platform/default/image.cpp +++ b/platform/default/image.cpp @@ -27,7 +27,7 @@ const static bool png_version_check = []() { namespace mbgl { namespace util { -std::string compress_png(int width, int height, const void *rgba) { +std::string compress_png(size_t width, size_t height, const uint8_t* rgba) { png_voidp error_ptr = 0; png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, error_ptr, NULL, NULL); if (!png_ptr) { @@ -63,7 +63,7 @@ std::string compress_png(int width, int height, const void *rgba) { png_bytep *rows = nullptr; } pointers(height); - for (int i = 0; i < height; i++) { + for (size_t i = 0; i < height; i++) { pointers.rows[i] = (png_bytep)((png_bytep)rgba + width * 4 * i); } @@ -78,10 +78,10 @@ Image::Image(std::string const& data) { try { - auto reader = getImageReader(data.c_str(), data.size()); + auto reader = getImageReader(reinterpret_cast(data.c_str()), data.size()); width = reader->width(); height = reader->height(); - img = std::make_unique(width * height * 4); + img = std::make_unique(width * height * 4); reader->read(0, 0, width, height, img.get()); } catch (ImageReaderException const& ex) diff --git a/platform/default/image_reader.cpp b/platform/default/image_reader.cpp index e80ccb681..3d27db58c 100644 --- a/platform/default/image_reader.cpp +++ b/platform/default/image_reader.cpp @@ -7,7 +7,7 @@ namespace mbgl { namespace util { -inline boost::optional type_from_bytes(char const* data, size_t size) +inline boost::optional type_from_bytes(const uint8_t* data, size_t size) { using result_type = boost::optional; if (size >= 4) @@ -42,9 +42,9 @@ inline boost::optional type_from_bytes(char const* data, size_t siz return result_type(); } -std::unique_ptr getImageReader(char const* data, size_t size) +std::unique_ptr getImageReader(const uint8_t* data, size_t size) { - boost::optional type = type_from_bytes(data,size); + boost::optional type = type_from_bytes(data, size); if (type) { if (*type == "png") diff --git a/platform/default/jpeg_reader.cpp b/platform/default/jpeg_reader.cpp index f89e76687..dac18f32d 100644 --- a/platform/default/jpeg_reader.cpp +++ b/platform/default/jpeg_reader.cpp @@ -13,8 +13,8 @@ namespace mbgl { namespace util { // ctor template -JpegReader::JpegReader(char const* data, size_t size) - : source_(data, size), +JpegReader::JpegReader(const uint8_t* data, size_t size) + : source_(reinterpret_cast(data), size), stream_(source_), width_(0), height_(0) @@ -145,7 +145,7 @@ unsigned JpegReader::height() const } template -void JpegReader::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char* image) +void JpegReader::read(unsigned x0, unsigned y0, unsigned w, unsigned h, uint8_t* image) { stream_.clear(); stream_.seekg(0, std::ios_base::beg); diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp index ede7e52be..204c4874f 100644 --- a/platform/default/png_reader.cpp +++ b/platform/default/png_reader.cpp @@ -40,8 +40,8 @@ void PngReader::png_read_data(png_structp png_ptr, png_bytep data, png_size_t } template -PngReader::PngReader(char const* data, std::size_t size) - : source_(data,size), +PngReader::PngReader(const uint8_t* data, std::size_t size) + : source_(reinterpret_cast(data), size), stream_(source_), width_(0), height_(0), @@ -115,7 +115,7 @@ unsigned PngReader::height() const } template -void PngReader::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char * image) +void PngReader::read(unsigned x0, unsigned y0, unsigned w, unsigned h, uint8_t* image) { stream_.clear(); stream_.seekg(0, std::ios_base::beg); diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 99fbb919e..eb9220548 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -360,8 +360,7 @@ void NodeMap::renderFinished() { cb->Call(1, argv); } else if (img) { v8::Local pixels = Nan::NewBuffer( - reinterpret_cast(img->pixels.get()), - size_t(img->width) * size_t(img->height) * sizeof(mbgl::StillImage::Pixel), + reinterpret_cast(img->pixels.get()), img->width * img->height * 4, // Retain the StillImage object until the buffer is deleted. [](char *, void *hint) { diff --git a/test/miscellaneous/bilinear.cpp b/test/miscellaneous/bilinear.cpp index bdfb9d911..722e7265c 100644 --- a/test/miscellaneous/bilinear.cpp +++ b/test/miscellaneous/bilinear.cpp @@ -42,7 +42,7 @@ TEST(Bilinear, Scaling) { util::bilinearScale(srcData, srcSize, { 252, 380, 12, 12 }, dstData, dstSize, { 18, 90, 24, 24 }, false); const std::string data { reinterpret_cast(dstData), dstSize.x * dstSize.y * sizeof(uint32_t) }; - util::write_file("test/fixtures/sprites/atlas_actual.png", util::compress_png(dstSize.x, dstSize.y, dstData)); + util::write_file("test/fixtures/sprites/atlas_actual.png", util::compress_png(dstSize.x, dstSize.y, reinterpret_cast(dstData))); util::write_file("test/fixtures/sprites/atlas_actual.bin", util::compress(data)); const std::string reference = util::decompress(util::read_file("test/fixtures/sprites/atlas_reference.bin"));