#import "PSGraphic.h"
#import "Image.h"
#import <mach.h>

@implementation PSGraphic

- replaceWithImage
{
    id retval = [[Image allocFromZone:[self zone]] initFromStream:newStream allowAlpha:YES];
    [retval setBounds:&bounds];
    if (!gFlags.selected) [retval deselect];
    if (gFlags.locked) [retval lock];
    [self free];
    return retval;    
}

- read:(NXTypedStream *)stream
{
    char *data;
    int length;
    float bbox[4];

    [super read:stream];
    NXReadTypes(stream,"ffffi",&bbox[0],&bbox[1],&bbox[2],&bbox[3],&length);
    vm_allocate(task_self(), (vm_address_t *)&data, length, YES);
    NXReadArray(stream, "c", length, data);
    newStream = NXOpenMemory(data, length, NX_READONLY);

    return self;
}

@end
