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

Function af_load_image_native

src/api/c/imageio2.cpp:136–327  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

134////////////////////////////////////////////////////////////////////////////////
135// Load image from disk.
136af_err af_load_image_native(af_array* out, const char* filename) {
137 try {
138 ARG_ASSERT(1, filename != NULL);
139
140 FreeImage_Module& _ = getFreeImagePlugin();
141
142 // set your own FreeImage error handler
143 _.FreeImage_SetOutputMessage(FreeImageErrorHandler);
144
145 // try to guess the file format from the file extension
146 FREE_IMAGE_FORMAT fif = _.FreeImage_GetFileType(filename, 0);
147 if (fif == FIF_UNKNOWN) {
148 fif = _.FreeImage_GetFIFFromFilename(filename);
149 }
150
151 if (fif == FIF_UNKNOWN) {
152 AF_ERROR("FreeImage Error: Unknown File or Filetype",
153 AF_ERR_NOT_SUPPORTED);
154 }
155
156 unsigned flags = 0;
157 if (fif == FIF_JPEG) {
158 flags = flags | static_cast<unsigned>(JPEG_ACCURATE);
159 }
160
161 // check that the plugin has reading capabilities ...
162 bitmap_ptr pBitmap = make_bitmap_ptr(nullptr);
163 if (_.FreeImage_FIFSupportsReading(fif)) {
164 pBitmap.reset(
165 _.FreeImage_Load(fif, filename, static_cast<int>(flags)));
166 }
167
168 if (pBitmap == NULL) {
169 AF_ERROR(
170 "FreeImage Error: Error reading image or file does not exist",
171 AF_ERR_RUNTIME);
172 }
173
174 // check image color type
175 uint color_type = _.FreeImage_GetColorType(pBitmap.get());
176 const uint fi_bpp = _.FreeImage_GetBPP(pBitmap.get());
177 // int fi_color = (int)((fi_bpp / 8.0) + 0.5); //ceil
178 uint fi_color;
179 switch (color_type) {
180 case 0: // FIC_MINISBLACK
181 case 1: // FIC_MINISWHITE
182 fi_color = 1;
183 break;
184 case 2: // FIC_PALETTE
185 case 3: // FIC_RGB
186 fi_color = 3;
187 break;
188 case 4: // FIC_RGBALPHA
189 case 5: // FIC_CMYK
190 fi_color = 4;
191 break;
192 default: // Should not come here
193 fi_color = 3;

Callers 2

cannyImageOtsuTestFunction · 0.50
loadImageNativeFunction · 0.50

Calls 4

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

Tested by

no test coverage detected