Turi Create  4.0
io.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_IMAGE_IO_IMPL_HPP
7 #define TURI_IMAGE_IO_IMPL_HPP
8 
9 #include <string>
10 #include <core/data/image/image_type.hpp>
11 
12 namespace turi {
13 /**
14  * Write the pixels into file as jpeg
15  * Only works with local files.
16  */
17 void write_image(const std::string& filename, char* data, size_t width, size_t height, size_t channels, Format format);
18 
19 /**
20  * Read the content from url and return an image type object.
21  * Throws an exception if failing to decode as format_hint.
22  */
23 image_type read_image(const std::string& url, const std::string& format_hint);
24 
25 /**
26  * Read raw image data from URL, store data in data and length. Store image information such as width, height, channels, and format.
27  */
28 void read_raw_image(const std::string& url, char** data, size_t& length, size_t& width, size_t& height, size_t& channels, Format& format, const std::string& format_hint);
29 
30 /**
31  * Parse the image information, set width, height and channels using libjpeg.
32  */
33 void parse_jpeg(const char* data, size_t length,
34  size_t& width, size_t& height, size_t& channels);
35 
36 void decode_jpeg(const char* data, size_t length, char** decoded_data, size_t& out_length);
37 
38 /**
39  * Parse the image information, set width, height and channels using libpng.
40  */
41 void parse_png(const char* data, size_t length,
42  size_t& width, size_t& height, size_t& channels);
43 
44 void decode_png(const char* data, size_t length, char** decoded_data, size_t& out_length);
45 
46 void encode_png(const char* data, size_t width, size_t height, size_t channels, char** out_data, size_t& out_length);
47 /**************************************************************************/
48 /* */
49 /* Prototype Code */
50 /* */
51 /**************************************************************************/
52 /**
53  * Parse the image information, set width, height and channels using boost_gil.
54  */
55 void boost_parse_image(std::string filename, size_t& width, size_t& height, size_t& channels, Format& format, size_t& image_data_size, std::string format_string);
56 
57 /**
58  * Read the content of jpeg image and return the pixel array into out_data
59  * Only works with local files.
60  */
61 void boost_read_image(std::string filename, char** out_data, size_t& width, size_t& height, size_t& channels, Format& format, size_t& image_data_size, std::string format_string);
62 
63 }
64 #endif
void write_image(const std::string &filename, char *data, size_t width, size_t height, size_t channels, Format format)
image_type read_image(const std::string &url, const std::string &format_hint)
void boost_parse_image(std::string filename, size_t &width, size_t &height, size_t &channels, Format &format, size_t &image_data_size, std::string format_string)
void boost_read_image(std::string filename, char **out_data, size_t &width, size_t &height, size_t &channels, Format &format, size_t &image_data_size, std::string format_string)
void parse_jpeg(const char *data, size_t length, size_t &width, size_t &height, size_t &channels)
void read_raw_image(const std::string &url, char **data, size_t &length, size_t &width, size_t &height, size_t &channels, Format &format, const std::string &format_hint)
void parse_png(const char *data, size_t length, size_t &width, size_t &height, size_t &channels)