diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-11-24 10:07:18 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-11-25 15:57:36 -0800 |
commit | 0c1e378bc9555f6cf826bb38b1a36fa742f8ce9b (patch) | |
tree | 9aec8e4f475ff715645072503b3e0ec78f0573af /include/mbgl/platform | |
parent | 2de0a351a0635192bd05116cebdf0103c2638d05 (diff) | |
download | qtlocation-mapboxgl-0c1e378bc9555f6cf826bb38b1a36fa742f8ce9b.tar.gz |
[core] Rewrite image handling
* Consolidate Image and StillImage
* Typecheck unassociated vs premultiplied images
* Rewrite default platform image decoding implementation
Diffstat (limited to 'include/mbgl/platform')
-rw-r--r-- | include/mbgl/platform/default/headless_view.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/platform/default/image_reader.hpp | 40 | ||||
-rw-r--r-- | include/mbgl/platform/default/jpeg_reader.hpp | 72 | ||||
-rw-r--r-- | include/mbgl/platform/default/png_reader.hpp | 65 |
4 files changed, 1 insertions, 178 deletions
diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp index 50edc48428..8b25620524 100644 --- a/include/mbgl/platform/default/headless_view.hpp +++ b/include/mbgl/platform/default/headless_view.hpp @@ -39,7 +39,7 @@ public: void invalidate() override; void beforeRender() override; void afterRender() override; - std::unique_ptr<StillImage> readStillImage() override; + UnassociatedImage readStillImage() override; void resizeFramebuffer(); void resize(uint16_t width, uint16_t height); diff --git a/include/mbgl/platform/default/image_reader.hpp b/include/mbgl/platform/default/image_reader.hpp deleted file mode 100644 index e46bb08ea2..0000000000 --- a/include/mbgl/platform/default/image_reader.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef MBGL_UTIL_IMAGE_READER_HPP -#define MBGL_UTIL_IMAGE_READER_HPP - -#include <mbgl/util/noncopyable.hpp> -// stl -#include <stdexcept> -#include <string> -#include <memory> - -namespace mbgl { namespace util { - -class ImageReaderException : public std::exception -{ -private: - std::string message_; -public: - ImageReaderException(std::string const& message) - : message_(message) {} - - ~ImageReaderException() throw() {} - - virtual const char* what() const throw() - { - return message_.c_str(); - } -}; - -struct ImageReader : private noncopyable -{ - virtual unsigned width() const=0; - virtual unsigned height() const=0; - virtual std::unique_ptr<uint8_t[]> read()=0; - virtual ~ImageReader() {} -}; - -std::unique_ptr<ImageReader> getImageReader(const uint8_t* data, size_t size); - -}} - -#endif diff --git a/include/mbgl/platform/default/jpeg_reader.hpp b/include/mbgl/platform/default/jpeg_reader.hpp deleted file mode 100644 index 2f988374c3..0000000000 --- a/include/mbgl/platform/default/jpeg_reader.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef MBGL_UTIL_JPEG_READER_HPP -#define MBGL_UTIL_JPEG_READER_HPP - -#include <mbgl/platform/default/image_reader.hpp> - -// jpeg -extern "C" -{ -#include <jpeglib.h> -} - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunknown-pragmas" -#pragma GCC diagnostic ignored "-Wunused-local-typedefs" -#pragma GCC diagnostic ignored "-Wshadow" -#include <boost/iostreams/stream.hpp> -#pragma GCC diagnostic pop - -namespace mbgl { namespace util { - -template <typename T> -class JpegReader : public ImageReader -{ -public: - using source_type = T; - using input_stream = boost::iostreams::stream<source_type>; - const static unsigned BUF_SIZE = 4096; -private: - struct jpeg_stream_wrapper - { - jpeg_source_mgr manager; - input_stream * stream; - JOCTET buffer[BUF_SIZE]; - }; - - struct jpeg_info_guard - { - jpeg_info_guard(jpeg_decompress_struct * cinfo) - : i_(cinfo) {} - - ~jpeg_info_guard() - { - jpeg_destroy_decompress(i_); - } - jpeg_decompress_struct * i_; - }; - -private: - source_type source_; - input_stream stream_; - unsigned width_; - unsigned height_; -public: - JpegReader(const uint8_t* data, size_t size); - ~JpegReader(); - unsigned width() const; - unsigned height() const; - std::unique_ptr<uint8_t[]> read(); -private: - void init(); - static void on_error(j_common_ptr cinfo); - static void on_error_message(j_common_ptr cinfo); - static void init_source(j_decompress_ptr cinfo); - static boolean fill_input_buffer(j_decompress_ptr cinfo); - static void skip(j_decompress_ptr cinfo, long count); - static void term(j_decompress_ptr cinfo); - static void attach_stream(j_decompress_ptr cinfo, input_stream* in); -}; - -}} - -#endif // MBGL_UTIL_JPEG_READER_HPP diff --git a/include/mbgl/platform/default/png_reader.hpp b/include/mbgl/platform/default/png_reader.hpp deleted file mode 100644 index c869e78ea4..0000000000 --- a/include/mbgl/platform/default/png_reader.hpp +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef MBGL_UTIL_PNG_READER_HPP -#define MBGL_UTIL_PNG_READER_HPP - -#include <mbgl/platform/default/image_reader.hpp> - -extern "C" -{ -#include <png.h> -} - -#include <cstring> -#include <memory> - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunknown-pragmas" -#pragma GCC diagnostic ignored "-Wunused-local-typedefs" -#pragma GCC diagnostic ignored "-Wshadow" -#include <boost/iostreams/stream.hpp> -#pragma GCC diagnostic pop - -namespace mbgl { namespace util { - -template <typename T> -class PngReader : public ImageReader -{ - using source_type = T; - using input_stream = boost::iostreams::stream<source_type>; - - struct png_struct_guard - { - png_struct_guard(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) - : p_(png_ptr_ptr), - i_(info_ptr_ptr) {} - - ~png_struct_guard() - { - png_destroy_read_struct(p_,i_,0); - } - png_structpp p_; - png_infopp i_; - }; - -private: - source_type source_; - input_stream stream_; - unsigned width_; - unsigned height_; - int bit_depth_; - int color_type_; - bool has_alpha_; -public: - PngReader(const uint8_t* data, std::size_t size); - ~PngReader(); - unsigned width() const; - unsigned height() const; - std::unique_ptr<uint8_t[]> read(); -private: - void init(); - static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length); -}; - - -}} - -#endif // MBGL_UTIL_PNG_READER_HPP |