我正在尝试使用CoreImage框架的CIColorCube CIFilter,我尝试对图像使用任意3D Luts,在将3D Luts作为参数传递给CIColorCube CIFilter之前,将其包装到NSData中。但我得到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];
我错过了什么吗,请帮忙
谢谢
最佳答案
CIColorCube
要求float类型的rgb数据在0.0 to 1.0
范围内,而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