home *** CD-ROM | disk | FTP | other *** search
- {
- Written by Jan Dekkers and Kevin Adams (c) 1995, 1996. If you are a non
- registered client, you may use or alter this demo only for evaluation
- purposes.
-
- Copyright by SkyLine Tools. All rights reserved.
-
- Part of Imagelib VCL/DLL Library.
- }
-
- unit Bimage;
-
- {Includes settings to compile in either 16 or 32 bit}
- {$I DEFILIB.INC}
-
- interface
-
- uses
- {$IFDEF DEL32}
- Windows,
- {$ELSE}
- WinTypes,
- WinProcs,
- {$ENDIF}
- DLL95V1, {ImageLib Dll interface and misc. functions}
- SysUtils,
- Messages,
- Classes,
- Graphics,
- Controls,
- Forms,
- Dialogs,
- StdCtrls,
- FileCtrl,
- Spin,
- Buttons,
- UFullscr, {Full screen display unit}
- Menus,
- UAbout,
- Tmultip, {PMultiImage VCL component}
- Gauges;
-
-
- type
- TConvertForm1 = class(TForm)
- DriveComboBox1: TDriveComboBox;
- DirectoryListBox1: TDirectoryListBox;
- FileListBox1: TFileListBox;
- Convert: TBitBtn;
- QualitySpin: TSpinEdit;
- Smoothspin: TSpinEdit;
- QualityLabel: TLabel;
- SmoothLabel: TLabel;
- GroupBox1: TGroupBox;
- res4: TRadioButton;
- res24: TRadioButton;
- res8: TRadioButton;
- GroupBox2: TGroupBox;
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- E1: TMenuItem;
- A1: TMenuItem;
- ComboBox1: TComboBox;
- Sstretch: TCheckBox;
- GroupBox3: TGroupBox;
- CTOJPEG: TRadioButton;
- CTOBMP: TRadioButton;
- Label1: TLabel;
- FileListBox2: TFileListBox;
- DirectoryListBox2: TDirectoryListBox;
- DriveComboBox2: TDriveComboBox;
- Label2: TLabel;
- CheckBox1: TCheckBox;
- CTOGIF: TRadioButton;
- CTOPCX: TRadioButton;
- CTOPNG: TRadioButton;
- MultiImage1: TPMultiImage;
- GroupBox4: TGroupBox;
- Saveres4: TRadioButton;
- Saveres24: TRadioButton;
- Saveres8: TRadioButton;
- CheckBox2: TCheckBox;
- SaveResAuto: TRadioButton;
- SaveRes4System: TRadioButton;
- resAuto: TRadioButton;
- res4System: TRadioButton;
- SaveResJpegGray: TRadioButton;
- CTOTIF: TRadioButton;
- TiffCombo: TComboBox;
- Label3: TLabel;
- Res1: TRadioButton;
- Gauge1: TGauge;
- procedure DriveComboBox1Change(Sender: TObject);
- procedure DirectoryListBox1Change(Sender: TObject);
- procedure FileListBox1Change(Sender: TObject);
- procedure SstretchOnOff(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure ResClick(Sender: TObject);
- procedure DitherClick(Sender: TObject);
- procedure MultiImage1Click(Sender: TObject);
- procedure E1Click(Sender: TObject);
- procedure A1Click(Sender: TObject);
- procedure ComboBox1Change(Sender: TObject);
- procedure ConvertClick(Sender: TObject);
- procedure DirectoryListBox2Change(Sender: TObject);
- procedure DriveComboBox2Change(Sender: TObject);
- procedure FileListBox2Change(Sender: TObject);
- procedure QualitySpinChange(Sender: TObject);
- procedure SmoothspinChange(Sender: TObject);
- procedure CTOJPEGClick(Sender: TObject);
- procedure SaveRes(Sender: TObject);
- procedure CheckBox2Click(Sender: TObject);
- procedure TiffComboChange(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- private
- function NameOnly(PName : string) : string;
- public
- { Public declarations }
- end;
-
- var
- ConvertForm1: TConvertForm1;
-
- implementation
-
- {$R *.DFM}
- {---------------------------------------------------------------------}
- {---------------------------------------------------------------------}
-
- {Changed in version 2.21 from a procedure to a function with cdecl.
- To cancel return a 0 else return a 1}
- Function BImageLibCallBack(i : integer) : integer; cdecl; export;
- {Callback function from the dll, CDECL and EXPORT ARE REQUIRED}
- begin
- if Application.Terminated then begin
- {User wants to terminate the program. Pass a 0 to the dll}
- Result:=0;
- end else begin
- {Be nice to others <g>}
- Application.ProcessMessages;
- {process a Gauge}
- if ConvertForm1 <> Nil then
- ConvertForm1.Gauge1.Progress:=i;
- {tell the dll that everything is OK}
- Result:=1;
- end;
- end;
- {---------------------------------------------------------------------}
-
- {update the drive of DirectoryListBox1 with the drive of DriveComboBox1}
- procedure TConvertForm1.DriveComboBox1Change(Sender: TObject);
- begin
- DirectoryListBox1.Drive := DriveComboBox1.Drive;
- end;
- {---------------------------------------------------------------------}
-
- {update the directory of FileListBox1 with the directory of FileListBox1}
- procedure TConvertForm1.DirectoryListBox1Change(Sender: TObject);
- begin
- FileListBox1.Directory := DirectoryListBox1.Directory;
- end;
- {---------------------------------------------------------------------}
-
- {Display the image of the FileListBox1.filename}
- procedure TConvertForm1.FileListBox1Change(Sender: TObject);
- begin
- {set hourglass cursor}
- screen.cursor:=crHourGlass;
- try
- {display an image using the vcl}
- MultiImage1.imagename:=FileListBox1.filename;
- finally
- {set default cursor}
- screen.cursor:=crDefault;
- end;
- end;
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.FileListBox2Change(Sender: TObject);
- begin
- {set hourglass cursor}
- screen.cursor:=crHourGlass;
- try
- {display an image using the vcl}
- MultiImage1.imagename:=FileListBox2.filename;
- finally
- {set default cursor}
- screen.cursor:=crDefault;
- end;
- end;
- {---------------------------------------------------------------------}
-
- {set strech mode}
- procedure TConvertForm1.SstretchOnOff(Sender: TObject);
- begin
- MultiImage1.stretch:=Sstretch.Checked;
- end;
- {---------------------------------------------------------------------}
-
- {what we do on create}
- procedure TConvertForm1.FormCreate(Sender: TObject);
- begin
- {set the value of the QualitySpin to the value of JPegSaveQuality}
- QualitySpin.value:=MultiImage1.JPegSaveQuality;
-
- {set the value of the Smoothspin to the value of JPegSaveSmooh}
- Smoothspin.value:=MultiImage1.JPegSaveSmooth;
-
- {Define the callback procedure}
- TPMultiImageCallBack:=BImageLibCallBack;
- end;
- {---------------------------------------------------------------------}
-
- {Set the resolution to either 16, 256 or true color in the vcl}
- procedure TConvertForm1.ResClick(Sender: TObject);
- {Set the read resolution to either 16, 256 or true color in the vcl}
- begin
- {set show resolution to 1 bit monochrome black and white}
- if Res1.checked then MultiImage1.ImageReadRes:=lMonoChrome;
-
- {set show resolution to 4 bit 16 color using the system's colors}
- if Res4System.checked then MultiImage1.ImageReadRes:=lColorVGA;
-
- {set show resolution to 4 bit 16 color}
- if res4.checked then MultiImage1.ImageReadRes:=lColor16;
-
- {set show resolution to 8 bit 256 color}
- if res8.checked then MultiImage1.ImageReadRes:=lColor256;
-
- {set show resolution to 24 bit true color}
- if res24.checked then MultiImage1.ImageReadRes:=lColorTrue;
-
- {Let ImageLib determine the best resolution}
- if resAuto.checked then MultiImage1.ImageReadRes:=lAutoMatic;
- end;
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.SaveRes(Sender: TObject);
- {Set the save resolution to either 16, 256 or true color in the vcl}
- begin
- {set Jpeg save resolution to GrayScale (Other formats will neglect
- this parameter and set it to 8 bit}
- if SaveResJpegGray.checked then MultiImage1.ImageWriteRes:=sJpegGray;
-
- {set save resolution to 4 bit 16 color using the system's colors}
- if SaveRes4System.checked then MultiImage1.ImageWriteRes:=sColorVGA;
-
- {set save resolution to 4 bit 16 color}
- if Saveres4.checked then MultiImage1.ImageWriteRes:=sColor16;
-
- {set save resolution to 8 bit 256 color}
- if Saveres8.checked then MultiImage1.ImageWriteRes:=sColor256;
-
- {set save resolution to 24 bit true color}
- if Saveres24.checked then MultiImage1.ImageWriteRes:=sColorTrue;
-
- {Let ImageLib determine the best resolution}
- if SaveResAuto.checked then MultiImage1.ImageWriteRes:=sAutoMatic;
- end;
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.DitherClick(Sender: TObject);
- begin
- {set the Display dither }
- MultiImage1.ImageDither:=CheckBox1.checked;
- end;
- {---------------------------------------------------------------------}
-
- {show fullscreen}
- procedure TConvertForm1.MultiImage1Click(Sender: TObject);
- begin
- {copy image to fullscreen image}
- FullSlide.MultiImage1.Picture.Graphic:=MultiImage1.Picture.Graphic;
- {show the image fulscreen}
- FullSlide.showmodal;
- end;
- {---------------------------------------------------------------------}
-
- {exit the program}
- procedure TConvertForm1.E1Click(Sender: TObject);
- begin
- close;
- end;
- {---------------------------------------------------------------------}
-
- {about box}
- procedure TConvertForm1.A1Click(Sender: TObject);
- begin
- {Copy the image to the image of he about box}
- AboutBox.Image1.Picture.Graphic:=MultiImage1.Picture.Graphic;
- {show the about box}
- AboutBox.showmodal;
- end;
-
-
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.ComboBox1Change(Sender: TObject);
- begin
- FileListBox1.Mask:=ComboBox1.text;
- FileListBox1.Update;
- end;
- {---------------------------------------------------------------------}
-
- {return filename only. no path, no extension}
- function TConvertForm1.NameOnly(PName : string) : string;
- var
- DtP : Byte;
-
- function JName(PName : string) : string;
- var
- I : Word;
- const
- DDSet : set of Char = ['\', ':', #0];
- begin
- I := Succ(Word(Length(PName)));
- repeat
- Dec(I);
- until (PName[I] in DDSet) or (I = 0);
- JName := Copy(PName, Succ(I), 64);
- end;
-
- begin
- PName := JName(PName);
- DtP := Pos('.', PName);
- if DtP > 0 then
- PName := Copy(PName, 1, DtP-1);
- NameOnly := PName;
- end;
- {---------------------------------------------------------------------}
-
- {The actual conversion}
- procedure TConvertForm1.ConvertClick(Sender: TObject);
- var i : integer;
- pTempExt : string[4];
- pExtension : string[4];
- pName : string[13];
- pPath : string[100];
- toTemp : string;
- frTemp : string;
- begin
-
- if CTOJPEG.Checked then
- pTempExt:='.JPG';
- if CTOBMP.Checked then
- pTempExt:='.BMP';
- if CTOGIF.Checked then
- pTempExt:='.GIF';
- if CTOPCX.Checked then
- pTempExt:='.PCX';
- if CTOPNG.Checked then
- pTempExt:='.PNG';
- if CTOTIF.Checked then
- pTempExt:='.TIF';
-
- for I := FileListBox1.Items.Count - 1 downto 0 do begin
-
- if FileListBox1.Selected[i] then begin
-
- pExtension:=UpperCase(ExtractFileExt(FileListBox1.Items.Strings[i]));
- pName:=UpperCase(NameOnly(FileListBox1.Items.Strings[i]));
- pPath:=UpperCase(DirectoryListBox2.Directory);
-
- toTemp:=pPath+'\'+pName+pTempExt;
- frTemp:=UpperCase(DirectoryListBox1.Directory+'\'+FileListBox1.Items.Strings[i]);
- {set hourglass cursor}
- screen.cursor:=crHourGlass;
- try
- if CTOJPEG.Checked then begin
- MultiImage1.imagename:=frTemp;
- MultiImage1.SaveAsJpg(toTemp)
- end else
- if CTOBMP.Checked then begin
- MultiImage1.imagename:=frTemp;
- MultiImage1.SaveAsBMP(toTemp)
- end else
- if CTOTIF.Checked then begin
- MultiImage1.imagename:=frTemp;
- MultiImage1.SaveAsTIF(toTemp)
- end else
- if CTOGIF.Checked then begin
- MultiImage1.imagename:=frTemp;
- MultiImage1.SaveAsGIF(toTemp)
- end else
- if CTOPCX.Checked then begin
- MultiImage1.imagename:=frTemp;
- MultiImage1.SaveAsPCX(toTemp)
- end else
- if CTOPNG.Checked then begin
- MultiImage1.imagename:=frTemp;
- MultiImage1.SaveAsPNG(toTemp)
- end;
- finally
- {set default cursor}
- screen.cursor:=crDefault;
- end;
- end;
- end;
- FileListBox2.UpDate;
- FileListBox1.UpDate;
- end;
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.DirectoryListBox2Change(Sender: TObject);
- begin
- FileListBox2.Directory := DirectoryListBox2.Directory;
- end;
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.DriveComboBox2Change(Sender: TObject);
- begin
- DirectoryListBox2.Drive := DriveComboBox2.Drive;
- end;
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.QualitySpinChange(Sender: TObject);
- begin
- MultiImage1.JpegSaveQuality:=QualitySpin.Value;
- end;
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.SmoothspinChange(Sender: TObject);
- begin
- MultiImage1.JpegSaveSmooth:=Smoothspin.Value;
- end;
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.CTOJPEGClick(Sender: TObject);
- begin
- QualityLabel.Visible:=CTOJPEG.Checked;
- SmoothLabel.Visible:=CTOJPEG.Checked;
- QualitySpin.Visible:=CTOJPEG.Checked;
- Smoothspin.Visible:=CTOJPEG.Checked;
- CheckBox2.Visible:=CTOPNG.Checked;
- TiffCombo.Visible:=CTOTIF.Checked;
- Label3.Visible:=CTOTIF.Checked;
- end;
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.CheckBox2Click(Sender: TObject);
- begin
- MultiImage1.PNGInterLaced:=CheckBox2.Checked;
- end;
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.TiffComboChange(Sender: TObject);
- begin
- {Set the compression method to save tiffs}
- if TiffCombo.Text ='NONE' then
- MultiImage1.TifSaveCompress:=sNONE;
-
- if TiffCombo.Text ='CCITT' then
- MultiImage1.TifSaveCompress:=sCCITT;
-
- if TiffCombo.Text ='LZW' then
- MultiImage1.TifSaveCompress:=sLZW;
-
- if TiffCombo.Text ='PACKBITS' then
- MultiImage1.TifSaveCompress:=sPACKBITS;
- end;
- {---------------------------------------------------------------------}
-
- procedure TConvertForm1.FormDestroy(Sender: TObject);
- begin
- {Unregister the callback procedure}
- TPMultiImageCallBack:=nil;
- ConvertForm1:=Nil;
- end;
-
- end.
-