/*  
** Copyright (c) 1995 Netsurfer Inc.  All Rights Reserved.
**
** Author: <bbum@friday.com>
*/

/*  This object is included in the MiscKit by permission from the author
**  and its use is governed by the MiscKit license, found in the file
**  "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
**  for a list of all applicable permissions and restrictions.
*/

#import <appkit/appkit.h>
#import "ImageView.h"

#import <SurfImage/surfimage.h>

@implementation ImageView
- free
{
	[imageToImage free];
	return self;
}

-drawSelf:(const NXRect **) rects :(int) count
{
	NXPoint target = { 0., 0. };
	
	NXSetColor(NX_COLORPURPLE);
	NXRectFill(&bounds);

	if(imageToImage)
		[imageToImage composite:NX_SOVER toPoint:&target];

	return self;
}

- setImage:anImage
{
	NXSize theSize;
	
	if(imageToImage)
		[imageToImage free];

	imageToImage = anImage;

	if(imageToImage) {
		[imageToImage getSize:&theSize];
		[self sizeTo:theSize.width :theSize.height];
	}

	[self display];

	return self;	
}

- saveImageAsTIFF: (const char *) fileName
{
	NXStream *s;

	if(!imageToImage)
		return nil;

	s = NXOpenMemory(NULL, 0, NX_WRITEONLY);

	[imageToImage writeTIFF: s allRepresentations: YES];

	NXSaveToFile(s, fileName);
	NXCloseMemory(s, NX_FREEBUFFER);

	return self;
}
@end
