[comp.sys.next] displaying 8-bit grayscale data files

rick@hanauma (Richard Ottolini) (08/27/89)

We store and display seismic data as 8-bit grayscale images.
A class to do this follows. (The class contains other methods for interacting
with the seismic database which is a text file of dimensions and binary
data.)


/* Generated by the NeXT Interface Builder */

#import <appkit/appkit.h>
#import <appkit/View.h>

@interface SeisView: View
{
	id	panel;
	id	form; /* form for entering data dimensions */
	id	file;
	id	n1;	/* fast dimension */
	id	n2;
	id	image; /* NeXTStep image object */
	char	*data; /* file data buffer */
}

+ newFrame: (NXRect *) frameRect
- drawSelf: (NXRect*)rect: (int)count;
- newdata: sender;
- openData: sender;
- rattle; /* show error by shaking */

@end


/* Generated by the NeXT Interface Builder */

#import "SeisView.h"

@implementation SeisView

+ newFrame: (NXRect *) frameRect
{
	self = [ super newFrame: frameRect ];
	image = 0;
	data = 0;
	return self;
}

- drawSelf: (NXRect*)rect: (int)count
{
	int i;
	NXSize size;
	NXRect box;

	if (!data) return self;
	[window setContentView: self];
	if (image) [image free];
/*
	image = [Bitmap  newRect: &bounds type: NX_UNIQUEBITMAP window: window];
*/
	box.origin.x = 0;
	box.origin.y = 0;
	box.size.width = bounds.size.width;
	box.size.height = bounds.size.height;
	image = [Bitmap newSize: box.size.width: box.size.height type: NX_UNIQUEBITMAP];
	[image image: data toRect: &bounds width: [n1 intValue] height: [n2 intValue] bps: 8 spp: 1];
	[image composite: NX_COPY toPoint: &bounds.origin];
	[image getSize: &size];
	return self;
}

- newdata: sender
{
	int i, n;

	if (!strcmp ([file stringValue],"")) {
		[form selectTextAt: 0];
		[self rattle];
		return self;
		}
	if (! [n1 intValue]) {
		[form selectTextAt: 1];
		[self rattle];
		return self;
		}
	if (! [n2 intValue]) {
		[form selectTextAt: 2];
		[self rattle];
		return self;
		}
	[panel orderOut: self];
	n = [n1 intValue] * [n2 intValue];
	if (data) free (data);
	data = (char *) malloc (n);
	read (open ([file stringValue],0),data,n);
	[window setTitle: [file stringValue]];
	[window orderFront: sender];
	[self display];
	return self;
}

- rattle
{
	NXRect rect;


	[panel orderFront: self];
	[panel getFrame: &rect];
	[panel moveTo: rect.origin.x-5: rect.origin.y];
	[panel moveTo: rect.origin.x+5: rect.origin.y];
	[panel moveTo: rect.origin.x-5: rect.origin.y];
	return self;
}

char *types[] = {".H",""};

- openData: sender
{
	id openPanel;
	char File[40];
	int N1, N2;

	openPanel = [OpenPanel new];
	if ([openPanel runModalForTypes: types] == TRUE) {
		GetparFile ([openPanel filename]);
		if (getpar ("in","s",File)) [file setStringValue: File];
		if (getpar ("n1","d",&N1)) [n1 setIntValue: N1];
		if (getpar ("n2","d",&N2)) [n2 setIntValue: N2];
		[self newdata];
	}
	[openPanel free];
	return self;
}

@end