| 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 | |
| 75 | for (int r = 0; r < height_; r++) |
| 76 | { |
| 77 | for (int c = 0; c < width_; c++) |
| 78 | { |
| 79 | assign_pixel(vimg[r][c], decoded[r][c]); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | void get_info(); |
no test coverage detected