1

我在 Mac 上实现了一个 Photoshop 插件,我正在使用 Cocoa 来实现。到目前为止一切正常,但下一步是提供“预览”图像,作为我的插件窗口的一部分,我被卡住了。我是一个 n00b Obj-C 程序员,这并没有真正的帮助:-)

到目前为止,我有这样的事情:

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 Adob​​e Photoshop Elements[46628] *** NSCopyMemoryPages(0x0, 0x245f4000, 2265088) 失败

我可能错误地计算了 inData 的大小。帮助?

此外,NSImage 是否能够正确解释该图像数据块?还是我应该放弃它,只在 NSImage 中进行逐像素映射?

4

1 回答 1

0

好吧,这比我预期的要痛苦得多。此外,感谢 NVidia 发布此PDF,它比实际的 SDK 文档更好地解释了 Photoshop SDK 过滤器记录。

除了用于调试目的的示例 tif 文件之外,此代码实际上读取 inData 并生成一个可用的 NSImage(大量日志记录只是为了弄清楚它在做什么,随意删除)。

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);
于 2009-07-23T14:35:50.013 回答