compoZ a compositing script (creates batch files)






Click on the link below to download compozFeb0220088pm.zip
which contains, the daz-studio script and the readme (instructions)


compoZ version 1.0 released Feb 02 2008 8pm




Here's the content readme and the script itself.
manual for compoz.ds v1.0
===========================================

--------------------------------------------------------------------------------------------
Credits
--------------------------------------------------------------------------------------------
Ideas by neon22 amd Casual implemented by Casual
The above are Daz3D forum aliases

--------------------------------------------------------------------------------------------
Purpose
--------------------------------------------------------------------------------------------
Images rendered by DazStudio (except .jpg) contain a 
transparency map or Alpha channel. Everything in the image 
not occupied by an object or figure is deemed transparent.

Using  a "compositing" utility you can combine a rendered 
(foreground) image with a second (background) image.

This script will build a batch (.bat)  file that in turn will 
repeatedly run the compositing utility and combine two 
series of images into one.

The batch (.bat) files generated by this script may not be 
compatible with Mac and Unix OSes

---------------------------------------------------------------------------------------------
Installation 
--------------------------------------------------------------------------------------------

You should place the present script (compoZ.ds) and the associated
icon image (compoZ.png)  in your daz studio script folder, usually 
C:\Program Files\Daz\Studio\Contents\Script 

Although other utilities could be used for image compositing,
this script was designed with ImageMagick in mind.

So first you need to get and install the free imaging suite 
ImageMagick which you can get from the official web site:
http://www.imagemagick.org

You only need to install the windows binaries located here: 
http://www.imagemagick.org/script/binary-releases.php#windows

--------------------------------------------------------------------------------------------
User manual
--------------------------------------------------------------------------------------------
=========================================================

=========================================================
Section 1 : Background Images
=========================================================

In this section you specify the location of the numbered images that will be used
as background images in the compositing process.

Using Daz Studio you can render an animation as a series of numbered images.
Using freeware like VirtualDub or almost any movie editor, you can convert
a video (avi mpg etc) into a series of numbered images.

As an example we will consider the case where you created 100 numbered 
background images and placed them in a folder named C:\job001\bkgpics  
The images are all prefixed "pic". The image numbers are padded with 3 zeros.

-----> pic001.png, pic002.png, pic003.png .... pic100.png, 

++++++++++++++++++++++++++++++
"Loop Range Start Image Number" 
and 
"Loop Range End Image Number"

If the foreground  animation lasts longer than the background image series, looping
will occur. Here you specify the looping range. 

In our example, we should specify 1 as the "Loop Range Start Image Number" 
and 100 for "Loop Range End Image Number"

++++++++++++++++++++++++++++++
First Image Used Number

The number of the first background image that will be composited with the first 
forground image. Usually this number will be the same as the "Loop Range Start Image Number" 
parameter ( 1 in our example ). 

++++++++++++++++++++++++++++++
Filename prefix

In our example, the image prefix is pic

++++++++++++++++++++++++++++++
File Number Padding

Some programs output numbered image with "zero padding".
In our example  (pic001.png) the filename numbers are padded with three zeros.
If your program outputs numbered images unpadded ( pic1.png)  then set
File Number Padding to 0

++++++++++++++++++++++++++++++
Image format

The background images dont need a transparency map, so all image formats
are allowed. Formats must be one of the many supported by Imagemagick 
here's the most used bmp jpg png tga gif. Do not include the period/dot (.).

in our example, "Image Format" is png

++++++++++++++++++++++++++++++
Path To Images

Location of the directory holding your series of background images.
The [...] button can be used to browse up to this directory. Note the absence
of a trailing backslash at the end of the path.

In our example, C:\job001\bkgpics

=========================================================
Section 2 : Foreground Images
=========================================================

In this section you specify the location of the numbered images that will be used
as foreground images in the compositing process.

Using Daz Studio you can render an animation as a series of numbered images.
And those images contain the required "alpha channel" or transparency map.

If the images supplied dont contain this feature ( example if you are trying to use jpg images)
the background images wont show through the foreground images

As an example we will consider the case where you created 300 numbered 
background images and placed them in a folder named C:\job001\frgpics  
The images are all prefixed "pic". The image numbers are padded with 3 zeros.

-----> pic000.png, pic001.png, pic002.png .... pic299.png, 

++++++++++++++++++++++++++++++
"Start Frame " and "End Frame"

