MCPcopy Create free account
hub / github.com/davisking/dlib / webp_loader

Class webp_loader

dlib/image_loader/webp_loader.h:17–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15{
16
17 class webp_loader : noncopyable
18 {
19 public:
20
21 webp_loader(const char* filename);
22 webp_loader(const std::string& filename);
23 webp_loader(const dlib::file& f);
24 webp_loader(const unsigned char* imgbuffer, size_t buffersize);
25
26 long nr() const;
27 long nc() const;
28
29 template<typename image_type>
30 void get_image(image_type& image) const
31 {
32#ifndef DLIB_WEBP_SUPPORT
33 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34 You are getting this error because you are trying to use the webp_loader
35 object but you haven't defined DLIB_WEBP_SUPPORT. You must do so to use
36 this object. You must also make sure you set your build environment
37 to link against the libwebp library.
38 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
39 static_assert(sizeof(image_type) == 0, "webp support not enabled.");
40#endif
41 image_view<image_type> vimg(image);
42 vimg.set_size(height_, width_);
43 typedef typename image_traits<image_type>::pixel_type pixel_type;
44
45 unsigned char* output = reinterpret_cast<unsigned char*>(image_data(vimg));
46 const int stride = width_step(vimg);
47 const size_t output_size = stride * height_;
48
49 if (pixel_traits<pixel_type>::rgb_alpha)
50 {
51 if (pixel_traits<pixel_type>::bgr_layout)
52 read_bgra(output, output_size, stride);
53 else
54 read_rgba(output, output_size, stride);
55 return;
56 }
57 if (pixel_traits<pixel_type>::rgb)
58 {
59 if (pixel_traits<pixel_type>::bgr_layout)
60 read_bgr(output, output_size, stride);
61 else
62 read_rgb(output, output_size, stride);
63 return;
64 }
65 // If we end up here, we are out of our fast path, and have to do it manually
66
67 array2d<rgb_alpha_pixel> decoded;
68 decoded.set_size(height_, width_);
69 unsigned char* output_dec = reinterpret_cast<unsigned char*>(image_data(decoded));
70 const int stride_dec = width_step(decoded);
71 const size_t output_dec_size = stride_dec * height_;
72
73 read_rgba(output_dec, output_dec_size, stride_dec);
74

Callers 1

load_webpFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected