[comp.sys.next] animation on the next machine

mark@tut.cis.ohio-state.edu (Mark Jansen) (07/10/89)

I am trying to do a simple animation on the NeXT machine, bitmaps seem to be
the logical object to use but I'm having trouble, the 0.9 documentation is
not complete.  What would be the correct ways to do the following four
simple operations.  Here are my guesses.

1) read a tiff file into a bitmap

	char *flnm;
	Bitmap aBitmap;

	aBitmap = [ Bitmap newFromTIFF:flnm ];

2) write a bitmap into a tiff file

	int      fd;
	NXStream *img_stream;
	Bitmap aBitmap;

	img_stream NXOpenFile( fd, "w" );
	[ aBitmap writeTIFF: img_stream ]

	the documentation says that what a stream is but how do I get one
	from a filename?  Some C functions use something called a file 
	descriptor of type int.(fd above)How do I get one of those?
        There is a c function to get a "typed stream" how is that different 
	from an untyped stream?

3) write a bitmap to a view on the megapixel display
	
	NXPOINT scr_point;

	[ aBitmap composite:NX_COPY
	          toPoint: scr_point ];

	is that point the bitmap is sent to in world coordinates or in
	whatever is the focused view or window of the application this is
	running to?

4) read a bitmap from a view on the display

	this one I am really unsure of. Perhaps something like.
	
	PSsizeimage()?
	img_data = malloc()
	NXReadBitmap(x,y,dx,dy,
			 dx,dy, 2, img_data)
	[ aBitmap readImage:img ];
	
	What are the coordinates for these NX and PS functions, do they 
	also use the focused view context or not?  n

are there better ways?  should I skip the bitmap part and just use images
and the C functions that manipulate images?  Would that be significantly 
faster?  I could use some help.  I'm pretty stuck.

ali@polya.Stanford.EDU (Ali T. Ozer) (07/11/89)

In article <54308@tut.cis.ohio-state.edu> Mark Jansen writes:
>1) read a tiff file into a bitmap
>	char *flnm;
>	Bitmap aBitmap;
>	aBitmap = [ Bitmap newFromTIFF:flnm ];

That's right. You can also read a bitmap from the the __TIFF segment of the 
executable; this might be desirable when you want your executable to be a 
stand-alone product without any auxiliary files which always seem
to get lost during a crucial demo. To accomplish this,
add to LDFLAGS in your Makefile (best accomplished through the use
of a Makefile.preamble, if you are using the IB project manager):

LDFLAGS = -segcreate __TIFF myPicture.tiff myPicture.tiff

This creates a section named myPicture.tiff in the __TIFF segment.
To get at this data, you'd do:

	aBitmap = [Bitmap newFromMachO:"myPicture.tiff"];

You can also include TIFF pictures as icons through Interface Builder; then 
they become available as named bitmaps, retrievable through the findBitmapFor: 
method.

>2) write a bitmap into a tiff file
>	img_stream NXOpenFile( fd, "w" );
>	[ aBitmap writeTIFF: img_stream ] 

Almost; to use NXOpenFile you need to first open a file with open(), which 
returns to you a file handle of type int, which is what fd is. Take a
look at StreamStuff.c in /NextDeveloper/Examples/Yap. Not necessarily the
optimal use of the streams package, but it should give you an idea... 

>3) write a bitmap to a view on the megapixel display
>	NXPOINT scr_point;
>	[ aBitmap composite:NX_COPY
>	          toPoint: scr_point ];
>
>	is that point the bitmap is sent to in world coordinates or in
>	whatever is the focused view or window of the application this is
>	running to?

The currently focused view. All drawing in the kit is done through 
locking the focus on some view. By the way, NXPOINT should be NXPoint, above.

>4) read a bitmap from a view on the display
>	this one I am really unsure of. Perhaps something like.
>	PSsizeimage()?
>	img_data = malloc()
>	NXReadBitmap(x,y,dx,dy,
>			 dx,dy, 2, img_data)
>	[ aBitmap readImage:img ];

I believe this method is used to read the image that is currently
in the bitmap to your own memory. You might not need this if you are
just going to do some animation. 

To read the image contained in a bitmap, seems like all
you need to do is use imageSize:width:height:bps:spp:inRect: in conjunction
with readImage:.  No need to use PSsizeimage() as you do above. (Before
I give a more definitive answer I'd like to get a a chance to play with this
stuff, however... I am away from my machine at the moment.)

Ali Ozer, NeXT Developer Support
aozer@NeXT.com