The range of foreground images that will be composited on top of the backround images

in our example, this could be 0 and 299 

++++++++++++++++++++++++++++++
Filename prefix

In our example, the image prefix is pic

++++++++++++++++++++++++++++++
File Number Padding

Some programs output numbered image with "zero padding".
In our example  (pic000.png) the filename numbers are padded with three zeros.
If your program outputs numbered images unpadded ( pic0.png)  then set
File Number Padding to 0

++++++++++++++++++++++++++++++
Image format

The foreground images do need a transparency map, but other than that,
all 100 image formats supported by Imagemagick can be used

here's the most common: bmp jpg png tga gif. 

Do not include the period/dot (.) in the "Image Format"

in our example, "Image Format" is png

++++++++++++++++++++++++++++++
Path To Images

Location of the directory holding your series of foreground images.
The [...] button can be used to browse up to this directory. Note the absence
of a trailing backslash at the end of the path.

In our example, C:\job001\frgpics

=========================================================
Section 3 : Output Images (composited)
=========================================================

In this section you specify the location of the numbered images that will be 
created by the compositing process.

As an example we will consider the case where you want to create
270 images numbered 30 to 299 and have them placed in a folder named 
C:\job001\outpics  

You want your images to be prefixed "pic". 

You want your image numbers to be padded with 3 zeros.

-----> pic030.png, pic031.png, pic032.png .... pic299.png, 


++++++++++++++++++++++++++++++
First Frame Number

An offset for the image numbers of the files created by compositing.

In our example, "First Frame Number" is 30

In most cases you'll leave "First Frame Number" at 0

++++++++++++++++++++++++++++++
Filename prefix

In our example, the image prefix is pic

++++++++++++++++++++++++++++++
File Number Padding

The composited images produced by the batch file (bat) built by this script
will usually be converted into a video file (avi mpg mov). Some programs
like bmptoavi or virtualdub require filename numbers to be "zero padded"

in our example we set the padding to 3

so our filenames will look like

-----> pic030.png, pic031.png, pic032.png .... pic299.png, 

if the output format was bmp, these filenames would be usable for conversion to avi
using bmp2avi

if you dont want zer0-padding, then set "File Number Padding" to 0

-----> pic30.png, pic31.png, pic32.png ... ppic299.png, 

++++++++++++++++++++++++++++++
Image format

The composited images will not include a transparency map.
so all 100 image formats supported by Imagemagick can be used

here's the most common: bmp jpg png tga gif. 

Do not include the period/dot (.) in the "Image Format"

in our example, "Image Format" is png

++++++++++++++++++++++++++++++
Path To Images

Location of the directory that will be holding your series of composited images.
The [...] button can be used to browse up to this directory. You can also use this
browser to create new directories (folders).

Note the absence of a trailing backslash at the end of the path.

In our example, C:\job001\outpics

=========================================================
Section 4 : Batch File Creation
=========================================================

Here you specify how the batch (.bat) file will be created by this script

++++++++++++++++++++++++++++++
Path To Compositing Utility

Specify where the compositing utility is located. Since i installed ImageMagick
in my C:\imagemagick directory, that the value i give to "Path To Compositing Utility"

++++++++++++++++++++++++++++++
Compositing formula (Advanced users)

If you have a good understanding of the compositing utilities you can
modify this formula

default value: composite -compose atop -geometry 640x480

the end part that reads 640x480 means that the foreground and background images
will be resized to 640 pixels by 480 pixels before being saved at this size

If your foreground images are 320x240 pixels, you probably want to change the formula to

composite -compose atop -geometry 320x240

++++++++++++++++++++++++++++++
Path to the batch file created by this script

Specify the location of the directory where you want this sscript to create the compositing 
batch (bat) file. 

---------------------------------------------------------------------------------------------
Thanks
---------------------------------------------------------------------------------------------

Thanks to DAZ Forum Team member Richard Haseltine 
for help on the initial idea which may be implemented soon

---------------------------------------------------------------------------------------------
History
---------------------------------------------------------------------------------------------
february 1st 2008 : v1.0 released

----------------------------------------------------------------------------------------------
Disclaimers
---------------------------------------------------------------------------------------------

We do not claim any copyrights for this script

We are not affiliated with Daz nor is this script endorsed by them.

We are not afiliated in any way with the makers of ImageMagick
(ImageMagick Studio LLC) and this script is not endorsed by them

