MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / af_load_image

Function af_load_image

src/api/c/imageio.cpp:234–530  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// File IO /////////////////////////////////////////////////////////////////////////// Load image from disk.

Source from the content-addressed store, hash-verified

232////////////////////////////////////////////////////////////////////////////////
233// Load image from disk.
234af_err af_load_image(af_array* out, const char* filename, const bool isColor) {
235 using arrayfire::readImage;
236 try {
237 ARG_ASSERT(1, filename != NULL);
238
239 FreeImage_Module& _ = getFreeImagePlugin();
240
241 // set your own FreeImage error handler
242 _.FreeImage_SetOutputMessage(FreeImageErrorHandler);
243
244 // try to guess the file format from the file extension
245 FREE_IMAGE_FORMAT fif = _.FreeImage_GetFileType(filename, 0);
246 if (fif == FIF_UNKNOWN) {
247 fif = _.FreeImage_GetFIFFromFilename(filename);
248 }
249
250 if (fif == FIF_UNKNOWN) {
251 AF_ERROR("FreeImage Error: Unknown File or Filetype",
252 AF_ERR_NOT_SUPPORTED);
253 }
254
255 unsigned flags = 0;
256 if (fif == FIF_JPEG) {
257 flags = flags | static_cast<unsigned>(JPEG_ACCURATE);
258 }
259#ifdef JPEG_GREYSCALE
260 if (fif == FIF_JPEG && !isColor) {
261 flags = flags | static_cast<unsigned>(JPEG_GREYSCALE);
262 }
263#endif
264
265 // check that the plugin has reading capabilities ...
266 bitmap_ptr pBitmap = make_bitmap_ptr(NULL);
267 if (_.FreeImage_FIFSupportsReading(fif)) {
268 pBitmap.reset(
269 _.FreeImage_Load(fif, filename, static_cast<int>(flags)));
270 }
271
272 if (pBitmap == NULL) {
273 AF_ERROR(
274 "FreeImage Error: Error reading image or file does not exist",
275 AF_ERR_RUNTIME);
276 }
277
278 // check image color type
279 uint color_type = _.FreeImage_GetColorType(pBitmap.get());
280 const uint fi_bpp = _.FreeImage_GetBPP(pBitmap.get());
281 // int fi_color = (int)((fi_bpp / 8.0) + 0.5); //ceil
282 uint fi_color;
283 switch (color_type) {
284 case 0: // FIC_MINISBLACK
285 case 1: // FIC_MINISWHITE
286 fi_color = 1;
287 break;
288 case 2: // FIC_PALETTE
289 case 3: // FIC_RGB
290 fi_color = 3;
291 break;

Callers 15

iterDeconvImageTestFunction · 0.50
homographyTestFunction · 0.50
bilateralTestFunction · 0.50
invDeconvImageTestFunction · 0.50
glohTestFunction · 0.50
harrisTestFunction · 0.50
siftTestFunction · 0.50
cannyImageOtsuTestFunction · 0.50
loadImageTestFunction · 0.50
loadimageArgsTestFunction · 0.50
orbTestFunction · 0.50
medfiltImageTestFunction · 0.50

Calls 4

make_bitmap_ptrFunction · 0.85
swapFunction · 0.85
resetMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected