From 36081f6486201d9bd316f3a8ceb5a38ad2e97310 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 23 Nov 2015 13:37:00 -0800 Subject: [core] For binary image data use uint8_t, not char --- platform/darwin/image.mm | 4 ++-- platform/default/headless_view.cpp | 2 +- platform/default/image.cpp | 8 ++++---- platform/default/image_reader.cpp | 6 +++--- platform/default/jpeg_reader.cpp | 6 +++--- platform/default/png_reader.cpp | 6 +++--- platform/node/src/node_map.cpp | 3 +-- 7 files changed, 17 insertions(+), 18 deletions(-) (limited to 'platform') diff --git a/platform/darwin/image.mm b/platform/darwin/image.mm index 31373e9d15..8965f1ea93 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 0587f5f380..fa83f65967 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 1562a06b74..bbd5d02b6f 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 e80ccb6819..3d27db58c3 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 f89e766874..dac18f32d2 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 ede7e52be1..204c4874f2 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 99fbb919e4..eb92205487 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) { -- cgit v1.2.1