You can read ImageMagick's license here:
http://www.imagemagick.org/script/license.php

This script has not been tested extensively,  The code was 
written to prevent users from doing simple errors. This is not
a commercial product it's just a script posted on a forum. 

If you're not careful you may even overwrite precious images, or fill
your hard disk with 100000 images.

In no event shall the author be liable for any damages whatsoever 
arising out of the use of or inability to use this script, the batch
files it produces and the documentation, 


// ideas by neon22 amd Casual implemented by Casual
// the above are Daz3D forum aliases
//
// thanks to DAZ Forum Team member Richard Haseltine 
// for help on the initial idea which may be implemented soon
// v1.0 released february 1st 2008
//
// We are not affiliated with Daz nor is this script endorsed by them
//
// Although other utilities could be used for image compositing,
// this program was designed with ImageMagick in mind.
//
// This script creates batch (.bat) files.
// When run/executed the batch files repeatedly launches
// the image compositing utility ( usually ImageMagick )
//
// We are not afiliated in any way with the makers of ImageMagick
// (ImageMagick Studio LLC) and this script is not endorsed by them
// 
// You should download and install ImageMagick on your PC
// from the official web site: http://www.imagemagick.org
// You only need to install the windows binaries
// located here: http://www.imagemagick.org/script/binary-releases.php#windows
//
// I doubt this script/batch system works on a MAC or on Unix
// 
// This is a DasStudio script script should be placed under your DazStudio

const SMALLWIDTH = 50;

var msg; //global var to pass messages string between  functions

// data and controls

var m_nValueBkgStart = 0;
var m_nValueBkgEnd = 30;
var m_nValueBkgOffset = 0;
var m_nValueBkgPfx = "pic";
var m_nValueBkgType = "png";
var m_nValueBkgPad = 0;
var m_nValueBkgPath = "c:\\job001\\bkgpics";

var m_wEntryBkgStart;
var m_wEntryBkgEnd;
var m_wEntryBkgOffset;
var m_wEntryBkgPfx;
var m_wEntryBkgPad;
var m_wEntryBkgType;
var m_wEntryBkgPath;

var m_nValueFrgStart = 0;
var m_nValueFrgEnd = 30;
var m_nValueFrgPfx = "pic";
var m_nValueFrgType = "png";
var m_nValueFrgPad = 0;
var m_nValueFrgPath = "c:\\job001\\frgpics";

var m_wEntryFrgStart;
var m_wEntryFrgEnd;
var m_wEntryFrgPfx;
var m_wEntryFrgPad;
var m_wEntryFrgType;
var m_wEntryFrgPath;

var m_nValueOutStart = 0;
var m_nValueOutPfx = "pic";
var m_nValueOutType = "png"
var m_nValueOutPad = 0;
var m_nValueOutPath = "c:\\job001\\outpics";

var m_wEntryOutStart;
var m_wEntryOutPfx;
var m_wEntryOutPad;
var m_wEntryOutType;
var m_wEntryOutPath;

var m_nValueMgkPath = "c:\\imagemagick";
var m_wEntryMgkPath;

var m_nValueBatPath = "c:\\job001\\compositethis.bat";
var m_wEntryBatPath;

var m_nValueCompMethod = "composite -compose atop -geometry 640x480";
var m_wEntryCompMethod;

// list of illegal characters for filename prefixes
// note: the 7 following characters 
// are in fact legal for fat32 : +,.;=[]
// but we disallow them 
var illegal = "\"*/:<>?\\|+,.;=[]";

//------------------------------------------------------
//------------------------------------------------------
//------------------------------------------------------
//------------------------------------------------------
//------------------------------------------------------
//------------------------------------------------------
// create dialog and its layout
var wDlg = new DzDialog;
wDlg.caption = "compoZ v1.0";

var wDlgLayout = new DzGridLayout( wDlg );
wDlgLayout.margin = 5;
wDlgLayout.spacing = 5;

//======================================================
// background images settings
//======================================================
// create a group box for the background images settings
var wDlgBkgGB = new DzVGroupBox( wDlg );
wDlgBkgGB.columns = 2;
wDlgBkgGB.title = "Background Images";

//------------------------------------------------------
new DzLabel( wDlgBkgGB ).text = "Loop Range Start image number:";

