90 if (!imageURL || !strlen(imageURL))
94 unsigned int dataLength;
101 FIMEMORY *hmem = FreeImage_OpenMemory((BYTE *)data, dataLength);
103 FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem, 0);
104 if (fif == FIF_UNKNOWN)
107 CFDataRef cfd = CFDataCreateWithBytesNoCopy(
nullptr, (UInt8 *)data, dataLength, kCFAllocatorNull);
110 CGImageSourceRef cgis = CGImageSourceCreateWithData(cfd,
nullptr);
114 size_t imageIndex = 0;
115 CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(cgis, imageIndex,
nullptr);
116 int32_t orientation = kCGImagePropertyOrientationUp;
119 CFNumberRef orientationCF =
static_cast<CFNumberRef
>(CFDictionaryGetValue(properties, kCGImagePropertyOrientation));
120 CFNumberGetValue(orientationCF, kCFNumberSInt32Type, &orientation);
121 CFRelease(properties);
124 CGImageRef cgi = CGImageSourceCreateImageAtIndex(cgis, imageIndex,
nullptr);
132 FreeImage_CloseMemory(hmem);
135 if (orientation != kCGImagePropertyOrientationUp)
141 if (orientation == kCGImagePropertyOrientationDown)
142 angleInDegrees = 180;
143 else if (orientation == kCGImagePropertyOrientationLeft)
145 else if (orientation == kCGImagePropertyOrientationRight)
146 angleInDegrees = -90;
159 VUserLog(
"Error: '%s': FreeImage couldn't determine the image type. The file might not be an image, or it might be corrupted.", imageURL);
160 FreeImage_CloseMemory(hmem);
164 if (!FreeImage_FIFSupportsReading(fif))
166 VUserLog(
"Error: '%s': FreeImage can't read this type of image.", imageURL);
167 FreeImage_CloseMemory(hmem);
172 dib = FreeImage_LoadFromMemory(fif, hmem, JPEG_EXIFROTATE);
173 FreeImage_CloseMemory(hmem);
177 VUserLog(
"Error: '%s': FreeImage couldn't read this image. The file might be corrupted.", imageURL);