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

Function load_image

dlib/image_loader/load_image.h:81–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79
80 template <typename image_type>
81 void load_image (
82 image_type& image,
83 const std::string& file_name
84 )
85 {
86 const image_file_type::type im_type = image_file_type::read_type(file_name);
87 switch (im_type)
88 {
89 case image_file_type::BMP: load_bmp(image, file_name); return;
90 case image_file_type::DNG: load_dng(image, file_name); return;
91#ifdef DLIB_PNG_SUPPORT
92 case image_file_type::PNG: load_png(image, file_name); return;
93#endif
94#ifdef DLIB_JPEG_SUPPORT
95 case image_file_type::JPG: load_jpeg(image, file_name); return;
96#endif
97#ifdef DLIB_WEBP_SUPPORT
98 case image_file_type::WEBP: load_webp(image, file_name); return;
99#endif
100#ifdef DLIB_JXL_SUPPORT
101 case image_file_type::JXL: load_jxl(image, file_name); return;
102#endif
103#ifdef DLIB_GIF_SUPPORT
104 case image_file_type::GIF:
105 {
106 image_view<image_type> img(image);
107 GifFileType* gif = DGifOpenFileName(file_name.c_str() DLIB_GIFLIB_HANDLE_DIFF_VERSIONS);
108 try
109 {
110 if (gif == 0) throw image_load_error("Couldn't open file " + file_name);
111 if (DGifSlurp(gif) != GIF_OK)
112 throw image_load_error("Error reading from " + file_name);
113
114 if (gif->ImageCount != 1) throw image_load_error("Dlib only supports reading GIF files containing one image.");
115 if (gif->SavedImages == 0) throw image_load_error("Unsupported GIF format 1.");
116
117 ColorMapObject* cmo=gif->SColorMap?gif->SColorMap:gif->SavedImages->ImageDesc.ColorMap;
118
119 if (cmo==0) throw image_load_error("Unsupported GIF format 2.");
120 if (cmo->Colors == 0) throw image_load_error("Unsupported GIF format 3.");
121 if (gif->SavedImages->ImageDesc.Width != gif->SWidth) throw image_load_error("Unsupported GIF format 4.");
122 if (gif->SavedImages->ImageDesc.Height != gif->SHeight) throw image_load_error("Unsupported GIF format 5.");
123 if (gif->SavedImages->RasterBits == 0) throw image_load_error("Unsupported GIF format 6.");
124 if (gif->Image.Top != 0) throw image_load_error("Unsupported GIF format 7.");
125 if (gif->Image.Left != 0) throw image_load_error("Unsupported GIF format 8.");
126
127 img.set_size(gif->SHeight, gif->SWidth);
128 unsigned char* raster = gif->SavedImages->RasterBits;
129 GifColorType* colormap = cmo->Colors;
130 if (gif->Image.Interlace)
131 {
132 const long interlaced_offset[] = { 0, 4, 2, 1 };
133 const long interlaced_jumps[] = { 8, 8, 4, 2 };
134 for (int i = 0; i < 4; ++i)
135 {
136 for (long r = interlaced_offset[i]; r < img.nr(); r += interlaced_jumps[i])
137 {
138 for (long c = 0; c < img.nc(); ++c)

Callers

nothing calls this directly

Calls 13

read_typeFunction · 0.85
load_bmpFunction · 0.85
load_dngFunction · 0.85
load_pngFunction · 0.85
load_jpegFunction · 0.85
load_webpFunction · 0.85
load_jxlFunction · 0.85
assign_pixelFunction · 0.85
image_load_errorClass · 0.70
set_sizeMethod · 0.45
nrMethod · 0.45
ncMethod · 0.45

Tested by

no test coverage detected