Подтвердить что ты не робот

Интерпретировать XMP-метаданные в ALAssetRepresentation

Когда пользователь делает некоторые изменения (обрезка, удаление эффекта красных глаз,...) на фотографии во встроенном Photos.app на iOS, изменения не применяются к 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 недостаточен, например, он не принимает параметры для положения глаз.)
  • Есть ли возможность создавать и применять эти фильтры в iOS 5?
4b9b3361

Ответ 1

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

// Create a buffer to hold the data for the asset 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);