如何从QTKIT中获取图像数据,没有颜色或雪豹中的伽马校正?
题
由于Snow Leopard,QTKit现在正在从QTMovies FrameImageattime等功能中返回颜色校正的图像数据:withAttributes:error:。给定未压缩的AVI文件,在Snow Leopard与Leopard中显示了相同的图像数据,具有较大的像素值。
目前,我正在使用frameimageattime获取NSIMAGE,然后询问该图像的tiffermentation。执行此操作后,雪豹中的像素值略高。
例如,豹子中具有以下像素值的文件:
[0 180 0]
现在有一个像素值类似:
[0 192 0]
有什么方法可以向未校正颜色的视频帧询问QTMovie?我应该要求cgimageref,ciimage或cvpixelbufferref吗?在阅读视频文件之前,有没有办法完全禁用颜色校正?
我试图通过使用NScalibratedColrospace纳入NSBITMAPIMAGEREP来解决这个问题,但这只会使我成为其中的一部分:
// Create a movie
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys :
nsFileName, QTMovieFileNameAttribute,
[NSNumber numberWithBool:NO], QTMovieOpenAsyncOKAttribute,
[NSNumber numberWithBool:NO], QTMovieLoopsAttribute,
[NSNumber numberWithBool:NO], QTMovieLoopsBackAndForthAttribute,
(id)nil];
_theMovie = [[QTMovie alloc] initWithAttributes:dict error:&error];
// ....
NSMutableDictionary *imageAttributes = [NSMutableDictionary dictionary];
[imageAttributes setObject:QTMovieFrameImageTypeNSImage forKey:QTMovieFrameImageType];
[imageAttributes setObject:[NSArray arrayWithObject:@"NSBitmapImageRep"] forKey: QTMovieFrameImageRepresentationsType];
[imageAttributes setObject:[NSNumber numberWithBool:YES] forKey:QTMovieFrameImageHighQuality];
NSError* err = nil;
NSImage* image = (NSImage*)[_theMovie frameImageAtTime:frameTime withAttributes:imageAttributes error:&err];
// copy NSImage into an NSBitmapImageRep (Objective-C)
NSBitmapImageRep* bitmap = [[image representations] objectAtIndex:0];
// Draw into a colorspace we know about
NSBitmapImageRep *bitmapWhoseFormatIKnow = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:getWidth()
pixelsHigh:getHeight()
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bitmapFormat:0
bytesPerRow:(getWidth() * 4)
bitsPerPixel:32];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:bitmapWhoseFormatIKnow]];
[bitmap draw];
[NSGraphicsContext restoreGraphicsState];
这确实转换回“非颜色校正”的颜色空间,但是颜色值并不与我们正在测试的未压缩AVI文件中存储的颜色值完全相同。另外,这效率要低得多,因为它正在从RGB->“设备RGB” - > RGB转换。
另外,我正在64位应用程序中工作,因此不能选择降低到QuickTime-C API。
谢谢你的帮助。
解决方案
这就是您正在抗衡的地方: http://support.apple.com/kb/ht3712此处也在参考QT中进行了描述: http://developer.apple.com/library/mac/#technotes/tn2227/_index.html
对于Colorsync(自动且沉默)应该有一个选择的标志,但是由于ColorSync回到了“碳含量时代”,因此如何从64位应用程序中禁用它很困惑。它甚至可能存在,只是没有文档。但是,即使是Adobe也没有弄清楚Afaik(64位Photoshop for OS X ????)[编辑:实际上,也许他们使用CS5或找到了解决方法...因此,如果您有任何朋友在那里工作的朋友,也许他们可以可以成为资源;)但是,我认为,即使在64位OS X vs Windows或32位的颜色也可能出现不同的颜色。
第一个链接讲述了如何强制伽马值1.8的系统范围和非编程性。只是指出了这一点 - 它可能仅适用于您的应用程序,但很高兴知道。
禁用colorync的通常方法是/
GraphicsImportSetFlags( gi, kGraphicsImporterDontUseColorMatching );
但是我不知道这是否会在64位应用程序中使用(可以肯定的是)。实际上,与ColorSync相关的许多事情更加困难,也许是64位。只需搜索“站点:苹果公司colorync 64位”。
如果我找到更好的东西,我会编辑答案。可以这么说,只是认为这会帮助您了解敌人。
另一个编辑:(重新标记您的视频也可能减轻或消除此问题,因为Colorsync以某种方式处理未标记的视频(请参阅链接),并根据标签的不同而对其进行不同的操作。视频的颜色配置是什么?尝试SRGB?