0

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.

felipou
  • 654
  • 6
  • 16
  • I just tested it with an equivalent Objective-C snippet and the result was exactly the same. – felipou Nov 25 '15 at 15:46
  • Ok, now I just tested a random JPEG file, and had the exact same results! Then I tested with Google's logo URL: https://www.google.com.br/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png and still it didn't work! Something nasty is going on here... – felipou Nov 25 '15 at 15:53
  • Hi, did you get anywhere with this? I am seeing the same issue as this where I can load from the URL but not from the data. My guess is that when loading raw photos it needs the file extension to give it a hint as to what it's looking at and what algorithm to use. If this is the case then loading RAW images will only work when using the url. This is just my guess though I have no idea what's going on – 0C3D Aug 06 '19 at 01:48

0 Answers0