What I am getting at is:

There are 2 possibilities REAL should consider with the API 
"REALLockPictureDescription".

1) If you really want to provide a picture description as a native type, then 
you should make sure that the call "[bitmap TIFFRepresentation]" used in a 
function like:

+ (Handle) hImage:(REALpicture)pic
{       
        CGImageRef image = REALCopyPictureCGImage(pic); 
        NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] 
initWithCGImage:image];
        
        int width   = [bitmap pixelsWide];
        int height  = [bitmap pixelsHigh];
        int pitch   = [bitmap bytesPerRow];
        
        NSData * data = [bitmap TIFFRepresentation];
        Handle picHandle = NewHandle(height*pitch);
        BlockMoveData([data bytes], *picHandle, height*pitch);
        [bitmap release];
        CGImageRelease(image);
        return picHandle;       
}

Does not lead to a console message:  <Error>: tiff data provider: Error 
fetching data for field "ICC Profile". First, we are forced to use 
REALCopyPictureCGImage, because the "native type" of the REALpicture is a 
pictureCGBitmapContext, despite the fact that a REALpicture derived from a pct 
file, or PICT resource is not a TIFF,JPEG, GIF, PDF. Note that any other trials 
to get a Handle from a CGImageRef fails, such as:

        // this does not give a displayable image, only the above when copying 
the TIFFRepresentation
        REALpictureDescription desc;
        
        if (REALLockPictureDescription(pic, &desc, pictureCGBitmapContext))
        {
                NSLog(@"pictureCGBitmapContext");
                int width   = desc.width;
                int height  = desc.height;
                NSLog(@"the width is %d and the height is %d", width, height);
                int pitch = 4 * width;//bytesPerRow
                NSLog(@"the pitch is %d bytes per row", pitch);
                Handle picHandle = NewHandle(height*pitch);
                BlockMoveData(desc.pictureData, *picHandle, height*pitch);
                return picHandle;       
        }
        return NULL;
or

+ (Handle) HandleFromCGImage:(CGImageRef)image
{
        CGDataProviderRef provider = CGImageGetDataProvider(image);
        CFDataRef dataRef = CGDataProviderCopyData(provider);
        
        CGDataProviderRelease(provider);        
        UInt8 *data = (UInt8*)CFDataGetBytePtr(dataRef);
        CFIndex length = CFDataGetLength(dataRef);
        
        int width   = CGImageGetWidth(image);
        int height  = CGImageGetHeight(image);
        int pitch   = CGImageGetBytesPerRow(image);
        
        NSLog(@"length = %d, height*pitch = %d", length, height*pitch);
        
        Handle picHandle = NewHandle(height*pitch);
        BlockMoveData(data, *picHandle, height*pitch);
        CFRelease(dataRef);
        return picHandle;
}

2) Make it simple, based on what is already available. Let us figure out 
whether we have to do with a PICT, a GWorld or a CGImageRef. We can do this for 
carbon, why not cocoa?


I can file this in the bug base, but some discussion first might be in 
place..., particularly because of a funky SDK that needs explanation.

Alfred

On Dec 19, 2010, at 5:13 PM, Alfred Van Hoek wrote:

> I am surprised to see that REALCopyPictureCGImage on a quickdraw picture 
> results in a pictureCGBitmapContext (maybe I shouldn't). However, in the 
> cocoa environment .pct files are also wrongly drawn in canvases. 
> 
> Cocoa provides a PICTRepresentation you can get from an NSPICTImageRep, but 
> unfortunately REALLockPictureDescription in the cocoa runtime appears to 
> return true when pictureCGBitmapContext is being used, not when 
> pictureMacintoshPICT is used.. 
> 
> 
> In cocoa, is there an sdk call that calls on the REALpicture, will provide 
> the correct picture type and we can go from there??

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to