2009-07-22 60 views
1

我在Mac上實現一個Photoshop插件,並且我正在使用Cocoa。目前做得不錯,但下一步是提供一個「預覽」圖像,作爲我的插件窗口的一部分,並且我被卡住了。我是一個的n00b的OBJ-C程序員,這是不是真的幫助:-)使用Cocoa的Photoshop插件 - 如何獲得預覽

到目前爲止,我有這樣的事情:

int dataSize = gFilterRecord->bigDocumentData->wholeSize32.v * 
       gFilterRecord->bigDocumentData->wholeSize32.h * 
       gFilterRecord->planes; 

NSData *inData = [[NSData alloc] initWithBytesNoCopy:gFilterRecord->inData length:dataSize freeWhenDone:NO]; 
NSLog(@"LoadImageFromSDK : Data created"); 
NSImage *imageTmp = [[NSImage alloc] initWithData:inData]; 
NSLog(@"LoadImageFromSDK : Image created"); 

//Save to PNG file as a test of this image creation 
[[imageTmp TIFFRepresentation] writeToFile:@"/tmp/imageTmp.tif" atomically:YES]; 
NSLog(@"LoadImageFromSDK : Wrote image to disk"); 

目前,它崩潰可怕的:
09/07/22 10:23:32上午Adobe Photoshop Elements [46628] *** NSCopyMemoryPages(0x0,0x245f4000,2265088)失敗

我可能計算錯誤的inData大小。幫幫我?

此外,NSImage是否能夠正確解釋該圖像數據blob?或者我應該放棄它,只是做一個逐像素映射到NSImage?

回答

0

好吧,這比我預料的要痛苦得多。此外,感謝NVidia發佈此PDF這是比實際的SDK文檔更好地解釋Photoshop SDK過濾器記錄。

此代碼實際上讀取inData並生成一個可用的NSImage(大量日誌記錄只是爲了弄清楚它在做什麼,隨時刪除)以及用於調試目的的示例tif文件。

NSLog(@"Entering LoadImageFromSDK"); 

unsigned char *bitmapPlanes[4];  
bitmapPlanes[0] = (unsigned char *) (gFilterRecord->inData); 

NSLog(@"Params to create bitmap"); 
NSLog(@"pixelsWide = %d", gFilterRecord->bigDocumentData->imageSize32.h); 
NSLog(@"pixelsHigh = %d", gFilterRecord->bigDocumentData->imageSize32.v); 
NSLog(@"bitsPerSample = %d", gFilterRecord->depth); 
NSLog(@"samplesPerPixel = %d", gFilterRecord->planes); 
NSLog(@"hasAlpha = %d", NO); 
NSLog(@"isPlanar = %d", NO); 
NSLog(@"colorSpaceName = %@", mapImageModeToColorSpace(gFilterRecord->imageMode)); 
NSLog(@"bytesPerRow = %d", gFilterRecord->inRowBytes); 
NSLog(@"bitsPerPixel = %d", gFilterRecord->depth*gFilterRecord->planes);  

NSBitmapImageRep *bitmapTmp = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:bitmapPlanes 
                     pixelsWide:gFilterRecord->bigDocumentData->imageSize32.h 
                     pixelsHigh:gFilterRecord->bigDocumentData->imageSize32.v 
                    bitsPerSample:gFilterRecord->depth 
                   samplesPerPixel:gFilterRecord->planes 
                     hasAlpha:NO 
                     isPlanar:NO 
                    colorSpaceName:mapImageModeToColorSpace(gFilterRecord->imageMode) 
                    bytesPerRow:gFilterRecord->inRowBytes 
                    bitsPerPixel:gFilterRecord->depth*gFilterRecord->planes]; 

NSLog(@"LoadImageFromSDK : Bitmap created = %@", bitmapTmp); 

[[bitmapTmp TIFFRepresentation] writeToFile:@"/Users/someuser/temp/sample.tif" atomically:YES]; 


NSImage *imageTmp = [[NSImage alloc] initWithSize:[bitmapTmp size]]; 
[imageTmp addRepresentation:bitmapTmp]; 
NSLog(@"LoadImageFromSDK : Image created = %@", imageTmp); 
相關問題