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

Function save_image

tools/python/src/numpy_returns.cpp:48–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46
47template <typename T>
48void 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

Callers

nothing calls this directly

Calls 12

has_endingFunction · 0.85
save_bmpFunction · 0.85
save_dngFunction · 0.85
save_pngFunction · 0.85
put_in_rangeFunction · 0.85
save_webpFunction · 0.85
save_jxlFunction · 0.85
errorClass · 0.85
save_jpegFunction · 0.50
maxFunction · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected