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 | |
parent | a620912176c066181c0cc81e41c9205cc2a0d9c0 (diff) | |
download | qtlocation-mapboxgl-36081f6486201d9bd316f3a8ceb5a38ad2e97310.tar.gz |
[core] For binary image data use uint8_t, not char
-rw-r--r-- | include/mbgl/map/still_image.hpp | 8 | ||||
-rw-r--r-- | include/mbgl/platform/default/image_reader.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/platform/default/jpeg_reader.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/platform/default/png_reader.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/util/image.hpp | 8 | ||||
-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 | ||||
-rw-r--r-- | test/miscellaneous/bilinear.cpp | 2 |
13 files changed, 31 insertions, 34 deletions
diff --git a/include/mbgl/map/still_image.hpp b/include/mbgl/map/still_image.hpp index b9ce0620fa..36922fe95a 100644 --- a/include/mbgl/map/still_image.hpp +++ b/include/mbgl/map/still_image.hpp @@ -3,17 +3,15 @@ #include <mbgl/util/noncopyable.hpp> -#include <string> #include <cstdint> namespace mbgl { class StillImage : util::noncopyable { public: - uint16_t width = 0; - uint16_t height = 0; - using Pixel = uint32_t; - std::unique_ptr<Pixel[]> pixels; + size_t width = 0; + size_t height = 0; + std::unique_ptr<uint8_t[]> pixels; }; } diff --git a/include/mbgl/platform/default/image_reader.hpp b/include/mbgl/platform/default/image_reader.hpp index 52a67a2830..8e293d8be3 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<ImageReader> getImageReader(char const* data, size_t size); +std::unique_ptr<ImageReader> 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 3e64ce291b..d877005354 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 5cbbc51e77..9d6af91daa 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 f58c2c0989..fc4078501e 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<char[]> img; + std::unique_ptr<uint8_t[]> img; }; 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) { diff --git a/test/miscellaneous/bilinear.cpp b/test/miscellaneous/bilinear.cpp index bdfb9d9117..722e7265c0 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<char *>(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<uint8_t *>(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")); |