m_wEntryBkgStart = new DzLineEdit( wDlgBkgGB );
m_wEntryBkgStart.inputMask = "#####";
m_wEntryBkgStart.alignment = AlignRight;
m_wEntryBkgStart.maxWidth = SMALLWIDTH;
m_wEntryBkgStart.text = m_nValueBkgStart;

//------------------------------------------------------
new DzLabel( wDlgBkgGB ).text = "Loop Range End image number:";

m_wEntryBkgEnd = new DzLineEdit( wDlgBkgGB );
m_wEntryBkgEnd.inputMask = "#####";
m_wEntryBkgEnd.alignment = AlignRight;
m_wEntryBkgEnd.maxWidth = SMALLWIDTH;
m_wEntryBkgEnd.text = m_nValueBkgEnd;

//------------------------------------------------------
new DzLabel( wDlgBkgGB ).text = "First Image Number Used";

m_wEntryBkgOffset = new DzLineEdit( wDlgBkgGB );
m_wEntryBkgOffset.inputMask = "#####";
m_wEntryBkgOffset.alignment = AlignRight;
m_wEntryBkgOffset.maxWidth = SMALLWIDTH;
m_wEntryBkgOffset.text = m_nValueBkgOffset;

//------------------------------------------------------
new DzLabel( wDlgBkgGB ).text = "Filename prefix ( ex: image ):";

m_wEntryBkgPfx = new DzLineEdit( wDlgBkgGB );
m_wEntryBkgPfx.alignment = AlignRight;
m_wEntryBkgPfx.maxWidth = SMALLWIDTH;
m_wEntryBkgPfx.text = m_nValueBkgPfx;

//------------------------------------------------------
new DzLabel( wDlgBkgGB ).text = "File number padding";

m_wEntryBkgPad = new DzComboBox( wDlgBkgGB );
m_wEntryBkgPad.insertItem( "0" );
m_wEntryBkgPad.insertItem( "1" );
m_wEntryBkgPad.insertItem( "2" );
m_wEntryBkgPad.insertItem( "3" );
m_wEntryBkgPad.insertItem( "4" );
m_wEntryBkgPad.insertItem( "5" );
m_wEntryBkgPad.maxWidth = SMALLWIDTH;
m_wEntryBkgPad.currentItem = m_nValueBkgPad;

//------------------------------------------------------
new DzLabel( wDlgBkgGB ).text = "Image format (ex: jpg)";

m_wEntryBkgType = new DzLineEdit( wDlgBkgGB );
m_wEntryBkgType.alignment = AlignRight;
m_wEntryBkgType.maxWidth = SMALLWIDTH;
m_wEntryBkgType.text = m_nValueBkgType;

//------------------------------------------------------
new DzLabel( wDlgBkgGB  ).text = "Path to images";

wDlgBkgGB.addSpace( 1 );

//-----------------------------------------------------------
m_wEntryBkgPath = new DzLineEdit( wDlgBkgGB  );
m_wEntryBkgPath.alignment = AlignRight;
m_wEntryBkgPath.text = m_nValueBkgPath;

// browse button 
var wPathBkgBrowseBtn = new DzPushButton( wDlgBkgGB  );
wPathBkgBrowseBtn.text = "...";
wPathBkgBrowseBtn.maxWidth = SMALLWIDTH;
wPathBkgBrowseBtn.maxHeight = 20;

connect( wPathBkgBrowseBtn, "clicked()", browseForBkgPath );

wDlgLayout.addWidget( wDlgBkgGB, 0, 0);


//======================================================
//======================================================
//======================================================
//======================================================
//======================================================
// Foreground images settings
//======================================================

// create a group box for the foreg images settings
var wDlgFrgGB = new DzVGroupBox( wDlg );
wDlgFrgGB.columns = 2;
wDlgFrgGB.title = "Foreground Images (with Alpha Channel)";

//------------------------------------------------------
new DzLabel( wDlgFrgGB ).text = "Start frame:";

m_wEntryFrgStart = new DzLineEdit( wDlgFrgGB );
m_wEntryFrgStart.inputMask = "#####";
m_wEntryFrgStart.alignment = AlignRight;
m_wEntryFrgStart.maxWidth = SMALLWIDTH;
m_wEntryFrgStart.text = m_nValueFrgStart;

//------------------------------------------------------
new DzLabel( wDlgFrgGB ).text = "End frame:";

