@@ -196,7 +196,7 @@ static int getJpegOptionFromImageLoadSetting(const ofImageLoadSettings &settings
196196}
197197
198198template <typename PixelType>
199- static bool loadImage (ofPixels_<PixelType> & pix, const of::filesystem::path& _fileName, const ofImageLoadSettings& settings){
199+ static bool loadImage (ofPixels_<PixelType> & pix, const of::filesystem::path & _fileName, const ofImageLoadSettings & settings){
200200 ofInitFreeImage ();
201201
202202 auto uriStr = _fileName.string ();
@@ -225,23 +225,34 @@ static bool loadImage(ofPixels_<PixelType> & pix, const of::filesystem::path& _f
225225 return ofLoadImage (pix, ofLoadURL (_fileName.string ()).data );
226226 }
227227
228- auto fileName = ofToDataPath (_fileName, true );
228+ auto fileName = ofToDataPathFS (_fileName, true );
229229 bool bLoaded = false ;
230230 FIBITMAP * bmp = nullptr ;
231231
232232 FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
233+ #ifdef OF_OS_WINDOWS
234+ fif = FreeImage_GetFileTypeU (fileName.c_str (), 0 );
235+ #else
233236 fif = FreeImage_GetFileType (fileName.c_str (), 0 );
237+ #endif
234238 if (fif == FIF_UNKNOWN) {
235239 // or guess via filename
236- fif = FreeImage_GetFIFFromFilename (fileName.c_str ());
240+ #ifdef OF_OS_WINDOWS
241+ fif = FreeImage_GetFIFFromFilenameU (_fileName.extension ().c_str ());
242+ #else
243+ fif = FreeImage_GetFIFFromFilename (_fileName.extension ().c_str ());
244+ #endif
237245 }
238246 if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading (fif)) {
247+ int option = 0 ;
239248 if (fif == FIF_JPEG) {
240- int option = getJpegOptionFromImageLoadSetting (settings);
241- bmp = FreeImage_Load (fif, fileName.c_str (), option | settings.freeImageFlags );
242- } else {
243- bmp = FreeImage_Load (fif, fileName.c_str (), 0 | settings.freeImageFlags );
249+ option = getJpegOptionFromImageLoadSetting (settings);
244250 }
251+ #ifdef OF_OS_WINDOWS
252+ bmp = FreeImage_LoadU (fif, fileName.c_str (), option | settings.freeImageFlags );
253+ #else
254+ bmp = FreeImage_Load (fif, fileName.c_str (), option | settings.freeImageFlags );
255+ #endif
245256
246257 if (bmp != nullptr ){
247258 bLoaded = true ;
@@ -284,12 +295,11 @@ static bool loadImage(ofPixels_<PixelType> & pix, const ofBuffer & buffer, const
284295
285296
286297 // make the image!!
298+ int option = 0 ;
287299 if (fif == FIF_JPEG) {
288- int option = getJpegOptionFromImageLoadSetting (settings);
289- bmp = FreeImage_LoadFromMemory (fif, hmem, option | settings.freeImageFlags );
290- } else {
291- bmp = FreeImage_LoadFromMemory (fif, hmem, settings.freeImageFlags );
300+ option = getJpegOptionFromImageLoadSetting (settings);
292301 }
302+ bmp = FreeImage_LoadFromMemory (fif, hmem, option | settings.freeImageFlags );
293303
294304 if ( bmp != nullptr ){
295305 bLoaded = true ;
@@ -313,37 +323,37 @@ static bool loadImage(ofPixels_<PixelType> & pix, const ofBuffer & buffer, const
313323}
314324
315325// ----------------------------------------------------------------
316- bool ofLoadImage (ofPixels & pix, const of::filesystem::path& path, const ofImageLoadSettings &settings) {
326+ bool ofLoadImage (ofPixels & pix, const of::filesystem::path & path, const ofImageLoadSettings & settings) {
317327 return loadImage (pix, path, settings);
318328}
319329
320330// ----------------------------------------------------------------
321- bool ofLoadImage (ofPixels & pix, const ofBuffer & buffer, const ofImageLoadSettings &settings) {
331+ bool ofLoadImage (ofPixels & pix, const ofBuffer & buffer, const ofImageLoadSettings & settings) {
322332 return loadImage (pix, buffer, settings);
323333}
324334
325335// ----------------------------------------------------------------
326- bool ofLoadImage (ofShortPixels & pix, const of::filesystem::path& path, const ofImageLoadSettings &settings) {
336+ bool ofLoadImage (ofShortPixels & pix, const of::filesystem::path & path, const ofImageLoadSettings & settings) {
327337 return loadImage (pix, path, settings);
328338}
329339
330340// ----------------------------------------------------------------
331- bool ofLoadImage (ofShortPixels & pix, const ofBuffer & buffer, const ofImageLoadSettings &settings) {
341+ bool ofLoadImage (ofShortPixels & pix, const ofBuffer & buffer, const ofImageLoadSettings & settings) {
332342 return loadImage (pix, buffer, settings);
333343}
334344
335345// ----------------------------------------------------------------
336- bool ofLoadImage (ofFloatPixels & pix, const of::filesystem::path& path, const ofImageLoadSettings &settings) {
346+ bool ofLoadImage (ofFloatPixels & pix, const of::filesystem::path & path, const ofImageLoadSettings & settings) {
337347 return loadImage (pix, path, settings);
338348}
339349
340350// ----------------------------------------------------------------
341- bool ofLoadImage (ofFloatPixels & pix, const ofBuffer & buffer, const ofImageLoadSettings &settings) {
351+ bool ofLoadImage (ofFloatPixels & pix, const ofBuffer & buffer, const ofImageLoadSettings & settings) {
342352 return loadImage (pix, buffer, settings);
343353}
344354
345355// ----------------------------------------------------------------
346- bool ofLoadImage (ofTexture & tex, const of::filesystem::path& path, const ofImageLoadSettings &settings ) {
356+ bool ofLoadImage (ofTexture & tex, const of::filesystem::path & path, const ofImageLoadSettings & settings ) {
347357 return ofLoadImage ( tex, path, false , settings );
348358}
349359
@@ -404,20 +414,28 @@ static bool saveImage(const ofPixels_<PixelType> & _pix, const of::filesystem::p
404414 }
405415
406416 ofFilePath::createEnclosingDirectory (_fileName);
407- auto fileName = ofToDataPath (_fileName);
417+ auto fileName = ofToDataPathFS (_fileName);
408418 FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
419+ #ifdef OF_OS_WINDOWS
420+ fif = FreeImage_GetFileTypeU (fileName.c_str (), 0 );
421+ #else
409422 fif = FreeImage_GetFileType (fileName.c_str (), 0 );
423+ #endif
410424 if (fif == FIF_UNKNOWN) {
411425 // or guess via filename
412- fif = FreeImage_GetFIFFromFilename (fileName.c_str ());
426+ #ifdef OF_OS_WINDOWS
427+ fif = FreeImage_GetFIFFromFilenameU (_fileName.extension ().c_str ());
428+ #else
429+ fif = FreeImage_GetFIFFromFilename (_fileName.extension ().c_str ());
430+ #endif
413431 }
414432 if (fif==FIF_JPEG && (_pix.getNumChannels ()==4 || _pix.getBitsPerChannel () > 8 )){
415433 ofPixels pix3 = _pix;
416434 if ( pix3.getPixelFormat () == OF_PIXELS_BGRA ){
417435 pix3.swapRgb ();
418436 }
419437 pix3.setNumChannels (3 );
420- return saveImage (pix3,_fileName,qualityLevel);
438+ return saveImage (pix3, _fileName, qualityLevel);
421439 }
422440
423441 FIBITMAP * bmp = nullptr ;
@@ -447,11 +465,15 @@ static bool saveImage(const ofPixels_<PixelType> & _pix, const of::filesystem::p
447465 case OF_IMAGE_QUALITY_HIGH: quality = JPEG_QUALITYGOOD; break ;
448466 case OF_IMAGE_QUALITY_BEST: quality = JPEG_QUALITYSUPERB; break ;
449467 }
468+ #ifdef OF_OS_WINDOWS
469+ retValue = FreeImage_SaveU (fif, bmp, fileName.c_str (), quality);
470+ #else
450471 retValue = FreeImage_Save (fif, bmp, fileName.c_str (), quality);
472+ #endif
451473 } else {
452474 if (qualityLevel != OF_IMAGE_QUALITY_BEST) {
453475 ofLogWarning (" ofImage" ) << " saveImage(): ofImageCompressionType only applies to JPEGs,"
454- << " ignoring value for \" " << fileName << " \" " ;
476+ << " ignoring value for " << _fileName ;
455477 }
456478
457479 if (fif == FIF_GIF) {
@@ -463,12 +485,20 @@ static bool saveImage(const ofPixels_<PixelType> & _pix, const of::filesystem::p
463485 // this will create a 256-color palette from the image
464486 convertedBmp = FreeImage_ColorQuantize (bmp, FIQ_NNQUANT);
465487 }
488+ #ifdef OF_OS_WINDOWS
489+ retValue = FreeImage_SaveU (fif, convertedBmp, fileName.c_str ());
490+ #else
466491 retValue = FreeImage_Save (fif, convertedBmp, fileName.c_str ());
492+ #endif
467493 if (convertedBmp != nullptr ){
468494 FreeImage_Unload (convertedBmp);
469495 }
470496 } else {
497+ #ifdef OF_OS_WINDOWS
498+ retValue = FreeImage_SaveU (fif, bmp, fileName.c_str ());
499+ #else
471500 retValue = FreeImage_Save (fif, bmp, fileName.c_str ());
501+ #endif
472502 }
473503 }
474504 }
@@ -746,14 +776,14 @@ bool ofImage_<PixelType>::loadImage(const ofFile & file){
746776
747777// ----------------------------------------------------------
748778template <typename PixelType>
749- bool ofImage_<PixelType>::load (const of::filesystem::path& fileName, const ofImageLoadSettings &settings){
779+ bool ofImage_<PixelType>::load (const of::filesystem::path & fileName, const ofImageLoadSettings & settings){
750780 #if defined(TARGET_ANDROID)
751781 ofAddListener (ofxAndroidEvents ().unloadGL ,this ,&ofImage_<PixelType>::unloadTexture);
752782 ofAddListener (ofxAndroidEvents ().reloadGL ,this ,&ofImage_<PixelType>::update);
753783 #endif
754784 bool bLoadedOk = ofLoadImage (pixels, fileName, settings);
755785 if (!bLoadedOk) {
756- ofLogError (" ofImage" ) << " loadImage(): couldn't load image from " << fileName << " " ;
786+ ofLogError (" ofImage" ) << " loadImage(): couldn't load image from " << fileName;
757787 clear ();
758788 return false ;
759789 }
0 commit comments