This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:mapbox/mapbox-gl-native
- Loading branch information
Showing
16 changed files
with
707 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef MBGL_UTIL_IMAGE_READER_HPP | ||
#define MBGL_UTIL_IMAGE_READER_HPP | ||
|
||
#include <mbgl/util/std.hpp> | ||
#include <mbgl/util/noncopyable.hpp> | ||
// stl | ||
#include <stdexcept> | ||
#include <string> | ||
|
||
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 bool hasAlpha() const=0; | ||
virtual bool premultipliedAlpha() const=0; | ||
virtual void read(unsigned x,unsigned y, unsigned width, unsigned height, char* image)=0; | ||
virtual ~ImageReader() {} | ||
}; | ||
|
||
std::unique_ptr<ImageReader> getImageReader(char const* data, size_t size); | ||
|
||
}} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#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> | ||
} | ||
|
||
#include <boost/iostreams/stream.hpp> | ||
|
||
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(char const* 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); | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#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> | ||
|
||
#include <boost/iostreams/stream.hpp> | ||
|
||
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(char const* 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); | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.