m_wEntryFrgEnd = new DzLineEdit( wDlgFrgGB );
m_wEntryFrgEnd.inputMask = "#####";
m_wEntryFrgEnd.alignment = AlignRight;
m_wEntryFrgEnd.maxWidth = SMALLWIDTH;
m_wEntryFrgEnd.text = m_nValueFrgEnd;

//------------------------------------------------------
new DzLabel( wDlgFrgGB ).text = "Filename prefix ( ex: image ):";

m_wEntryFrgPfx = new DzLineEdit( wDlgFrgGB );
m_wEntryFrgPfx.alignment = AlignRight;
m_wEntryFrgPfx.maxWidth = SMALLWIDTH;
m_wEntryFrgPfx.text = m_nValueFrgPfx;

//------------------------------------------------------
new DzLabel( wDlgFrgGB ).text = "File number padding";

m_wEntryFrgPad = new DzComboBox( wDlgFrgGB );
m_wEntryFrgPad.insertItem( "0" );
m_wEntryFrgPad.insertItem( "1" );
m_wEntryFrgPad.insertItem( "2" );
m_wEntryFrgPad.insertItem( "3" );
m_wEntryFrgPad.insertItem( "4" );
m_wEntryFrgPad.insertItem( "5" );
m_wEntryFrgPad.maxWidth = SMALLWIDTH;
m_wEntryFrgPad.currentItem = m_nValueFrgPad;

//------------------------------------------------------
new DzLabel( wDlgFrgGB ).text = "Image format";

m_wEntryFrgType = new DzLineEdit( wDlgFrgGB );
m_wEntryFrgType.alignment = AlignRight;
m_wEntryFrgType.maxWidth = SMALLWIDTH;
m_wEntryFrgType.text = m_nValueFrgType;

//-----------------------------------------------------------
new DzLabel( wDlgFrgGB ).text = "Path to images";

wDlgFrgGB.addSpace( 1 );

m_wEntryFrgPath = new DzLineEdit( wDlgFrgGB  );
m_wEntryFrgPath.alignment = AlignRight;
m_wEntryFrgPath.text = m_nValueFrgPath;


// browse button 
var wPathFrgBrowseBtn = new DzPushButton( wDlgFrgGB  );
wPathFrgBrowseBtn.text = "...";
wPathFrgBrowseBtn.maxWidth = SMALLWIDTH;
wPathFrgBrowseBtn.maxHeight = 20;

connect( wPathFrgBrowseBtn, "clicked()", browseForFrgPath );

wDlgLayout.addWidget( wDlgFrgGB, 0, 1);

//======================================================
//======================================================
//======================================================
//======================================================
//======================================================
// Output images settings
//======================================================

// create a group box for the output images settings
var wDlgOutGB = new DzVGroupBox( wDlg );
wDlgOutGB.columns = 2;
wDlgOutGB.title = "Output Images (composited)";

//------------------------------------------------------
new DzLabel( wDlgOutGB ).text = "First frame number:";

m_wEntryOutStart = new DzLineEdit( wDlgOutGB );
m_wEntryOutStart.inputMask = "#####";
m_wEntryOutStart.alignment = AlignRight;
m_wEntryOutStart.maxWidth = SMALLWIDTH;
m_wEntryOutStart.text = m_nValueOutStart;

//------------------------------------------------------
new DzLabel( wDlgOutGB ).text = "Filename prefix ( ex: image ):";

m_wEntryOutPfx = new DzLineEdit( wDlgOutGB );
m_wEntryOutPfx.alignment = AlignRight;
m_wEntryOutPfx.maxWidth = SMALLWIDTH;
m_wEntryOutPfx.text = m_nValueOutPfx;

//------------------------------------------------------
new DzLabel( wDlgOutGB ).text = "File number padding";

m_wEntryOutPad = new DzComboBox( wDlgOutGB );
m_wEntryOutPad.insertItem( "0" );
m_wEntryOutPad.insertItem( "1" );
m_wEntryOutPad.insertItem( "2" );
m_wEntryOutPad.insertItem( "3" );
m_wEntryOutPad.insertItem( "4" );
m_wEntryOutPad.insertItem( "5" );
m_wEntryOutPad.maxWidth = SMALLWIDTH;
m_wEntryOutPad.currentItem = m_nValueOutPad;

//------------------------------------------------------
new DzLabel( wDlgOutGB ).text = "Image format";

m_wEntryOutType = new DzLineEdit( wDlgOutGB );
m_wEntryOutType.alignment = AlignRight;
m_wEntryOutType.maxWidth = SMALLWIDTH;
m_wEntryOutType.text = m_nValueOutType;

