| 46 | |
| 47 | template <typename T> |
| 48 | void save_image(numpy_image<T> img, const std::string &path, const float quality) |
| 49 | { |
| 50 | std::string lowered_path = path; |
| 51 | std::transform(lowered_path.begin(), lowered_path.end(), lowered_path.begin(), ::tolower); |
| 52 | std::string error_message = "Unsupported image type, image path must end with one of [.bmp, .dng"; |
| 53 | #if DLIB_PNG_SUPPORT |
| 54 | error_message += ", .png"; |
| 55 | #endif |
| 56 | #if DLIB_JPEG_SUPPORT |
| 57 | error_message += ", .jpg, jpeg"; |
| 58 | #endif |
| 59 | #if DLIB_WEBP_SUPPORT |
| 60 | error_message += ", .webp"; |
| 61 | #endif |
| 62 | #if DLIB_JXL_SUPPORT |
| 63 | error_message += ", .jxl"; |
| 64 | #endif |
| 65 | error_message += "]"; |
| 66 | |
| 67 | if(has_ending(lowered_path, ".bmp")) { |
| 68 | save_bmp(img, path); |
| 69 | } else if(has_ending(lowered_path, ".dng")) { |
| 70 | save_dng(img, path); |
| 71 | #if DLIB_PNG_SUPPORT |
| 72 | } else if(has_ending(lowered_path, ".png")) { |
| 73 | save_png(img, path); |
| 74 | #endif |
| 75 | #if DLIB_JPEG_SUPPORT |
| 76 | } else if(has_ending(lowered_path, ".jpg") || has_ending(lowered_path, ".jpeg")) { |
| 77 | save_jpeg(img, path, put_in_range(0, 100, std::lround(quality))); |
| 78 | #endif |
| 79 | #if DLIB_WEBP_SUPPORT |
| 80 | } else if(has_ending(lowered_path, ".webp")) { |
| 81 | save_webp(img, path, std::max(0.f, quality)); |
| 82 | #endif |
| 83 | #if DLIB_JXL_SUPPORT |
| 84 | } else if(has_ending(lowered_path, ".jxl")) { |
| 85 | save_jxl(img, path, put_in_range(0, 100, quality)); |
| 86 | #endif |
| 87 | } else { |
| 88 | throw dlib::error(error_message); |
| 89 | } |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | // ---------------------------------------------------------------------------------------- |
| 94 |
nothing calls this directly
no test coverage detected