格式化数据CIColorCube

时间:2013-02-25 13:17:43

标签: ios nsdata exc-bad-access core-image cifilter

我正在尝试使用CoreImage框架的CIColorCube CIFilter,我尝试了任意3D Luts图像,我将3D luts包装到NSData,然后作为参数传递给CIColorCube CIFilter。但我得到EXC_BAD_ACCESS异常.. 这是我的代码:

CIContext * context = [CIContext contextWithOptions:nil];     CIFilter * filter = [CIFilter filterWithName:@“CIColorCube”];

uint8_t color_cube_data[4096*4] = {
    153, 255, 255, 1,
    170, 255, 255, 1,
    186, 255, 255, 1,
    204, 255, 255, 1,
    221, 255, 255, 1,
    237, 255, 255, 1,
    255, 255, 255, 1};
NSData * cube_data =[NSData dataWithBytes:color_cube_data length:4096*sizeof(float)*4];

[filter setValue:originalImage forKey:kCIInputImageKey];
[filter setValue:[NSNumber numberWithFloat:16] forKey:@"inputCubeDimension"];
[filter setValue:cube_data forKey:@"inputCubeData"];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGImageRef cgImage =[context createCGImage:result fromRect:originalImage.extent];
imgVw_Result.image=[UIImage imageWithCGImage:cgImage]; 

我错过了什么,请帮助 感谢

1 个答案:

答案 0 :(得分:1)

CIColorCube要求0.0 to 1.0范围内的float类型的rgb数据,而color_cube_data结构的类型为uint8_t。此外,在cube_data构造函数中,您实际上已经考虑了类型float(“sizeof(float)”),这意味着您没有为过滤器的NSData结构提供正确的字节大小。

请参阅以下文档中的清单5-3: https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/CoreImaging/ci_filer_recipes/ci_filter_recipes.html#//apple_ref/doc/uid/TP30001185-CH4-SW1