diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-11-23 13:37:00 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-11-23 17:28:44 -0800 |
commit | 36081f6486201d9bd316f3a8ceb5a38ad2e97310 (patch) | |
tree | 58797124ca97462a455c42314d0235ff6df33d11 /platform | |
parent | a620912176c066181c0cc81e41c9205cc2a0d9c0 (diff) | |
download | qtlocation-mapboxgl-36081f6486201d9bd316f3a8ceb5a38ad2e97310.tar.gz |
[core] For binary image data use uint8_t, not char
Diffstat (limited to 'platform')
-rw-r--r-- | platform/darwin/image.mm | 4 | ||||
-rw-r--r-- | platform/default/headless_view.cpp | 2 | ||||
-rw-r--r-- | platform/default/image.cpp | 8 | ||||
-rw-r--r-- | platform/default/image_reader.cpp | 6 | ||||
-rw-r--r-- | platform/default/jpeg_reader.cpp | 6 | ||||
-rw-r--r-- | platform/default/png_reader.cpp | 6 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 3 |
7 files changed, 17 insertions, 18 deletions
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<CGFloat>(width), static_cast<CGFloat>(height) }}; - img = std::make_unique<char[]>(width * height * 4); + img = std::make_unique<uint8_t[]>(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<StillImage> HeadlessView::readStillImage() { auto image = std::make_unique<StillImage>(); image->width = w; image->height = h; - image->pixels = std::make_unique<uint32_t[]>(w * h); + image->pixels = std::make_unique<uint8_t[]>(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<const uint8_t*>(data.c_str()), data.size()); width = reader->width(); height = reader->height(); - img = std::make_unique<char[]>(width * height * 4); + img = std::make_unique<uint8_t[]>(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<std::string> type_from_bytes(char const* data, size_t size) +inline boost::optional<std::string> type_from_bytes(const uint8_t* data, size_t size) { using result_type = boost::optional<std::string>; if (size >= 4) @@ -42,9 +42,9 @@ inline boost::optional<std::string> type_from_bytes(char const* data, size_t siz return result_type(); } -std::unique_ptr<ImageReader> getImageReader(char const* data, size_t size) +std::unique_ptr<ImageReader> getImageReader(const uint8_t* data, size_t size) { - boost::optional<std::string> type = type_from_bytes(data,size); + boost::optional<std::string> 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 <typename T> -JpegReader<T>::JpegReader(char const* data, size_t size) - : source_(data, size), +JpegReader<T>::JpegReader(const uint8_t* data, size_t size) + : source_(reinterpret_cast<const char*>(data), size), stream_(source_), width_(0), height_(0) @@ -145,7 +145,7 @@ unsigned JpegReader<T>::height() const } template <typename T> -void JpegReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char* image) +void JpegReader<T>::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<T>::png_read_data(png_structp png_ptr, png_bytep data, png_size_t } template <typename T> -PngReader<T>::PngReader(char const* data, std::size_t size) - : source_(data,size), +PngReader<T>::PngReader(const uint8_t* data, std::size_t size) + : source_(reinterpret_cast<const char*>(data), size), stream_(source_), width_(0), height_(0), @@ -115,7 +115,7 @@ unsigned PngReader<T>::height() const } template <typename T> -void PngReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char * image) +void PngReader<T>::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<v8::Object> pixels = Nan::NewBuffer( - reinterpret_cast<char *>(img->pixels.get()), - size_t(img->width) * size_t(img->height) * sizeof(mbgl::StillImage::Pixel), + reinterpret_cast<char *>(img->pixels.get()), img->width * img->height * 4, // Retain the StillImage object until the buffer is deleted. [](char *, void *hint) { |