ALAssetRepresentation में XMP-Metadata की व्याख्या करें


95

जब कोई उपयोगकर्ता iOS में अंतर्निहित Photos.app में फ़ोटो में कुछ बदलाव (क्रॉपिंग, रेड-आई रिमूव , ...) करता है , तो परिवर्तन fullResolutionImageसंबंधित द्वारा दिए गए पर लागू नहीं होते हैं ALAssetRepresentation

हालाँकि, परिवर्तन लागू होते हैं thumbnailऔर fullScreenImageद्वारा लौटा दिए जाते हैं ALAssetRepresentation। इसके अलावा, लागू परिवर्तनों के बारे में जानकारी ALAssetRepresentationकुंजी के माध्यम से मेटाडेटा शब्दकोश में पाई जा सकती है @"AdjustmentXMP"

मैं fullResolutionImageखुद को निरंतरता बनाए रखने के लिए इन परिवर्तनों को लागू करना चाहूंगा । मुझे पता चला है कि पर iOS6 + CIFilter की filterArrayFromSerializedXMP: inputImageExtent:error:की एक सरणी को यह XMP-मेटाडाटा में बदल सकते हैं CIFilterकी:

ALAssetRepresentation *rep; 
NSString *xmpString = rep.metadata[@"AdjustmentXMP"];
NSData *xmpData = [xmpString dataUsingEncoding:NSUTF8StringEncoding];

CIImage *image = [CIImage imageWithCGImage:rep.fullResolutionImage];

NSError *error = nil;
NSArray *filterArray = [CIFilter filterArrayFromSerializedXMP:xmpData 
                                             inputImageExtent:image.extent 
                                                        error:&error];
if (error) {
     NSLog(@"Error during CIFilter creation: %@", [error localizedDescription]);
}

CIContext *context = [CIContext contextWithOptions:nil];

for (CIFilter *filter in filterArray) {
     [filter setValue:image forKey:kCIInputImageKey];
     image = [filter outputImage];
}

हालाँकि, यह केवल कुछ फिल्टर (क्रॉपिंग, ऑटो-एन्हांस) के लिए काम करता है, लेकिन दूसरों के लिए नहीं जैसे कि रेड-आई रिमूवल। इन मामलों में, CIFilterएस का कोई स्पष्ट प्रभाव नहीं है। इसलिए, मेरे सवाल:

  • क्या किसी को रेड-आई हटाने का तरीका पता है CIFilter? (एक तरह से Photos.app के अनुरूप। कुंजी के साथ फ़िल्टर kCIImageAutoAdjustRedEyeपर्याप्त नहीं है। उदाहरण के लिए, यह आंखों की स्थिति के लिए पैरामीटर नहीं लेता है।)
  • क्या आईओएस 5 के तहत इन फिल्टर को उत्पन्न करने और लागू करने की संभावना है?

यह लिंक एक और स्टाकेवरफ्लो प्रश्न है जो लाल आंख के लिए एक एल्गोरिथ्म प्रदान करता है। यह ज्यादा नहीं है लेकिन यह एक शुरुआत है। stackoverflow.com/questions/133675/red-eye-reduction-algorithm
Roecrew

IOS 7 पर सूचीबद्ध कोड सही ढंग से रेड-आई रिमूवल फिल्टर (CIRedEyeCorrections internal filter) लागू होता है।
पिव

जवाबों:


2
ALAssetRepresentation* representation = [[self assetAtIndex:index] defaultRepresentation];

// Create a buffer to hold the data for the asset's image
uint8_t *buffer = (Byte*)malloc(representation.size); // Copy the data from the asset into the buffer
NSUInteger length = [representation getBytes:buffer fromOffset: 0.0  length:representation.size error:nil];

if (length==0)
    return nil;

// Convert the buffer into a NSData object, and free the buffer after.

NSData *adata = [[NSData alloc] initWithBytesNoCopy:buffer length:representation.size freeWhenDone:YES];

// Set up a dictionary with a UTI hint. The UTI hint identifies the type
// of image we are dealing with (that is, a jpeg, png, or a possible
// RAW file).

// Specify the source hint.

NSDictionary* sourceOptionsDict = [NSDictionary dictionaryWithObjectsAndKeys:

(id)[representation UTI], kCGImageSourceTypeIdentifierHint, nil];

// Create a CGImageSource with the NSData. A image source can
// contain x number of thumbnails and full images.

CGImageSourceRef sourceRef = CGImageSourceCreateWithData((CFDataRef) adata,  (CFDictionaryRef) sourceOptionsDict);

[adata release];

CFDictionaryRef imagePropertiesDictionary;

// Get a copy of the image properties from the CGImageSourceRef.

imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(sourceRef,0, NULL);

CFNumberRef imageWidth = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelWidth);

CFNumberRef imageHeight = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelHeight);

int w = 0;

int h = 0;

CFNumberGetValue(imageWidth, kCFNumberIntType, &w);

CFNumberGetValue(imageHeight, kCFNumberIntType, &h);

// Clean up memory

CFRelease(imagePropertiesDictionary);
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.