由於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。
感謝您的幫助。
你的位圖中像素的目的地是什麼?你從[位圖顏色空間]得到什麼樣的色彩空間? – 2012-01-03 00:37:31