//-----------------------------------------------------------
new DzLabel( wDlgOutGB ).text = "Path to images";

wDlgOutGB.addSpace( 1 );

m_wEntryOutPath = new DzLineEdit( wDlgOutGB  );
m_wEntryOutPath.alignment = AlignRight;
m_wEntryOutPath.text = m_nValueOutPath;


// browse button 
var wPathOutBrowseBtn = new DzPushButton( wDlgOutGB  );
wPathOutBrowseBtn.text = "...";
wPathOutBrowseBtn.maxWidth = SMALLWIDTH;
wPathOutBrowseBtn.maxHeight = 20;

connect( wPathOutBrowseBtn, "clicked()", browseForOutPath );

wDlgLayout.addWidget( wDlgOutGB, 1, 0);

//======================================================
//======================================================
//======================================================
//======================================================
//======================================================
// Job Control
//======================================================
// create a group box for the job control 
var wDlgJobGB = new DzVGroupBox( wDlg );
wDlgJobGB.columns = 2;
wDlgJobGB.title = "Batch file creation";

//------------------------------------------------------
new DzLabel( wDlgJobGB ).text = "Path to Compositing Utilities";

wDlgJobGB.addSpace( 1 );

m_wEntryMgkPath = new DzLineEdit( wDlgJobGB  );
m_wEntryMgkPath.alignment = AlignRight;
m_wEntryMgkPath.text = m_nValueMgkPath;

// browse button 
var wPathMgkBrowseBtn = new DzPushButton( wDlgJobGB  );
wPathMgkBrowseBtn.text = "...";
wPathMgkBrowseBtn.maxWidth = SMALLWIDTH;
wPathMgkBrowseBtn.maxHeight = 20;

connect( wPathMgkBrowseBtn, "clicked()", browseForMgkPath );


//------------------------------------------------------
new DzLabel( wDlgJobGB ).text = "Compositing formula (advanced users)";

wDlgJobGB.addSpace( 1 );

m_wEntryCompMethod = new DzLineEdit( wDlgJobGB  );
m_wEntryCompMethod.alignment = AlignRight;
m_wEntryCompMethod.text = m_nValueCompMethod;

wDlgJobGB.addSpace( 1 );

//------------------------------------------------------
new DzLabel( wDlgJobGB ).text = "Path to Batch file created by this script";

wDlgJobGB.addSpace( 1 );

m_wEntryBatPath = new DzLineEdit( wDlgJobGB  );
m_wEntryBatPath.alignment = AlignRight;
m_wEntryBatPath.text = m_nValueBatPath;


// browse button 
var wPathBatBrowseBtn = new DzPushButton( wDlgJobGB  );
wPathBatBrowseBtn.text = "...";
wPathBatBrowseBtn.maxWidth = SMALLWIDTH;
wPathBatBrowseBtn.maxHeight = 20;

connect( wPathBatBrowseBtn, "clicked()", browseForBatPath );

wDlgLayout.addWidget( wDlgJobGB, 1, 1);

//=============================================================

// create the doit button
var wdoitBtn = new DzPushButton( wDlgJobGB  );
wdoitBtn.text = "&Do it";
wdoitBtn.maxWidth = 80;
wdoitBtn.maxHeight = 20;
connect( wdoitBtn, "clicked()", doit );

// create the cancel button
var wCancelBtn = new DzPushButton( wDlgJobGB  );
wCancelBtn.text = "&Cancel";
wCancelBtn.maxWidth = 80;
wCancelBtn.maxHeight = 20;
wDlg.setRejectButton( wCancelBtn );

wDlg.exec();


