I've trying to open LinearDNG file in my MacOS app.
As far as I've investigated, that's not possible with CoreImage.
So, the questions:
- Is it possible to open
LinearDNGfile as 16-bit/8-bit RGBA data withCoreImage? - Is it possible to open
LinearDNGfile as 16-bit/8-bit RGBA data withdcraw? - Do you know the other libs to open
LinearDNGfile as 16-bit/8-bit RGBA data?
My LinearDNG files are 16-bit. The relevant EXIF data:
File Type : DNG
File Type Extension : dng
MIME Type : image/x-adobe-dng
Bits Per Sample : 16 16 16
Compression : Uncompressed
Photometric Interpretation : Linear Raw
Format : image/jpeg
I've read that CIContext can convert an image to TIFF/JPEG, but code with this particular LinearDNG file doesn't work.
All JPEG images are black, all TIFF images are transparent.
I guess CIImage just doesn't understand this encoding.
My testing code:
[self convertLinearDNGToJPEG:@"super_jpeg.jpeg"];
[self convertLinearDNGToTIFF:kCIFormatRGBA8 fileName:@"super_kCIFormatRGBA8.tiff"];
[self convertLinearDNGToTIFF:kCIFormatRGBA16 fileName:@"super_kCIFormatRGBA16.tiff"];
[self convertLinearDNGToTIFF:kCIFormatARGB8 fileName:@"super_kCIFormatARGB8.tiff"];
[self convertLinearDNGToTIFF:kCIFormatRGBAh fileName:@"super_kCIFormatRGBAh.tiff"];
The corresponding functions (convertLinearDNGToTIFF/convertLinearDNGToJPEG ):
- (void)convertLinearDNGToJPEG:(NSString*)fileName
{
CIImage* inputImage = [self createInputImage];
NSError* superError = nil;
CIContext* ciContext = [self createCiContext];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL* superURL = [NSURL fileURLWithPath: [documentsDirectory stringByAppendingPathComponent:fileName] ];
CGColorSpaceRef superColorSpace = CGColorSpaceCreateDeviceRGB();
[ciContext writeJPEGRepresentationOfImage:inputImage
toURL:superURL
colorSpace:superColorSpace
options:@{} // CIImageRepresentationOption
error:&superError];
}
- (void)convertLinearDNGToTIFF:(CIFormat)format fileName:(NSString*)fileName
{
CIImage* inputImage = [self createInputImage];
NSError* superError = nil;
CIContext* ciContext = [self createCiContext];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL* superURL = [NSURL fileURLWithPath: [documentsDirectory stringByAppendingPathComponent:fileName] ];
CGColorSpaceRef superColorSpace = CGColorSpaceCreateDeviceRGB();
[ciContext writeTIFFRepresentationOfImage:inputImage
toURL:superURL
format:format
colorSpace:superColorSpace
options:@{} // CIImageRepresentationOption
error:&superError];
}
Well, I've tried LibRaw: https://github.com/LibRaw/LibRaw. It's able to export my
LinearDNGto TIFF. And I can open TIFF withCoreImage. The white balance is wrong though. I assume this is becauselibrawreads metadata wrong ( filesamples/raw-identify.cpp).The code for exporting to TIFF is in file
samples/simple_dcraw.cpp