#import "GIF.h"
#import <stdio.h>
#import <stdlib.h>
#import <libc.h>
#import <zone.h>
#import <mach.h>
#import <appkit/Window.h>
#import <appkit/Panel.h>
#import <appkit/tiff.h>

extern int readgifheader(char *filename, int *xsize, int *ysize);
extern int readgif(unsigned char *rmap, unsigned char *gmap, unsigned char *bmap);

// GIF.m 
// 
// Written by Vince DeMarco 
// 	demarco@cpsc.ucalgary.ca
//
// This program is In the Public Domain. If you make any improvements to this
// program please let me know
// 

@implementation GIF:Image

- init
{
    self = [super init];
    strncpy(windowIconName,"gif.icon.tiff",14);
    return(self);
}

-open:(char *)filename
{
    strncpy(fileName,filename,1024);
    if (readgifheader(filename,&xsize,&ysize) < 0){
	NXRunAlertPanel("GIF ERROR", "Can't open %s", NULL, NULL, NULL, fileName);
	return(self);
    }
    // Allocate three buffers to store the R,G,B Triplets
    r = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
    g = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
    b = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));

    if (readgif(r,g,b) < 0){
	NXRunAlertPanel("GIF ERROR", "%s Not an GIF file ", NULL, NULL, NULL, fileName);
	return(self);
    }

    numColors = 3;
    [self displayImage];
    return(self);
}

@end