//=============================================================
//=============================================================
//=============================================================
//=============================================================
// transfer data from controls to global variables
//=============================================================
function transfer()
{
m_nValueBkgStart  = parseInt( m_wEntryBkgStart.text );
m_nValueBkgEnd    = parseInt( m_wEntryBkgEnd.text );
m_nValueBkgOffset = parseInt( m_wEntryBkgOffset.text );
m_nValueBkgPfx    =           m_wEntryBkgPfx.text;
m_nValueBkgType   =           m_wEntryBkgType.text;
m_nValueBkgPad    =           m_wEntryBkgPad.currentItem;
m_nValueBkgPath   =           m_wEntryBkgPath.text;

m_nValueFrgStart  = parseInt( m_wEntryFrgStart.text );
m_nValueFrgEnd    = parseInt( m_wEntryFrgEnd.text );
m_nValueFrgPfx    =           m_wEntryFrgPfx.text;
m_nValueFrgType   =           m_wEntryFrgType.text;
m_nValueFrgPad    =           m_wEntryFrgPad.currentItem;
m_nValueFrgPath   =           m_wEntryFrgPath.text;

m_nValueOutStart  =  parseInt( m_wEntryOutStart.text );
m_nValueOutPfx    =            m_wEntryOutPfx.text;
m_nValueOutType   =            m_wEntryOutType.text;
m_nValueOutPad    =            m_wEntryOutPad.currentItem;
m_nValueOutPath   =            m_wEntryOutPath.text;

m_nValueMgkPath   =            m_wEntryMgkPath.text;

m_nValueCompMethod=            m_wEntryCompMethod.text;

m_nValueBatPath   =            m_wEntryBatPath.text;
}

//=============================================================
// review user provided data for validity
// a global string named "msg" is used
// returns true if all the data is valid
// else returns false and msg will contain a description 
// of the first invalid data encountered
//=============================================================
function validate()
{
var section;

msg = "";

//.............................................................
section = "Background Images, ";
if( m_nValueBkgStart < 0 )
	{
	msg = section + "Start_image_number has a negative value";
	return( false );
	}
if( m_nValueBkgStart > m_nValueBkgEnd )
	{
	msg = section + "Start_image_number is greater than End_Image_Number";
	return( false );
	}

//the two conditions above imply that m_nValueBkgEnd is valid

//we accept anything for m_nValueBkgOffset, except negative values
if( m_nValueBkgOffset < 0 )
	{
	msg = section + "First Imange Number Used has a negative value";
	return( false );
	}

//pfx must be letters numbers and/or underscore
if( containsillegalchars( m_nValueBkgPfx ) )
	{
	msg = section + "Prefix contains illegal characters.\n List of illegal characters: ( " + illegal + " )";
	return( false );
	}

//m_nValueBkgType must be one of the 100 supported by imagemagick
// TODO m_nValueBkgType

//padding is always valid 
//m_nValueBkgPad

//path must exist
d = new DzDir( m_nValueBkgPath );
if( !d.exists() )
	{
	msg = section + "Directory does not exist";
	return( false );
	}
//.............................................................
section = "Foreground Images, ";
if( m_nValueFrgStart < 0 )
	{
	msg = section + "Start_image_number has a negative value";
	return( false );
	}
if( m_nValueFrgStart > m_nValueFrgEnd )
	{
	msg = section + "Start_image_number is greater than End_Image_Number";
	return( false );
	}

//the two conditions above imply that m_nValueFrgEnd is valid

//pfx must be letters numbers and/or underscore
if( containsillegalchars( m_nValueFrgPfx ) )
	{
	msg = section + "Prefix contains illegal characters";
	return( false );
	}

//m_nValueFrgType should be one of the formats allowed by the compositer
//m_nValueFrgType

//padding is always valid 
//m_nValueFrgPad

//path must exist
d = new DzDir( m_nValueFrgPath );
if( !d.exists() )
	{
	msg = section + "Directory does not exist";
	return( false );
	}

//.............................................................
section = "Output Images (composited), ";
if( m_nValueOutStart < 0 )
	{
	msg = section + "First Image Number has a negative value";
	return( false );
	}

//pfx must be letters numbers and/or underscore
if( containsillegalchars( m_nValueOutPfx ) )
	{
	msg = section + "Prefix contains illegal characters";
	return( false );
	}

//m_nValueOutType should be one of the formats supported by the compositing utility
//m_nValueOutType TODO

//padding is always valid 
//m_nValueOutPad

//path must exist
d = new DzDir( m_nValueOutPath );
if( !d.exists() )
	{
	msg = section + "Directory does not exist";
	return( false );
	}

//.............................................................
section = "Batch Creation, ";
//path must exist
d = new DzDir( m_nValueMgkPath );
if( !d.exists() )
	{
	msg = section + "Imagemagick directory does not exist";
	return( false );
	}

//batch file creation must work
var oFile = new DzFile( m_nValueBatPath );
if( ! oFile.open( DzFile.WriteOnly ) )
	{
	msg = section + "Location or filename for batch file not valid";
	return( false );	
	}
oFile.close();

msg = "";
return( true );
}

