home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / leadtools / ocx32.lt / Main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-01  |  45.2 KB  |  1,247 lines

  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <printers.hpp>
  4. #pragma hdrstop
  5.  
  6. #include "Main.h"
  7. #include "ListDiag.h"
  8. #include "ColorRes.h"
  9. #include "Info.h"
  10. #include "About.h"
  11. #include "..\..\..\include\l_ocxcb.h"
  12. //---------------------------------------------------------------------
  13. #pragma link "LTOCX10N"
  14. #pragma resource "*.dfm"
  15.  
  16. #define MAX_STRING_LIST 8
  17.  
  18. TMainForm *MainForm;
  19.  
  20. char szLoadFilter[] = "All files (*.*)|*.*|LEAD|*.cmp|JPEG|*.jpg|CALS 1|*.cal|Compuserve PNG|*.png|"\
  21.          "EPS|*.eps|GEM|*.gem|GIF|*.gif|IOCA|*.ica|Mac PICT|*.pct|"\
  22.          "MacPaint|*.mac|MSP|*.msp|PCX|*.pcx|PSD|*.psd|SUN|*.ras|TGA|*.tga|"\
  23.          "TIFF|*.tif;*.jtf|BMP|*.bmp|FPX|*.fpx|DIC|*.dic|ICO|*.ico|CUR|*.cur|AWD|*.awd";
  24.  
  25. char szSaveFilter[] = "LEAD|*.cmp|JPEG|*.jpg|CALS|*.cal|PNG|*.png|" \
  26.          "EPS|*.eps|GEM|*.gem|GIF|*.gif|IOCA|*.ica|Mac PICT|*.pct|" \
  27.          "MacPaint|*.mac|MSP|*.msp|PCX|*.pcx|PSD|*.psd|SUN|*.ras|TGA|*.tga|"\
  28.          "TIF|*.tif|TIF CCITT|*.tif|TIF JPEG|*.jtf|TIF LZW|*.tif|BMP|*.bmp|FPX|*.fpx|"\
  29.          "RLE|*.rle|TIF CMYK|*.tif|TIF LZW CMYK|*.tif|TIF RLE|*.tif|TIF RLE CMYK|*.tif|"\
  30.          "DICOM Gray|*.dic|DICOM Color|*.dic|ICON|*.ico|CURSOR|*.cur|"\
  31.          "TIF YCC|*.tif|TIF LZW YCC|*.tif|TIF RLE YCC|*.tif|EXIF|*.tif|EXIF YCC|*.tif|"\
  32.          "EXIF JPEG|*.jpg|AWD|*.awd";
  33.  
  34. String aGradientList[]= {"North","North-East","East","South-East","South","South-West","West","North-West"};
  35. String aLaplacianList[] = {"Filter 1", "Filter 2", "Filter 3","Diagonal", "Horizontal", "Vertical", "", "" };
  36. String aHorzVertList[] = { "Horizontal", "Vertical", "", "", "", "", "" , "" };
  37. String aShiftDiffList[] = { "Diagonal", "Horizontal", "Vertical", "", "", "", "", "" };
  38. String aLineSegmentList[] = { "Horizontal", "Vertical", "Left to Right", "Right to Left", "", "", "", "" };
  39. String aBinaryFilterList[] = { "Omnidirectional", "Horizontal", "Vertical", "Diagonal", "", "", "", ""};
  40. String aChannelList[] = { "Master", "Red", "Green", "Blue", "", "", "", "" };
  41. String aEffectList[] = {
  42.    "Wipe left to right",
  43.    "Wipe right to left",
  44.    "Wipe top to bottom",
  45.    "Wipe bottom to top",
  46.    "Wipe left-top to right-bottom",
  47.    "Wipe left-bottom to right-top",
  48.    "Wipe right-top to left-bottom",
  49.    "Wipe right-bottom to left-top",
  50.    "Wipe horizontal interlace left to right twice",
  51.    "Wipe vertical interlace top to bottom twice",
  52.    "Wipe horizontal interlace left to right then back",
  53.    "Wipe vertical interlace top to bottom then back",
  54.    "Wipe vertical interlace left to right twice",
  55.    "Wipe vertical interlace right to left twice",
  56.    "Wipe horizontal interlace top to bottom twice",
  57.    "Wipe horizontal interlace bottom to top twice",
  58.    "Wipe vertical interlace left to right then back",
  59.    "Wipe vertical interlace right to left then back",
  60.    "Wipe horizontal interlace top to bottom then back",
  61.    "Wipe horizontal interlace bottom to top then back",
  62.    "Wipe horizontal interlace left to right and right to left",
  63.    "Wipe vertical interlace top to bottom and bottom to top",
  64.    "Wipe vertical interlace left and right to center",
  65.    "Wipe vertical interlace center to left and right",
  66.    "Wipe horizontal interlace top and bottom to center",
  67.    "Wipe horizontal interlace center to top and bottom",
  68.    "Wipe vertical interlace left and right to center then back",
  69.    "Wipe vertical interlace center to left and right then back",
  70.    "Wipe horizontal interlace top and bottom to center then back",
  71.    "Wipe horizontal interlace center to top and bottom then back",
  72.    "Wipe2 left-top and right-bottom to center",
  73.    "Wipe2 left-bottom and right-top to center",
  74.    "Wipe2 center to left-top and right-bottom",
  75.    "Wipe2 center to left-bottom and right-top",
  76.    "Wipe2 left-bottom and right-bottom to top",
  77.    "Wipe2 left-top and right-top to bottom",
  78.    "Wipe2 right-top and right-bottom to left",
  79.    "Wipe2 left-top and left-bottom to right",
  80.    "Wipe2 left top to bottom and right bottom to top",
  81.    "Wipe2 top left to right and bottom right to left",
  82.    "Wipe4 corners out",
  83.    "Wipe4 center to left and right then top and bottom",
  84.    "Wipe4 top and bottom then left and right to center",
  85.  };
  86.  
  87. //---------------------------------------------------------------------
  88. __fastcall TMainForm::TMainForm(TComponent *Owner)
  89.     : TForm(Owner)
  90. {
  91. }
  92. //---------------------------------------------------------------------
  93. void __fastcall TMainForm::FormCreate(TObject *Sender)
  94. {
  95.     HiddenLead->UnlockSupport(L_SUPPORT_EXPRESS, L_KEY_EXPRESS);
  96.     HiddenLead->UnlockSupport(L_SUPPORT_GIFLZW, L_KEY_GIFLZW);
  97.     HiddenLead->UnlockSupport(L_SUPPORT_TIFLZW, L_KEY_TIFLZW);
  98.     HiddenLead->Visible = FALSE;
  99.     Application->OnHint = ShowHint;
  100.     Screen->OnActiveFormChange = UpdateMenuItems;
  101. }
  102. //---------------------------------------------------------------------
  103. void __fastcall TMainForm::ShowHint(TObject *Sender)
  104. {
  105.     StatusBar->SimpleText = Application->Hint;
  106. }
  107. //---------------------------------------------------------------------
  108. void __fastcall TMainForm::CreateMDIChild(String Name)
  109. {
  110.     TMDIChild *Child;
  111.     int       nRet;
  112.  
  113.     //--- create a new MDI child window ----
  114.     Child = new TMDIChild(Application);
  115.     Child->Lead1->EnableProgressEvent = Statusbar1->Checked;
  116.     Child->InitStatusProcess("Loading: " + Name);
  117.     try
  118.      {
  119.         nRet = Child->Lead1->Load(Name,0,0,1);
  120.         Child->ResetStatusProcess();
  121.         if(nRet == 0)
  122.          {
  123.            Child->Lead1->AutoAnimate=true;
  124.            Child->Lead1->AutoRepaint=false;
  125.            Child->Lead1->PaintPalette=HiddenLead->PaintPalette;
  126.            Child->Lead1->PaintDither=HiddenLead->PaintDither;
  127.            Child->Lead1->BitonalScaling=HiddenLead->BitonalScaling;
  128.            Child->Lead1->EnableProgressEvent=HiddenLead->EnableProgressEvent;
  129.            Child->Lead1->AutoRepaint=true;
  130.            Child->ZoomMode=PAINTSIZEMODE_NORMAL;
  131.            Child->ZoomSize=100;
  132.            Child->RegionTool=RGNMARK_NONE;
  133.            Child->Caption = Name;
  134.          }
  135.         else
  136.             Child->Close();
  137.      }
  138.     catch(...)
  139.      {
  140.        Child->Close();
  141.      }
  142. }
  143. //---------------------------------------------------------------------
  144. void __fastcall TMainForm::FileNewItemClick(TObject *Sender)
  145. {
  146.     CreateMDIChild("NONAME" + IntToStr(MDIChildCount + 1));
  147. }
  148. //--------------------------------------------------------------------- 
  149. void __fastcall TMainForm::FileOpenItemClick(TObject *Sender)
  150. {
  151.     OpenDialog->Filter = szLoadFilter;
  152.     if (OpenDialog->Execute())
  153.         CreateMDIChild(OpenDialog->FileName);
  154. }
  155. //--------------------------------------------------------------------- 
  156. void __fastcall TMainForm::FileCloseItemClick(TObject *Sender)
  157. {
  158.     if (ActiveMDIChild)
  159.      {
  160.        ActiveMDIChild->Close();
  161.      }
  162. }
  163. //--------------------------------------------------------------------- 
  164. void __fastcall TMainForm::FileSaveItemClick(TObject *Sender)
  165. {
  166.     //---- save current file (ActiveMDIChild points to the window) ----
  167. }
  168. //--------------------------------------------------------------------- 
  169. void __fastcall TMainForm::FileSaveAsItemClick(TObject *Sender)
  170. {
  171.    ((TMDIChild *)ActiveMDIChild)->SaveImage();
  172. }
  173. //--------------------------------------------------------------------- 
  174. void __fastcall TMainForm::FileExitItemClick(TObject *Sender)
  175. {
  176.     Close();
  177. }
  178. //--------------------------------------------------------------------- 
  179. void __fastcall TMainForm::CutItemClick(TObject *Sender)
  180. {
  181.     //---- cut selection to clipboard ----
  182. }
  183. //--------------------------------------------------------------------- 
  184. void __fastcall TMainForm::CopyItemClick(TObject *Sender)
  185. {
  186.   if (((TMDIChild *)ActiveMDIChild)->Lead1->Copy(COPY_EMPTY + COPY_DIB + COPY_PALETTE)!=0)
  187.      Application->MessageBox("Error copying to clipboard","Error",MB_ICONINFORMATION);
  188.   UpdateMenuItems(Sender);
  189. }
  190. //--------------------------------------------------------------------- 
  191. void __fastcall TMainForm::PasteItemClick(TObject *Sender)
  192. {
  193.   TMDIChild *Child;
  194.  
  195.   if(HiddenLead->Paste(PASTE_ISREADY)!=0)
  196.    {
  197.       Child = new TMDIChild(Application);
  198.       Child->Caption = "Clipboard image";
  199.       Child->Lead1->AutoAnimate=true;
  200.       Child->Lead1->AutoRepaint=false;
  201.       Child->Lead1->PaintPalette=HiddenLead->PaintPalette;
  202.       Child->Lead1->PaintDither=HiddenLead->PaintDither;
  203.       Child->Lead1->BitonalScaling=HiddenLead->BitonalScaling;
  204.       Child->Lead1->EnableProgressEvent=HiddenLead->EnableProgressEvent;
  205.       Child->Lead1->AutoRepaint=true;
  206.       Child->ZoomMode=PAINTSIZEMODE_NORMAL;
  207.       Child->ZoomSize=100;
  208.       Child->RegionTool=RGNMARK_NONE;
  209.       if(Child->Lead1->Paste(0)!= 0)
  210.         Child->Close();
  211.    }
  212. }
  213. //---------------------------------------------------------------------
  214. void __fastcall TMainForm::WindowCascadeItemClick(TObject *Sender)
  215. {
  216.     Cascade();
  217. }
  218. //---------------------------------------------------------------------
  219. void __fastcall TMainForm::WindowTileItemClick(TObject *Sender)
  220. {
  221.     Tile();
  222. }
  223. //---------------------------------------------------------------------
  224. void __fastcall TMainForm::WindowArrangeItemClick(TObject *Sender)
  225. {
  226.     ArrangeIcons();
  227. }
  228. //---------------------------------------------------------------------
  229. void __fastcall TMainForm::WindowMinimizeItemClick(TObject *Sender)
  230. {
  231.     int i;
  232.  
  233.     //---- Must be done backwards through the MDIChildren array ----
  234.     for (i=MDIChildCount-1; i >= 0; i--)
  235.         MDIChildren[i]->WindowState = wsMinimized;
  236. }
  237. //--------------------------------------------------------------------- 
  238. void __fastcall TMainForm::UpdateMenuItems(TObject *Sender)
  239. {
  240.     FileCloseItem->Enabled = MDIChildCount > 0;
  241.     FileSaveAsItem->Enabled = MDIChildCount > 0;
  242.     CopyItem->Enabled = MDIChildCount > 0;
  243.     PasteItem->Enabled = (HiddenLead->Paste(PASTE_ISREADY)!=0);
  244.     SaveBtn->Enabled = MDIChildCount > 0;
  245.     CopyBtn->Enabled = MDIChildCount > 0;
  246.     PasteBtn->Enabled = PasteItem->Enabled;
  247.     WindowCascadeItem->Enabled = MDIChildCount > 0;
  248.     WindowTileItem->Enabled = MDIChildCount > 0;
  249.     WindowArrangeItem->Enabled = MDIChildCount > 0;
  250.     WindowMinimizeItem->Enabled = MDIChildCount > 0;
  251.     View1->Enabled = MDIChildCount > 0;
  252.     Image1->Enabled = MDIChildCount > 0;
  253.     Color1->Enabled = MDIChildCount > 0;
  254.     Print1->Enabled = MDIChildCount > 0;
  255.     SelectRegion1->Enabled = MDIChildCount > 0;
  256.     if(MDIChildCount>0)
  257.     {
  258.       Effects1->Checked =(((TMDIChild *)ActiveMDIChild)->Lead1->PaintEffect!=EFX_EFFECT_NONE);
  259.       if(((TMDIChild *)ActiveMDIChild)->Lead1->Bitmap!=0)
  260.         CancelRegion1->Enabled=((TMDIChild *)ActiveMDIChild)->Lead1->HasRgn;
  261.       else
  262.         CancelRegion1->Enabled=false;
  263.       int zm=((TMDIChild *)ActiveMDIChild)->ZoomMode;
  264.       int wz=((TMDIChild *)ActiveMDIChild)->ZoomSize;
  265.       N2x1->Checked=false;
  266.       N3x1->Checked=false;
  267.       N4x1->Checked=false;
  268.       N121->Checked=false;
  269.       N131->Checked=false;
  270.       N141->Checked=false;
  271.       switch(zm)
  272.       {
  273.          case PAINTSIZEMODE_NORMAL:
  274.            Normal1->Checked=true;
  275.            break;
  276.          case PAINTSIZEMODE_FIT:
  277.            FitToWindow1->Checked=true;
  278.            break;
  279.          case PAINTSIZEMODE_ZOOM:
  280.            if(wz==1 || wz==2 || wz==3)
  281.             {
  282.               ZoomIn1->Checked=true;
  283.               ZoomOut1->Checked=false;
  284.             }
  285.            else
  286.             {
  287.               ZoomOut1->Checked=true;
  288.               ZoomIn1->Checked=false;
  289.             }
  290.            switch(wz)
  291.             {
  292.               case 1: N2x1->Checked=true; break;
  293.               case 2: N3x1->Checked=true; break;
  294.               case 3: N4x1->Checked=true; break;
  295.               case 4: N121->Checked=true; break;
  296.               case 5: N131->Checked=true; break;
  297.               case 6: N141->Checked=true; break;
  298.             }
  299.       }
  300.     }
  301. }
  302. //--------------------------------------------------------------------- 
  303. void __fastcall TMainForm::FormDestroy(TObject *Sender)
  304. {
  305.     Screen->OnActiveFormChange = NULL;
  306. }
  307. //---------------------------------------------------------------------
  308. void __fastcall TMainForm::Statusbar1Click(TObject *Sender)
  309. {
  310.   int i;
  311.  
  312.   if(Statusbar1->Checked == false)
  313.    {
  314.      HiddenLead->EnableProgressEvent = Statusbar1->Checked = true;
  315.    }
  316.   else
  317.     Statusbar1->Checked = false;
  318.   for(i=0;i<MDIChildCount-1;i++)
  319.    {
  320.      ((TMDIChild *)MDIChildren[i])->Lead1->EnableProgressEvent = Statusbar1->Checked;
  321.    }
  322. }
  323. //---------------------------------------------------------------------------
  324. void __fastcall TMainForm::Normal1Click(TObject *Sender)
  325. {
  326.   Normal1->Checked=true;
  327.   ((TMDIChild *)ActiveMDIChild)->Lead1->PaintSizeMode = PAINTSIZEMODE_NORMAL;
  328.   ((TMDIChild *)ActiveMDIChild)->ZoomMode = PAINTSIZEMODE_NORMAL;
  329. }
  330. //---------------------------------------------------------------------------
  331. void __fastcall TMainForm::FitToWindow1Click(TObject *Sender)
  332. {
  333.   FitToWindow1->Checked = true;
  334.   ((TMDIChild *)ActiveMDIChild)->Lead1->PaintSizeMode = PAINTSIZEMODE_FIT;
  335.   ((TMDIChild *)ActiveMDIChild)->ZoomMode = PAINTSIZEMODE_FIT;
  336. }
  337. //---------------------------------------------------------------------------
  338. void __fastcall TMainForm::Print1Click(TObject *Sender)
  339. {
  340.    int w,h;
  341.    TPrinter *Printer;
  342.  
  343.    Printer = new TPrinter;
  344.    Cursor=crHourGlass;
  345.    Printer->BeginDoc();
  346.    w = ((TMDIChild *)ActiveMDIChild)->Lead1->BitmapWidth;
  347.    h = ((TMDIChild *)ActiveMDIChild)->Lead1->BitmapHeight;
  348.    ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Printing Image");
  349.    ((TMDIChild *)ActiveMDIChild)->Lead1->Render((int)Printer->Handle,0,0,w,h);
  350.    Printer->EndDoc();
  351.    ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  352.    Cursor=crDefault;
  353.    delete Printer;
  354. }
  355. //---------------------------------------------------------------------------
  356. void __fastcall TMainForm::PrintSetup1Click(TObject *Sender)
  357. {
  358.    PrinterSetupDialog1->Execute();
  359. }
  360. //---------------------------------------------------------------------------
  361. void __fastcall TMainForm::Rectangle1Click(TObject *Sender)
  362. {
  363.   Rectangle1->Checked=true;
  364.   ((TMDIChild *)ActiveMDIChild)->RegionTool=RGNMARK_RECT;
  365. }
  366. //---------------------------------------------------------------------------
  367. void __fastcall TMainForm::None1Click(TObject *Sender)
  368. {
  369.   None1->Checked=true;
  370.   ((TMDIChild *)ActiveMDIChild)->RegionTool=RGNMARK_NONE;
  371. }
  372. //---------------------------------------------------------------------------
  373. void __fastcall TMainForm::Ellispe1Click(TObject *Sender)
  374. {
  375.    Ellispe1->Checked=true;
  376.    ((TMDIChild *)ActiveMDIChild)->RegionTool=RGNMARK_ELLIPSE;    
  377. }
  378. //---------------------------------------------------------------------------
  379. void __fastcall TMainForm::RoundedRectangle1Click(TObject *Sender)
  380. {
  381.    RoundedRectangle1->Checked=true;
  382.    ((TMDIChild *)ActiveMDIChild)->RegionTool=RGNMARK_ROUNDRECT;
  383. }
  384. //---------------------------------------------------------------------------
  385. void __fastcall TMainForm::Freehand1Click(TObject *Sender)
  386. {
  387.    Freehand1->Checked=true;
  388.    ((TMDIChild *)ActiveMDIChild)->RegionTool=RGNMARK_FREEHAND;    
  389. }
  390. //---------------------------------------------------------------------------
  391. void __fastcall TMainForm::CancelRegion1Click(TObject *Sender)
  392. {
  393.   ((TMDIChild *)ActiveMDIChild)->CancelRegion();    
  394. }
  395. //---------------------------------------------------------------------------
  396. void __fastcall TMainForm::N2x1Click(TObject *Sender)
  397. {
  398.    ZoomIn1->Checked=true;
  399.    ZoomOut1->Checked=false;
  400.    N2x1->Checked=true;
  401.    ((TMDIChild *)ActiveMDIChild)->ZoomMode=PAINTSIZEMODE_ZOOM;
  402.    ((TMDIChild *)ActiveMDIChild)->ZoomImage(2,true);
  403.    ((TMDIChild *)ActiveMDIChild)->ZoomSize=1;
  404. }
  405. //---------------------------------------------------------------------------
  406. void __fastcall TMainForm::N3x1Click(TObject *Sender)
  407. {
  408.    N3x1->Checked=true;
  409.    ZoomIn1->Checked=true;
  410.    ZoomOut1->Checked=false;
  411.    ((TMDIChild *)ActiveMDIChild)->ZoomMode=PAINTSIZEMODE_ZOOM;
  412.    ((TMDIChild *)ActiveMDIChild)->ZoomImage(3,true);
  413.    ((TMDIChild *)ActiveMDIChild)->ZoomSize=2;
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TMainForm::N4x1Click(TObject *Sender)
  417. {
  418.    N4x1->Checked=true;
  419.    ZoomIn1->Checked=true;
  420.    ZoomOut1->Checked=false;
  421.    ((TMDIChild *)ActiveMDIChild)->ZoomMode=PAINTSIZEMODE_ZOOM;
  422.    ((TMDIChild *)ActiveMDIChild)->ZoomImage(4,true);
  423.    ((TMDIChild *)ActiveMDIChild)->ZoomSize=3;
  424. }
  425. //---------------------------------------------------------------------------
  426. void __fastcall TMainForm::N121Click(TObject *Sender)
  427. {
  428.    N121->Checked=true;
  429.    ZoomIn1->Checked=false;
  430.    ZoomOut1->Checked=true;
  431.    ((TMDIChild *)ActiveMDIChild)->ZoomMode=PAINTSIZEMODE_ZOOM;
  432.    ((TMDIChild *)ActiveMDIChild)->ZoomImage(2,false);
  433.    ((TMDIChild *)ActiveMDIChild)->ZoomSize=4;
  434. }
  435. //---------------------------------------------------------------------------
  436. void __fastcall TMainForm::N131Click(TObject *Sender)
  437. {
  438.    N131->Checked=true;
  439.    ZoomIn1->Checked=false;
  440.    ZoomOut1->Checked=true;
  441.    ((TMDIChild *)ActiveMDIChild)->ZoomMode=PAINTSIZEMODE_ZOOM;
  442.    ((TMDIChild *)ActiveMDIChild)->ZoomImage(3,false);
  443.    ((TMDIChild *)ActiveMDIChild)->ZoomSize=5;
  444. }
  445. //---------------------------------------------------------------------------
  446. void __fastcall TMainForm::N141Click(TObject *Sender)
  447. {
  448.    N141->Checked=true;
  449.    ZoomIn1->Checked=false;
  450.    ZoomOut1->Checked=true;
  451.    ((TMDIChild *)ActiveMDIChild)->ZoomMode=PAINTSIZEMODE_ZOOM;
  452.    ((TMDIChild *)ActiveMDIChild)->ZoomImage(4,false);
  453.    ((TMDIChild *)ActiveMDIChild)->ZoomSize=6;
  454. }
  455. //---------------------------------------------------------------------------
  456. void __fastcall TMainForm::Flip1Click(TObject *Sender)
  457. {
  458.    ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Flipping Image");
  459.    if(((TMDIChild *)ActiveMDIChild)->Lead1->HasRgn)
  460.      ((TMDIChild *)ActiveMDIChild)->ProcessRegion("Flip");
  461.    else
  462.      ((TMDIChild *)ActiveMDIChild)->Lead1->Flip();
  463.    ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  464. }
  465. //---------------------------------------------------------------------------
  466. void __fastcall TMainForm::Reverse1Click(TObject *Sender)
  467. {
  468.    ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Reversing Image");
  469.    if(((TMDIChild *)ActiveMDIChild)->Lead1->HasRgn)
  470.      ((TMDIChild *)ActiveMDIChild)->ProcessRegion("Reverse");
  471.    else
  472.      ((TMDIChild *)ActiveMDIChild)->Lead1->Reverse();
  473.    ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  474. }
  475. //---------------------------------------------------------------------------
  476. void __fastcall TMainForm::Rotate1Click(TObject *Sender)
  477. {
  478.    String instring;
  479.    int degrees;
  480.  
  481.    if(InputQuery("Rotate Image", "Enter Degrees (-360...360)", instring))
  482.     {
  483.       degrees = instring.ToInt();
  484.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Rotating Image");
  485.       if(((TMDIChild *)ActiveMDIChild)->Lead1->HasRgn)
  486.        {
  487.          ((TMDIChild *)ActiveMDIChild)->rValue = degrees;
  488.          ((TMDIChild *)ActiveMDIChild)->ProcessRegion("Rotate");
  489.        }
  490.       else
  491.        ((TMDIChild *)ActiveMDIChild)->Lead1->Rotate(degrees*100,true,clBlack);
  492.       ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  493.     }
  494. }
  495. //---------------------------------------------------------------------------
  496. void __fastcall TMainForm::Shear1Click(TObject *Sender)
  497. {
  498.    String instring;
  499.    int angle;
  500.  
  501.    if(InputQuery("Shear", "Clockwise angle in degrees (-45...45)", instring))
  502.     {
  503.       angle = instring.ToInt();
  504.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Shearing Image");
  505.       if(((TMDIChild *)ActiveMDIChild)->Lead1->HasRgn)
  506.        {
  507.          ((TMDIChild *)ActiveMDIChild)->rValue = angle;
  508.          ((TMDIChild *)ActiveMDIChild)->ProcessRegion("Shear");
  509.        }
  510.       else
  511.        ((TMDIChild *)ActiveMDIChild)->Lead1->Shear(angle*100,true,clBlack);
  512.       ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  513.     }
  514. }
  515. //---------------------------------------------------------------------------
  516. void __fastcall TMainForm::Resize1Click(TObject *Sender)
  517. {
  518.   String instring(((TMDIChild *)ActiveMDIChild)->Lead1->BitmapWidth);
  519.   int w,h;
  520.  
  521.   //instring;
  522.   if(InputQuery("New Image Width", "Enter Width", instring))
  523.    {
  524.       w = instring.ToInt();
  525.       if(w > 0)
  526.        {
  527.          String in(((TMDIChild *)ActiveMDIChild)->Lead1->BitmapHeight);
  528.          if(InputQuery("New Image Height", "Enter Height", in))
  529.           {
  530.              h=in.ToInt();
  531.              if(h > 0)
  532.               {
  533.                  ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Resizing Image");
  534.                  if(((TMDIChild *)ActiveMDIChild)->Lead1->HasRgn)
  535.                   {
  536.                     ((TMDIChild *)ActiveMDIChild)->rValue = w;
  537.                     ((TMDIChild *)ActiveMDIChild)->sValue = h;
  538.                     ((TMDIChild *)ActiveMDIChild)->ProcessRegion("Resize");
  539.                   }
  540.                  else
  541.                   ((TMDIChild *)ActiveMDIChild)->Lead1->Size(w,h,RESIZE_NORMAL);
  542.                  ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  543.               }
  544.           }
  545.        }
  546.    }
  547. }
  548. //---------------------------------------------------------------------------
  549. void __fastcall TMainForm::Resample1Click(TObject *Sender)
  550. {
  551.   String instring(((TMDIChild *)ActiveMDIChild)->Lead1->BitmapWidth);
  552.   int w,h;
  553.  
  554.   if(InputQuery("New Image Width", "Enter Width", instring))
  555.    {
  556.       w = instring.ToInt();
  557.       if(w > 0)
  558.        {
  559.          String in(((TMDIChild *)ActiveMDIChild)->Lead1->BitmapHeight);
  560.          if(InputQuery("New Image Height", "Enter Height", in))
  561.           {
  562.              h=in.ToInt();
  563.              if(h > 0)
  564.               {
  565.                  ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Resampling Image");
  566.                  if(((TMDIChild *)ActiveMDIChild)->Lead1->HasRgn)
  567.                   {
  568.                     ((TMDIChild *)ActiveMDIChild)->rValue = w;
  569.                     ((TMDIChild *)ActiveMDIChild)->sValue = h;
  570.                     ((TMDIChild *)ActiveMDIChild)->ProcessRegion("Resample");
  571.                   }
  572.                  else
  573.                   ((TMDIChild *)ActiveMDIChild)->Lead1->Size(w,h,RESIZE_RESAMPLE);
  574.                  ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  575.               }
  576.           }
  577.        }
  578.    }
  579. }
  580. //---------------------------------------------------------------------------
  581. void __fastcall TMainForm::Posterize1Click(TObject *Sender)
  582. {
  583.    String instring;
  584.    int nVal;
  585.  
  586.    instring = "2";
  587.    if(InputQuery("Posterize", "Levels per color (2..64)", instring))
  588.     {
  589.       nVal = instring.ToInt();
  590.       if(nVal<2 || nVal>64)
  591.         Application->MessageBox("Invalid Value","Error",MB_ICONINFORMATION);
  592.       else
  593.        {
  594.          ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Posterizing Image");
  595.          ((TMDIChild *)ActiveMDIChild)->Lead1->Posterize(nVal);
  596.          ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  597.        }
  598.     }
  599. }
  600. //---------------------------------------------------------------------------
  601. void __fastcall TMainForm::Mosaic1Click(TObject *Sender)
  602. {
  603.    String instring;
  604.    int nVal;
  605.  
  606.    instring = "2";
  607.    if(InputQuery("Mosaic", "Tile size (2..64)", instring))
  608.     {
  609.       nVal = instring.ToInt();
  610.       if(nVal<2 || nVal>64)
  611.         Application->MessageBox("Invalid Value","Error",MB_ICONINFORMATION);
  612.       else
  613.        {
  614.          ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Mosaic");
  615.          ((TMDIChild *)ActiveMDIChild)->Lead1->Mosaic(nVal);
  616.          ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  617.        }
  618.     }
  619. }
  620. //---------------------------------------------------------------------------
  621. void __fastcall TMainForm::Average1Click(TObject *Sender)
  622. {
  623.   String instring;
  624.    int nVal;
  625.  
  626.    instring = "3";
  627.    if(InputQuery("Average Filter", "Sample Size (3..11)", instring))
  628.     {
  629.       nVal = instring.ToInt();
  630.       if(nVal<3 || nVal>11)
  631.         Application->MessageBox("Invalid Value","Error",MB_ICONINFORMATION);
  632.       else
  633.        {
  634.          ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Averaging Image");
  635.          ((TMDIChild *)ActiveMDIChild)->Lead1->Average(nVal);
  636.          ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  637.        }
  638.     }
  639. }
  640. //---------------------------------------------------------------------------
  641. void __fastcall TMainForm::Median1Click(TObject *Sender)
  642. {
  643.    String instring;
  644.    int nVal;
  645.  
  646.    instring = "3";
  647.    if(InputQuery("Median Filter", "Sample Size (3..11)", instring))
  648.     {
  649.       nVal = instring.ToInt();
  650.       if(nVal<3 || nVal>11)
  651.         Application->MessageBox("Invalid Value","Error",MB_ICONINFORMATION);
  652.       else
  653.        {
  654.          ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Median Filter");
  655.          ((TMDIChild *)ActiveMDIChild)->Lead1->Median(nVal);
  656.          ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  657.        }
  658.     }
  659. }
  660. //---------------------------------------------------------------------------
  661. void __fastcall TMainForm::Sharpen1Click(TObject *Sender)
  662. {
  663.    String instring;
  664.    int nVal;
  665.  
  666.    instring = "0";
  667.    if(InputQuery("Sharpen", "Percentage (-100..100)", instring))
  668.     {
  669.       nVal = instring.ToInt();
  670.       if(nVal<-100 || nVal>100)
  671.         Application->MessageBox("Invalid Value","Error",MB_ICONINFORMATION);
  672.       else
  673.        {
  674.          ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Sharpening Image");
  675.          ((TMDIChild *)ActiveMDIChild)->Lead1->Sharpen(nVal*10);
  676.          ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  677.        }
  678.     }
  679. }
  680. //---------------------------------------------------------------------------
  681. void __fastcall TMainForm::AddNoise1Click(TObject *Sender)
  682. {
  683.    String instring;
  684.    int nVal,nChannel;
  685.  
  686.    instring = "0";
  687.    if(InputQuery("Add Noise", "Level (0..100)", instring))
  688.     {
  689.       nVal = instring.ToInt();
  690.       if(nVal<0 || nVal>100)
  691.         Application->MessageBox("Invalid Value","Error",MB_ICONINFORMATION);
  692.       else
  693.        {
  694.           nChannel = CHANNEL_MASTER;
  695.           if(!GetListIndex("Add noise", "Channel", aChannelList,&nChannel))
  696.             return;
  697.          ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Adding Noise");
  698.          ((TMDIChild *)ActiveMDIChild)->Lead1->AddNoise(nVal*10,nChannel);
  699.          ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  700.        }
  701.     }
  702. }
  703. //---------------------------------------------------------------------------
  704. void __fastcall TMainForm::Emboss1Click(TObject *Sender)
  705. {
  706.    int nFlt;
  707.  
  708.    if(GetListIndex("Emboss Spatial Filter","Direction",aGradientList,&nFlt))
  709.     {
  710.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Embossing Image");
  711.       ((TMDIChild *)ActiveMDIChild)->Lead1->SpatialFilter(nFlt+FLT_EMBOSS_N);
  712.       ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  713.     }
  714. }
  715. //---------------------------------------------------------------------------
  716. void __fastcall TMainForm::Despeckle1Click(TObject *Sender)
  717. {
  718.    ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Despeckling Image");
  719.    ((TMDIChild *)ActiveMDIChild)->Lead1->Despeckle();
  720.    ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  721. }
  722. //---------------------------------------------------------------------------
  723. void __fastcall TMainForm::Halftone1Click(TObject *Sender)
  724. {
  725.    ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Halftoning Image");
  726.    ((TMDIChild *)ActiveMDIChild)->Lead1->Halftone(HALFTONE_VIEW,0);
  727.    ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  728. }
  729. //---------------------------------------------------------------------------
  730. void __fastcall TMainForm::Grayscale1Click(TObject *Sender)
  731. {
  732.    ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Graying Image");
  733.    ((TMDIChild *)ActiveMDIChild)->Lead1->Grayscale(8);
  734.    ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  735. }
  736. //---------------------------------------------------------------------------
  737. void __fastcall TMainForm::Invert1Click(TObject *Sender)
  738. {
  739.    ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Inverting Image");
  740.    ((TMDIChild *)ActiveMDIChild)->Lead1->Invert();
  741.    ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  742. }
  743. //---------------------------------------------------------------------------
  744. void __fastcall TMainForm::Brightness1Click(TObject *Sender)
  745. {
  746.    String instring;
  747.    int nVal;
  748.  
  749.    instring = "0";
  750.    if(InputQuery("Change brightness", "Percentage (-100..100)", instring))
  751.     {
  752.       nVal = instring.ToInt();
  753.       if(nVal<-100 || nVal>100)
  754.         Application->MessageBox("Invalid Value","Error",MB_ICONINFORMATION);
  755.       else
  756.        {
  757.          ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Changing Brightness");
  758.          ((TMDIChild *)ActiveMDIChild)->Lead1->Intensity(nVal*10);
  759.          ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  760.        }
  761.     }
  762. }
  763. //---------------------------------------------------------------------------
  764. void __fastcall TMainForm::Contrast1Click(TObject *Sender)
  765. {
  766.    String instring;
  767.    int nVal;
  768.  
  769.    instring = "0";
  770.    if(InputQuery("Change Contrast", "Percentage (-100..100)", instring))
  771.     {
  772.       nVal = instring.ToInt();
  773.       if(nVal<-100 || nVal>100)
  774.         Application->MessageBox("Invalid Value","Error",MB_ICONINFORMATION);
  775.       else
  776.        {
  777.          ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Changing Contrast");
  778.          ((TMDIChild *)ActiveMDIChild)->Lead1->Contrast(nVal*10);
  779.          ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  780.        }
  781.     }
  782. }
  783. //---------------------------------------------------------------------------
  784. void __fastcall TMainForm::Hue1Click(TObject *Sender)
  785. {
  786.    String instring;
  787.    int nVal;
  788.  
  789.    instring = "0";
  790.    if(InputQuery("Change Hue", "Angle in degrees (0..360)", instring))
  791.     {
  792.       nVal = instring.ToInt();
  793.       if(nVal<0 || nVal>360)
  794.         Application->MessageBox("Invalid Value","Error",MB_ICONINFORMATION);
  795.       else
  796.        {
  797.          ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Changing Hue");
  798.          ((TMDIChild *)ActiveMDIChild)->Lead1->Contrast(nVal);
  799.          ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  800.        }
  801.     }
  802. }
  803. //---------------------------------------------------------------------------
  804. void __fastcall TMainForm::HistogramEqualize1Click(TObject *Sender)
  805. {
  806.    ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Histogram Equalize");
  807.    ((TMDIChild *)ActiveMDIChild)->Lead1->HistoEqualize();
  808.    ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  809. }
  810. //---------------------------------------------------------------------------
  811. void __fastcall TMainForm::StretchIntensity1Click(TObject *Sender)
  812. {
  813.    ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Stretch Intensity");
  814.    ((TMDIChild *)ActiveMDIChild)->Lead1->StretchIntensity();
  815.    ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  816. }
  817. //---------------------------------------------------------------------------
  818. void __fastcall TMainForm::GammaCorrect1Click(TObject *Sender)
  819. {
  820.    String instring;
  821.    int nVal;
  822.  
  823.    instring = "50";
  824.    if(InputQuery("Gamma correct", "Value (0..500)", instring))
  825.     {
  826.       nVal = instring.ToInt();
  827.       if(nVal<0 || nVal>500)
  828.         Application->MessageBox("Invalid Value","Error",MB_ICONINFORMATION);
  829.       else
  830.        {
  831.          ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Gamma Correcting");
  832.          ((TMDIChild *)ActiveMDIChild)->Lead1->GammaCorrect(nVal);
  833.          ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  834.        }
  835.     }
  836. }
  837. //---------------------------------------------------------------------------
  838. void __fastcall TMainForm::IntensityDetect1Click(TObject *Sender)
  839. {
  840.   String instring;
  841.   int l,h;
  842.  
  843.   instring="0";
  844.   if(InputQuery("Intensity Detect", "min (0..255)", instring))
  845.    {
  846.       l = instring.ToInt();
  847.       if(l>= 0 && l<=255)
  848.        {
  849.          instring="0";
  850.          if(InputQuery("Intensity Detect", "max (0..255)", instring))
  851.           {
  852.              h=instring.ToInt();
  853.              if(h >= 0 && h<=255)
  854.               {
  855.                  ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Intensity Detect");
  856.                  ((TMDIChild *)ActiveMDIChild)->Lead1->IntensityDetect(l,h);
  857.                  ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  858.               }
  859.           }
  860.        }
  861.    }
  862. }
  863. //---------------------------------------------------------------------------
  864.  
  865. bool TMainForm::GetListIndex(String Title,String LabelTitle,String strings[],int *index)
  866. {
  867.   int i;
  868.  
  869.   ListDlg->Caption=Title;
  870.   ListDlg->GroupBox1->Caption=LabelTitle;
  871.   ListDlg->ListBox1->Clear();
  872.   for(i=0;i<MAX_STRING_LIST;i++)
  873.     if(strings[i]!="")
  874.       ListDlg->ListBox1->Items->Add(strings[i]);
  875.     else
  876.       break;
  877.   ListDlg->ListBox1->ItemIndex=0;
  878.   ListDlg->ShowModal();
  879.   *index=ListDlg->ListBox1->ItemIndex;
  880.   return(ListDlg->ModalResult==mrOk);
  881. }
  882.  
  883. void __fastcall TMainForm::Gradient1Click(TObject *Sender)
  884. {
  885.    int nFlt;
  886.  
  887.    if(GetListIndex("Gradient Spatial Filter","Direction",aGradientList,&nFlt))
  888.     {
  889.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Applying Gradient Filter");
  890.       ((TMDIChild *)ActiveMDIChild)->Lead1->SpatialFilter(nFlt+FLT_GRADIENT_N);
  891.       ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  892.     }
  893. }
  894.  
  895. //---------------------------------------------------------------------------
  896. void __fastcall TMainForm::Laplacian1Click(TObject *Sender)
  897. {
  898.    int nFlt;
  899.  
  900.    if(GetListIndex("Laplacian Spatial Filter","Type",aLaplacianList,&nFlt))
  901.     {
  902.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Applying Laplacian Filter");
  903.       ((TMDIChild *)ActiveMDIChild)->Lead1->SpatialFilter(nFlt+FLT_LAPLACE_1);
  904.       ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  905.     }
  906. }
  907.  
  908. bool TMainForm::GetPaintEffect(int *index)
  909. {
  910.   int i;
  911.  
  912.   ListDlg->Caption="Paint Effect";
  913.   ListDlg->GroupBox1->Caption="Select Effect";
  914.   ListDlg->ListBox1->Clear();
  915.   for(i=0;i<sizeof(aEffectList)/sizeof(aEffectList[0]);i++)
  916.     ListDlg->ListBox1->Items->Add(aEffectList[i]);
  917.   ListDlg->ListBox1->ItemIndex=0;
  918.   ListDlg->ShowModal();
  919.   *index=ListDlg->ListBox1->ItemIndex+2000;
  920.   return(ListDlg->ModalResult==mrOk);
  921. }
  922.  
  923. //---------------------------------------------------------------------------
  924. void __fastcall TMainForm::Sobel1Click(TObject *Sender)
  925. {
  926.    int nFlt;
  927.  
  928.    if(GetListIndex("Sobel Spatial Filter","Direction",aHorzVertList,&nFlt))
  929.     {
  930.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Applying Spatial Filter");
  931.       ((TMDIChild *)ActiveMDIChild)->Lead1->SpatialFilter(nFlt+FLT_SOBEL_HORZ);
  932.       ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  933.     }
  934. }
  935. //---------------------------------------------------------------------------
  936. void __fastcall TMainForm::Prewitt1Click(TObject *Sender)
  937. {
  938.    int nFlt;
  939.  
  940.    if(GetListIndex("Prewitt Spatial Filter","Direction",aHorzVertList,&nFlt))
  941.     {
  942.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Applying Prewitt Filter");
  943.       ((TMDIChild *)ActiveMDIChild)->Lead1->SpatialFilter(nFlt+FLT_PREWITT_HORZ);
  944.       ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  945.     }
  946. }
  947. //---------------------------------------------------------------------------
  948. void __fastcall TMainForm::ShiftandDifference1Click(TObject *Sender)
  949. {
  950.    int nFlt;
  951.  
  952.    if(GetListIndex("Shift & Difference Spatial Filter","Direction",aShiftDiffList,&nFlt))
  953.     {
  954.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Applying Shift & Difference");
  955.       ((TMDIChild *)ActiveMDIChild)->Lead1->SpatialFilter(nFlt+FLT_SHIFTDIFF_DIAG);
  956.       ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  957.     }
  958. }
  959. //---------------------------------------------------------------------------
  960. void __fastcall TMainForm::LineSegment1Click(TObject *Sender)
  961. {
  962.    int nFlt;
  963.  
  964.    if(GetListIndex("Line Segment Spatial Filter","Filter Type",aLineSegmentList,&nFlt))
  965.     {
  966.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Applying Line Segment Filter");
  967.       ((TMDIChild *)ActiveMDIChild)->Lead1->SpatialFilter(nFlt+FLT_LINESEG_HORZ);
  968.       ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  969.     }
  970. }
  971. //---------------------------------------------------------------------------
  972. void __fastcall TMainForm::Erosion1Click(TObject *Sender)
  973. {
  974.    int nFlt;
  975.  
  976.    if(GetListIndex("Erosion Binary Filter","Direction",aBinaryFilterList,&nFlt))
  977.     {
  978.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Applying Erosion Filter");
  979.       ((TMDIChild *)ActiveMDIChild)->Lead1->BinaryFilter(nFlt+BFLT_EROSION_OMNI);
  980.       ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  981.     }
  982. }
  983. //---------------------------------------------------------------------------
  984. void __fastcall TMainForm::Dilation1Click(TObject *Sender)
  985. {
  986.    int nFlt;
  987.  
  988.    if(GetListIndex("Dialation Binary Filter","Direction",aBinaryFilterList,&nFlt))
  989.     {
  990.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Applying Dialation Filter");
  991.       ((TMDIChild *)ActiveMDIChild)->Lead1->BinaryFilter(nFlt+BFLT_DILATION_OMNI);
  992.       ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  993.     }
  994. }
  995. //---------------------------------------------------------------------------
  996. void __fastcall TMainForm::Auto1Click(TObject *Sender)
  997. {
  998.   Auto1->Checked=true;
  999.   Fixed1->Checked=false;
  1000.   HiddenLead->PaintPalette=PAINTPALETTE_AUTO;
  1001.   for(int i=0;i<MDIChildCount-1;i++)
  1002.     ((TMDIChild *)MDIChildren[i])->Lead1->PaintPalette=HiddenLead->PaintPalette;
  1003. }
  1004. //---------------------------------------------------------------------------
  1005. void __fastcall TMainForm::Fixed1Click(TObject *Sender)
  1006. {
  1007.    Fixed1->Checked=true;
  1008.    Auto1->Checked=false;
  1009.    HiddenLead->PaintPalette=PAINTPALETTE_FIXED;
  1010.    for(int i=0;i<MDIChildCount-1;i++)
  1011.     ((TMDIChild *)MDIChildren[i])->Lead1->PaintPalette=HiddenLead->PaintPalette;
  1012. }
  1013. //---------------------------------------------------------------------------
  1014. void __fastcall TMainForm::Ordered1Click(TObject *Sender)
  1015. {
  1016.    Ordered1->Checked=true;
  1017.    ErrorDiffusion1->Checked=false;
  1018.    HiddenLead->PaintDither=PAINTDITHER_ORDERED;
  1019.    for(int i=0;i<MDIChildCount-1;i++)
  1020.     ((TMDIChild *)MDIChildren[i])->Lead1->PaintDither=HiddenLead->PaintDither;
  1021. }
  1022. //---------------------------------------------------------------------------
  1023. void __fastcall TMainForm::ErrorDiffusion1Click(TObject *Sender)
  1024. {
  1025.    ErrorDiffusion1->Checked=true;
  1026.    Ordered1->Checked=false;
  1027.    HiddenLead->PaintDither=PAINTDITHER_DIFFUSION;
  1028.    for(int i=0;i<MDIChildCount-1;i++)
  1029.     ((TMDIChild *)MDIChildren[i])->Lead1->PaintDither=HiddenLead->PaintDither;
  1030. }
  1031. //---------------------------------------------------------------------------
  1032. void __fastcall TMainForm::Normal2Click(TObject *Sender)
  1033. {
  1034.    Normal2->Checked=true;
  1035.    FavorBlack1->Checked=false;
  1036.    ScaleToGray1->Checked=false;
  1037.    HiddenLead->BitonalScaling=BITONALSCALING_NORMAL;
  1038.    for(int i=0;i<MDIChildCount-1;i++)
  1039.     ((TMDIChild *)MDIChildren[i])->Lead1->BitonalScaling=HiddenLead->BitonalScaling;
  1040. }
  1041. //---------------------------------------------------------------------------
  1042. void __fastcall TMainForm::FavorBlack1Click(TObject *Sender)
  1043. {
  1044.    FavorBlack1->Checked=true;
  1045.    Normal2->Checked=false;
  1046.    ScaleToGray1->Checked=false;
  1047.    HiddenLead->BitonalScaling=BITONALSCALING_FAVORBLACK;
  1048.    for(int i=0;i<MDIChildCount-1;i++)
  1049.     ((TMDIChild *)MDIChildren[i])->Lead1->BitonalScaling=HiddenLead->BitonalScaling;
  1050. }
  1051. //---------------------------------------------------------------------------
  1052. void __fastcall TMainForm::ScaleToGray1Click(TObject *Sender)
  1053. {
  1054.    ScaleToGray1->Checked=true;
  1055.    Normal2->Checked=false;
  1056.    FavorBlack1->Checked=false;
  1057.    HiddenLead->BitonalScaling=BITONALSCALING_SCALETOGRAY;
  1058.    for(int i=0;i<MDIChildCount-1;i++)
  1059.     ((TMDIChild *)MDIChildren[i])->Lead1->BitonalScaling=HiddenLead->BitonalScaling;
  1060. }
  1061. //---------------------------------------------------------------------------
  1062. void __fastcall TMainForm::CaptureScreen1Click(TObject *Sender)
  1063. {
  1064.    HDC screenDC;
  1065.    int nRet;
  1066.    TMDIChild *Child;
  1067.  
  1068.    Visible=false;
  1069. #ifdef WIN32
  1070.    Sleep(1000);
  1071. #else
  1072.    Yield();
  1073. #endif
  1074.    screenDC = GetDC(0);
  1075.    nRet = HiddenLead->Capture((int)screenDC,0,0,GetDeviceCaps(screenDC,HORZRES),
  1076.                              GetDeviceCaps(screenDC,VERTRES));
  1077.    ReleaseDC(0,screenDC);
  1078.    Visible=true;
  1079.    if(nRet==0)
  1080.     {
  1081.        Child = new TMDIChild(Application);
  1082.        Child->Caption="Screen Capture";
  1083.        Child->Lead1->Bitmap=HiddenLead->Bitmap;
  1084.        Child->Lead1->AutoAnimate=true;
  1085.        Child->Lead1->AutoRepaint=false;
  1086.        Child->Lead1->PaintPalette=HiddenLead->PaintPalette;
  1087.        Child->Lead1->PaintDither=HiddenLead->PaintDither;
  1088.        Child->Lead1->BitonalScaling=HiddenLead->BitonalScaling;
  1089.        Child->Lead1->EnableProgressEvent=HiddenLead->EnableProgressEvent;
  1090.        Child->Lead1->AutoRepaint=true;
  1091.        Child->ZoomMode=PAINTSIZEMODE_NORMAL;
  1092.        Child->ZoomSize=100;
  1093.        Child->RegionTool=RGNMARK_NONE;
  1094.        HiddenLead->Bitmap=0;
  1095.     }
  1096.    else
  1097.     {
  1098.        Application->MessageBox("Error capturing the screen","ERROR",MB_ICONINFORMATION);
  1099.     }
  1100. }
  1101. //---------------------------------------------------------------------------
  1102. void __fastcall TMainForm::ColorResolution1Click(TObject *Sender)
  1103. {
  1104.    int nRet,nBits;
  1105.    long uDither,uPalette,uFlags;
  1106.  
  1107.    ColorResDlg->ShowModal();
  1108.    if(ColorResDlg->ModalResult==mrOk)
  1109.     {
  1110.       switch(ColorResDlg->BPP->ItemIndex)
  1111.        {
  1112.          case 0: nBits=1; break;
  1113.          case 1: nBits=2; break;
  1114.          case 2: nBits=3; break;
  1115.          case 3: nBits=4; break;
  1116.          case 4: nBits=5; break;
  1117.          case 5: nBits=6; break;
  1118.          case 6: nBits=7; break;
  1119.          case 7: nBits=8; break;
  1120.          case 8: nBits=16; break;
  1121.          case 9: nBits=24; break;
  1122.          case 10: nBits=32; break;
  1123.        }
  1124.       switch(ColorResDlg->DitherMethod->ItemIndex)
  1125.        {
  1126.          case 0: uDither=CRD_NODITHERING; break;
  1127.          case 1: uDither=CRD_FLOYDSTEINDITHERING; break;
  1128.          case 2: uDither=CRD_BURKESDITHERING; break;
  1129.          case 3: uDither=CRD_STUCKIDITHERING; break;
  1130.          case 4: uDither=CRD_SIERRADITHERING; break;
  1131.          case 5: uDither=CRD_STEVENSONARCEDITHERING; break;
  1132.          case 6: uDither=CRD_JARVISDITHERING; break;
  1133.        }
  1134.       if(ColorResDlg->PaletteOption->ItemIndex==0)
  1135.         uPalette=CRP_OPTIMIZEDPALETTE;
  1136.       else
  1137.         uPalette=CRP_FIXEDPALETTE;
  1138.       if(nBits>8)
  1139.        {
  1140.          if(ColorResDlg->ColorOrder->ItemIndex==0)
  1141.            uPalette=CRP_BYTEORDERBGR;
  1142.          else
  1143.            uPalette=CRP_BYTEORDERRGB;
  1144.        }
  1145.       ((TMDIChild *)ActiveMDIChild)->InitStatusProcess("Doing ColorRes");
  1146.       try
  1147.        {
  1148.          ((TMDIChild *)ActiveMDIChild)->Lead1->ColorRes(nBits,uPalette,uDither,0);
  1149.        }
  1150.      catch(...)
  1151.        {
  1152.          ((TMDIChild *)ActiveMDIChild)->ResetStatusProcess();
  1153.        }
  1154.     }
  1155. }
  1156. //---------------------------------------------------------------------------
  1157. void __fastcall TMainForm::ImageInfo1Click(TObject *Sender)
  1158. {
  1159.    int nRet;
  1160.    char s[10];
  1161.  
  1162.    OpenDialog->Filter=szLoadFilter;
  1163.    if(OpenDialog->Execute())
  1164.     {
  1165.        nRet=HiddenLead->GetFileInfo(OpenDialog->FileName,0);
  1166.        if(nRet==0)
  1167.         {
  1168.            InfoBox->FName->Caption=OpenDialog->FileName;
  1169.            itoa(HiddenLead->InfoFormat,s,10);
  1170.            InfoBox->FFormat->Caption=s;
  1171.            itoa(HiddenLead->InfoWidth,s,10);
  1172.            InfoBox->FWidth->Caption=s;
  1173.            itoa(HiddenLead->InfoHeight,s,10);
  1174.            InfoBox->FHeight->Caption=s;
  1175.            itoa(HiddenLead->InfoBits,s,10);
  1176.            InfoBox->FBits->Caption=s;
  1177.            itoa(HiddenLead->InfoSizeDisk,s,10);
  1178.            InfoBox->FDisk->Caption=s;
  1179.            itoa(HiddenLead->InfoSizeMem,s,10);
  1180.            InfoBox->FMem->Caption=s;
  1181.            InfoBox->FComp->Caption=HiddenLead->InfoCompress;
  1182.            InfoBox->ShowModal();
  1183.         }
  1184.        else
  1185.         {
  1186.            Application->MessageBox("Error Getting Info","Error",MB_ICONEXCLAMATION);
  1187.         }
  1188.     }
  1189. }
  1190. //---------------------------------------------------------------------------
  1191.  
  1192.  
  1193. void __fastcall TMainForm::HelpAboutItemClick(TObject *Sender)
  1194. {
  1195.   AboutBox->ShowModal();    
  1196. }
  1197. //---------------------------------------------------------------------------
  1198. void __fastcall TMainForm::TwainSelect1Click(TObject *Sender)
  1199. {
  1200.    HiddenLead->TwainSelect((int)Handle);
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. void __fastcall TMainForm::TwainAcquire1Click(TObject *Sender)
  1204. {
  1205.    int nRet;
  1206.    TMDIChild *Child;
  1207.  
  1208.    nRet=HiddenLead->TwainAcquire((int)Handle);
  1209.    if(nRet==0)
  1210.     {
  1211.        Child = new TMDIChild(Application);
  1212.        Child->Caption = "Twain image";
  1213.        Child->Lead1->AutoAnimate=true;
  1214.        Child->Lead1->AutoRepaint=false;
  1215.        Child->Lead1->EnableProgressEvent=HiddenLead->EnableProgressEvent;
  1216.        Child->Lead1->PaintPalette=HiddenLead->PaintPalette;
  1217.        Child->Lead1->PaintDither=HiddenLead->PaintDither;
  1218.        Child->Lead1->BitonalScaling=HiddenLead->BitonalScaling;
  1219.        Child->Lead1->AutoRepaint=true;
  1220.        Child->ZoomMode=PAINTSIZEMODE_NORMAL;
  1221.        Child->ZoomSize=100;
  1222.        Child->RegionTool=RGNMARK_NONE;
  1223.        Child->Lead1->Bitmap=HiddenLead->Bitmap;
  1224.        HiddenLead->Bitmap=0;
  1225.     }
  1226. }
  1227. //---------------------------------------------------------------------------
  1228. void __fastcall TMainForm::Effects1Click(TObject *Sender)
  1229. {
  1230.   int nVal;
  1231.  
  1232.   if(Effects1->Checked)
  1233.    {
  1234.      Effects1->Checked = false;
  1235.      ((TMDIChild *)ActiveMDIChild)->Lead1->PaintEffect = EFX_EFFECT_NONE;
  1236.    }
  1237.   else
  1238.    {
  1239.      if(GetPaintEffect(&nVal))
  1240.       {
  1241.         Effects1->Checked = true;
  1242.         ((TMDIChild *)ActiveMDIChild)->Lead1->PaintEffect = nVal;
  1243.       }
  1244.    }
  1245. }
  1246. //---------------------------------------------------------------------------
  1247.