/*
------------------------------------------------------------------------------
This AREXX-Script will make any image gray.

Host address: ADPro (Art Department Professional   ®ASDG)
Written by Jan Van Overbeke, 3-DEE, ©1993.
Read the AREXX-Scripti doc, for more information about operation and rights!
------------------------------------------------------------------------------
*/

arg filename
if ~ exists(filename)|filename='' then do
	say 'Unable to find the image !!'
	say 'See Ya...'
	say ''
	exit
	end

address 'ADPro'
say 'Gray Image: Written by JAN VAN OVERBEKE, 3-DEE, ©1993'
say 'Image: 'filename
say 'SAVE: IFF 256/16/24Bit colors'
say ''

OPTIONS RESULTS
LFORMAT "UNIVERSAL"
if RC ~=0 then do
	say 'Unable to select the UNIVERSAL loader.'
	say 'See Ya...'
	say ''
	exit
	end

say 'Loading.........'
LOAD filename
if RC ~=0 then do
	say 'Had some problems while loading.'
	say 'See Ya...'
	say ''
	exit
	end

/* ---- Check if image is gray, if it is, just end program ---- */
/* ----           Check if loaded image is 24Bit           ---- */
/* ------------------------------------------------------------ */
IMAGE
help=ADPRO_RESULT
if pos('GRAY',help)>0 then do
	say 'Image already is gray!!!!!'
	say 'See Ya......'
	say ''
	exit
	end
dontrender='ok'
if pos('RENDERED',help)>0|pos('BITPLANE',help)>0 then dontrender='nok'

say 'Converting......'
operator Color_To_Gray
if RC~=0 then do
	say 'Color_To_Gray operation failed!'
	say 'See Ya......'
	say ''
	exit
	end

SFORMAT "IFF"
if RC ~=0 then do
	say 'Unable to select the IFF Saver.'
	say 'See Ya...'
	say ''
	exit
	end

/* ---- If image is not 24Bit, render new image ---- */
/* ----  and use appropriate palette settings   ---- */
/* ------------------------------------------------- */
if dontrender='nok' then do
	render_type
	colors=ADPRO_RESULT
	ptotal colors
	pused colors
	EXECUTE
	if RC~=0 then do
		say 'Execute failed.'
		say 'See Ya......'
		say ''
		exit
		end
	say 'Saving IMAGE 'colors'.....'
	savemode='IMAGE'
	end
	else do
		savemode='RAW'
		say 'Saving RAW.....'
	     end

filename=filename'.new'
SAVE filename savemode
if RC~=0 then do
	say 'Problems while saving: NOT SAVED.'
	say 'See Ya...'
	end
say ''
exit
