2010-01-12 13 views
8

由於Snow Leopard,QTKit現在正在從QTMovies frameImageAtTime:withAttributes:error:返回色彩校正圖像數據。給定一個未壓縮的AVI文件,相同的圖像數據在Snow Leopard vs. Leopard中以更大的像素值顯示。如何從雪豹的QTKit中獲取圖像數據而無需顏色或伽馬校正?

目前,我正在使用frameImageAtTime來獲取NSImage,然後請求該圖像的tiffRepresentation。完成此操作後,雪豹的像素值稍高。

例如,在豹以下像素值的文件:

[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]; 

這並轉換​​回的「非色彩校正'colorspace,但顏色值NOT與存儲在我們正在測試的未壓縮AVI文件中的值完全相同。而且這樣效率低得多,因爲它是從RGB轉換到「Device RGB」 - > RGB。

另外,我正在使用64位應用程序,因此不能選擇下載到Quicktime-C API。

感謝您的幫助。

+0

你的位圖中像素的目的地是什麼?你從[位圖顏色空間]得到什麼樣的色彩空間? – 2012-01-03 00:37:31

回答

2

這是你對運行的是什麼了:http://developer.apple.com/library/mac/#technotes/tn2227/_index.html

有被認爲是對的ColorSync(這是自動和靜音)選擇退出的標誌,但:還描述了參考QT http://support.apple.com/kb/ht3712 由於ColorSync可以回到「碳排放時代」,所以關於如何從64位應用程序中禁用它,存在很多混淆。它甚至可能存在,只是沒有文檔。但即使是Adobe還沒有弄清楚它AFAIK(64位Photoshop的OS X ???)[編輯:其實,也許他們做了CS5,或找到了解決方法...所以如果你有任何朋友誰在那裏工作也許他們可以是一種資源;)但是,我認爲即使它們的顏色在64位OS X與Windows或32位上可能會有所不同。

第一個鏈接告訴我們如何強制1.8系統範圍內的伽馬值和非編程方式。只是指出它 - 它可能只是對你的應用程序有限的使用,但很好知道。

通常的方法來禁用的ColorSync是/是

GraphicsImportSetFlags(gi, kGraphicsImporterDontUseColorMatching); 

但我不知道這是怎麼回事在64位應用程序的工作(非常肯定它不會)。事實上,與ColorSync相關的許多事情在64位中都比較困難,可能還不可能。只需搜索「網站:apple.com colorsync 64位」。

如果我找到更好的東西,我會編輯我的答案。只是認爲這會幫助你瞭解敵人,可以這麼說。

另一個編輯:(重新)標記您的視頻可能會減輕或消除這個問題,因爲ColorSync以某種方式對未加標籤的視頻進行處理(請參閱鏈接),並根據標籤對它們進行不同處理。什麼是視頻的顏色配置文件?試試sRGB吧?