//=============================================================
// browse to Bkg images directory
//=============================================================
function browseForBkgPath()
{
var path = FileDialog.doDirectoryDialog( "Select a directory", "" );
if( path )
	{
	m_nValueBkgPath = path
	m_wEntryBkgPath.text = m_nValueBkgPath;
	}
}

//=============================================================
// browse to Frg Images directory
//=============================================================
function browseForFrgPath()
{
var path = FileDialog.doDirectoryDialog( "Select a directory", "" );
if( path )
	{
	m_nValueFrgPath = path
	m_wEntryFrgPath.text = m_nValueFrgPath;
	}
}

//=============================================================
// browse to Output Images  directory
//=============================================================
function browseForOutPath()
{
var path = FileDialog.doDirectoryDialog( "Select a directory", "" );
if( path )
	{
	m_nValueOutPath = path
	m_wEntryOutPath.text = m_nValueOutPath;
	}

}
//=============================================================
// browse to Imagemagick directory
//=============================================================
function browseForMgkPath()
{
var path = FileDialog.doDirectoryDialog( "Select a directory", "" );
if( path )
	{
	m_nValueMgkPath = path
	m_wEntryMgkPath.text = m_nValueMgkPath;
	}
}
//=============================================================
// browse to location of Batch file that will be created
// and specify filename
//=============================================================
function browseForBatPath()
{
var filename = FileDialog.doFileDialog( false, "Save Batch File As", "", "Batch Files (*.bat)" );
if( filename )
	{
	m_nValueBatPath = filename
	m_wEntryBatPath.text = m_nValueBatPath;
	}
}

//=============================================================
// transfer data, validate data, if ok, do it, really i mean
//=============================================================
function doit()
{
transfer();
var res = validate();
if( !res )
	{
	MessageBox.warning( msg, "Error", "&OK", "" ); 
	}
else
	{
	reallydoit();
	}
}
//=============================================================
//
//=============================================================
function reallydoit()
{
oFile = new DzFile( m_nValueBatPath );
oFile.open( DzFile.WriteOnly );

var iOut = m_nValueOutStart;
var iBkg = m_nValueBkgStart; //m_nValueBkgStart;

if( iBkg > m_nValueBkgEnd )
	{
	iBkg = m_nValueBkgStart;
	}

var totalpics = m_nValueFrgEnd - m_nValueFrgStart + 1;

for( var iFrg = m_nValueFrgStart; iFrg <= m_nValueFrgEnd; iFrg++, iOut++ )
	{
	var fnFrg = m_nValueFrgPath + "\\" + m_nValueFrgPfx + padthis( iFrg, m_nValueFrgPad ) + "." + m_nValueFrgType;
	var fnBkg = m_nValueBkgPath + "\\" + m_nValueBkgPfx + padthis( iBkg, m_nValueBkgPad ) + "." + m_nValueBkgType;
	var fnOut = m_nValueOutPath + "\\" + m_nValueOutPfx + padthis( iOut, m_nValueOutPad ) + "." + m_nValueOutType;

	oFile.writeLine( 
		  m_nValueMgkPath 
		+ "\\"
		+ m_nValueCompMethod
		+ " \"" + fnFrg  + "\"" 
		+ " \"" + fnBkg  + "\"" 
		+ " \"" + fnOut  + "\"" );

	++iBkg;
	if( iBkg > m_nValueBkgEnd )
		{
		iBkg = m_nValueBkgStart;
		}
	}

oFile.close();

App.statusLine( "Batch file created for " + totalpics + " images" );

wDlg.close();
}

//-----------------------------------------------------------
//
//-----------------------------------------------------------
function padthis( i, padd )
{
if( padd <= 1 ) 
	return( i );

//ex padd=6, 000000, 100000 or 10^5is the first comparison
var str = "";
var decade = Math.pow(10,padd-1);
for( j = padd-1; j > 0; j-- ) 
	{
	if( i < decade )
		{
		str = str + "0";
		}
	decade = decade / 10;	
	}
str = str + i;
return( str );
}

//-----------------------------------------------------------
//
//-----------------------------------------------------------
function containsillegalchars( name )
{
for( var i = 0; i < name.length; i++ )
	{
	if( illegal.find( name.charAt(i)) >= 0 )
		{
		return( true );
    		}
	}
return( false );
}


1