/*
----------------------------------------------------------------------------
This AREXX-Script will make any image embossed.
If the image is 24Bit, it will be saved as 24Bit.
If you have an AGA machine, it will save 256 colors or less.
If you don't, it will save 32 colors or less.

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

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

if ~(c='COLOR'|c='GRAY')|c='' then do
	say 'Invalid argument! Read the doc!'
	say 'See Ya.....'
	say ''
	exit
	end

if offX='' then offX=1
if offY='' then offY=1

options results
address 'ADPro'
say 'Emboss: Written by Jan Van Overbeke, 3-DEE, ©1993'
say 'Image: 'filename
say 'SAVE: =<256 / =<32 / 24Bit'
say ''

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

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

/* ----   Get info about image: is it 24Bit? is it gray? ---- */
/* ---- If it is gray, and if gray emboss is requested,  ---- */
/* ----      we'll have to do something about it         ---- */
/* ---------------------------------------------------------- */
IMAGE
help=ADPRO_RESULT
dontrender='ok'
if pos('Rendered',help)>0|pos('BITPLANE',help)>0 then dontrender='nok'
if word(help,1)~='GRAY' & c='GRAY' then do
	say 'Converting image to gray.....'
	operator Color_To_Gray
	if RC~=0 then do
		say 'Unable to operate the Color_to_gray operator!!!!'
		say 'See Ya.......'
		say ''
		exit
		end
	end

say 'Saving1 24Bit......'
save 'ram:1' "RAW"
if RC~=0 then do
	say 'This save failed!!!!!!!!'
	say 'See Ya...'
	say ''
	exit
	end

say 'Making image Negative.'
operator Negative
if RC ~=0 then do
	say 'Unable to select the Negative operator.'
	say 'See Ya...'
	say ''
	exit
	end

say 'Saving2 24Bit......'
save 'ram:2' "RAW"
if RC~=0 then do
	say 'This save failed!!!!!!!!'
	say 'See Ya......'
	say ''
	exit
	end

say 'Loading 1st part of Emboss.'
load 'ram:1'
if RC~=0 then do
	say 'Error loading.'
	say 'See Ya.....'
	say ''
	exit
	end

address COMMAND 'delete >NIL: ram:1'
say 'Loading 2nd part of Emboss.'
LOAD 'ram:2' offX OffY 50 -1 -1 -1
if RC ~=0 then do
	say 'Had some problems while compositing.'
	say 'See Ya.'
	say ''
	exit
	end

/* ----       That was basic Emboss routine:       ---- */
/* ---- overlay the (gray) image with its negative ---- */
/* ----            with a little offset            ---- */
/* ----            and mix it 50 percent           ---- */
/* ---------------------------------------------------- */


/* ---- If the original image was not 24bit, all palette and image ---- */
/* ----               settings must fit the gray data.             ---- */
/* -------------------------------------------------------------------- */
address COMMAND 'delete >NIL: ram:2'
if dontrender='nok' then do
	savemode="IMAGE"
	say 'Converting......'
	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'....'
	end
	else do
		savemode="RAW"
		say 'Saving 'savemode'....'
	     end

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