I have a little script written in Swift that I used to manipulate some RAW images, and it worked wonders until some previous version of Xcode (I don't remember exactly which was the last one, but I know it worked with version 7.0, because I converted it to Swift 2 and tested it).
But when I tried to run it today, it wasn't working. I isolated the problem in a little snippet:
let turl = NSURL(string: "file:///some/random/path/IMG_5467.CR2")!
let tdata = NSData(contentsOfURL: turl)
print ("data size = \( tdata!.length )")
//let imageSource = CGImageSourceCreateWithURL( turl, nil );
let imageSource = CGImageSourceCreateWithData(tdata!, nil);
print( "StatusComplete = \(CGImageSourceStatus.StatusComplete.rawValue)" );
print( "StatusUnknownType = \(CGImageSourceStatus.StatusUnknownType.rawValue)" );
print( "URL: \(turl) - \(imageSource) - status \( CGImageSourceGetStatus(imageSource!).rawValue )" );
print( "count \( CGImageSourceGetCount(imageSource!) )" );
print( "status 0 \( CGImageSourceGetStatusAtIndex(imageSource!, 0).rawValue )" );
print( "type \( CGImageSourceGetType( imageSource! ) )" );
print( "Supported types: \( CGImageSourceCopyTypeIdentifiers() )" )
exit(1)
And this is the resulting output:
data size = 24730146
StatusComplete = 0
StatusUnknownType = -3
URL: file:///some/random/path/IMG_5467.CR2 - Optional(<CGImageSource 0x7fd51a40d2d0 [0x7fff7763ded0]>) - status -3
count 0
status 0 -3
type nil
When I try loading the image through the URL directly (using CGImageSourceCreateWithURL
), the image source status is 0 (StatusComplete), but the status in index 0 is also -3 (StatusUnknownType). Another difference is that the type is "com.canon.cr2-raw-image" when loading with the URL.
The data size is correct, the URL so the URL is correct and the file is being loaded correctly. I'll try to load the file using Objective-C now, just to confirm it's not a problem with Swift itself.
Any ideas? I tried both new and already tested RAW images files.