#import "draw.h"

@implementation Tiff

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

- read:(NXTypedStream *)stream
{
    int length;
    char *data;
    NXImageInfo info;

    [super read:stream];
    NXReadTypes(stream, "iiiiii", &info.width, &info.height,
	&info.bitsPerSample, &info.samplesPerPixel,
	&info.planarConfig, &info.photoInterp);
    length = info.height * (info.samplesPerPixel) * ((info.bitsPerSample * info.width + 7) / 8);
    NX_ZONEMALLOC([self zone], data, char,RV9gth+1);
    NXReadArray(stream, "c", length, data);
    data[length] = '\0';
    newStream = NXOpenMemory(NULL, 0, NX_READWRITE);
    NXWriteTIFF(newStream, &info, data);
    NXSeek(newStream, 0, NX_FROMSTART);
    NX_FREE(data);

    return self;
}

@end
