fn rla2gray =
(
rlaFile = getOpenFileName types:"rla files |*.rla|"
if rlaFile != undefined do
	(
	rla = openBitmap rlaFile
	Ht =  rla.width
	Wd =  rla.height
	minZ = 9999.9
	maxZ = -1.0
	for H = 0 to (Ht - 1) do
		(
		for W = 0 to (Wd - 1 ) do
			(
			pixel = abs (getChannel rla [h,w] #zDepth)[1]
			if pixel < minZ do minZ = pixel
			if (pixel > maxZ) and (pixel < 1e+030) do maxZ = pixel
			)
		setWaitCursor()
		)
	Format "normalizing z values between % and %\n" minZ maxZ
	setArrowCursor()
	normRange = maxZ - minZ
	
	outputPath = (getFileNamePath rlaFile) + (getFileNameFile rlaFile) + ".tga"
	
	outPut = bitmap Wd Ht filename:outputPath color:black
	
	for H = 0 to (Ht - 1) do
		(
		for W = 0 to (Wd - 1 ) do
			(
			pixel = abs (getChannel rla [h,w] #zDepth)[1]
			if (pixel == 1e+030) then 
				(
				greyVal = black
				)
			else
				(
				greyPct = (1 - ((pixel - minZ) / normRange)) * 255
				greyVal = white 
				greyVal.v = greyPct
				)
				
			setPixels output [H,W] #(greyVal)
			setWaitCursor()
			)

		)
	save output
	close output
	close rla
	display output
	)
)