home *** CD-ROM | disk | FTP | other *** search
- unit Unit1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ExtCtrls, Menus, fif, fifdlls, ComCtrls;
-
- type
- TImgViewForm = class(TForm)
- MainMenu1: TMainMenu;
- OpenDialog1: TOpenDialog;
- Colors1: TMenuItem;
- N8bitcolor1: TMenuItem;
- N8bitgrayscale1: TMenuItem;
- N15bitcolor1: TMenuItem;
- N24bitcolor1: TMenuItem;
- ScrollBox1: TScrollBox;
- Image1: TImage;
- StatusBar1: TStatusBar;
- procedure Exit1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Open1Click(Sender: TObject);
- procedure Colors1Click(Sender: TObject);
- procedure ChangeColorFormat(Sender: TObject);
- procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- protected
- Filename: string;
- Zoom: Integer;
- public
- procedure UpdateCaption;
- procedure FitToWindow;
- procedure Rescale;
- procedure UpdateProgressBar(Sender: TObject; Action: TProgressAction;
- PercentComplete: Longint);
- end;
-
- var
- ImgViewForm: TImgViewForm;
-
- implementation
-
- {$R *.DFM}
-
- procedure TImgViewForm.Exit1Click(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TImgViewForm.FormCreate(Sender: TObject);
- begin
- OpenDialog1.Filter := GraphicFilter(TGraphic);
- Colors1.Enabled := Image1.Picture.Graphic is TFIFImage;
- Caption := Application.Title;
- if not LoadFIFDecodeLibrary(FIFDecodeDLLName, False) then
- Application.MessageBox('Can''t find '+FIFDecodeDLLName+
- '. You will not be able to view FIF images until the '+
- 'Iterated Systems FIF decoder DLL is installed. '+
- 'To install the decoder DLL, run extras\fif\FD12W32.EXE '+
- 'found on the Delphi CDRom.', 'FIF Not Installed', mb_OK);
- end;
-
- procedure TImgViewForm.UpdateCaption;
- var
- ZoomTop, ZoomBottom: Integer;
- begin
- if Length(Filename) = 0 then
- Caption := Application.Title
- else
- begin
- ZoomTop := 1;
- ZoomBottom := 1;
- if Zoom < 0 then
- ZoomBottom := Abs(Zoom)+1
- else if Zoom > 0 then
- ZoomTop := Zoom+1;
- Caption := Format('%s - %s (%d:%d)',[Application.Title, Filename, ZoomTop,
- ZoomBottom]);
- end;
- end;
-
- procedure TImgViewForm.Open1Click(Sender: TObject);
- begin
- if OpenDialog1.Execute then
- begin
- Image1.Autosize := True;
- Image1.Picture.LoadFromFile(OpenDialog1.Filename);
- Colors1.Enabled := Image1.Picture.Graphic is TFIFImage;
- if Image1.Picture.Graphic is TFIFImage then
- TFIFImage(Image1.Picture.Graphic).OnLoading := UpdateProgressBar;
- Filename := OpenDialog1.Filename;
- FitToWindow;
- UpdateCaption;
- end;
- end;
-
- procedure TImgViewForm.Colors1Click(Sender: TObject);
- begin
- with Image1.Picture.Graphic as TFIFImage do
- case ColorFormat of
- RGB8 : N8bitcolor1.Checked := True;
- RGB15: N15bitcolor1.Checked := True;
- RGB24: N24bitcolor1.Checked := True;
- GRAYSCALE8: N8bitgrayscale1.Checked := True;
- end;
- end;
-
- procedure TImgViewForm.ChangeColorFormat(Sender: TObject);
- begin
- (Image1.Picture.Graphic as TFIFImage).ColorFormat :=
- TColorFormat((Sender as TComponent).Tag);
- end;
-
- procedure TImgViewForm.Image1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- case Button of
- mbLeft: Inc(Zoom);
- mbRight: Dec(Zoom);
- end;
- Rescale;
- UpdateCaption;
- end;
-
- procedure TImgViewForm.Rescale;
- var
- Multiplier: Double;
- begin
- if Zoom > 0 then
- Multiplier := Zoom + 1
- else if Zoom < 0 then
- Multiplier := 1 / (Abs(Zoom) + 1)
- else
- Multiplier := 1;
- with Image1.Picture do
- if Graphic is TFIFImage then
- begin
- Image1.Autosize := True;
- Image1.Stretch := False;
- Graphic.Width := Trunc(TFIFImage(Graphic).OriginalWidth * Multiplier);
- Graphic.Height := Trunc(TFIFImage(Graphic).OriginalHeight * Multiplier);
- end
- else
- begin
- Image1.AutoSize := Zoom = 0;
- Image1.Stretch := Zoom <> 0;
- if Zoom <> 0 then
- begin
- Image1.Width := Trunc(Graphic.Width * Multiplier);
- Image1.Height := Trunc(Graphic.Height * Multiplier);
- end;
- end;
- end;
-
- procedure TImgViewForm.FitToWindow;
- begin
- Zoom := 0;
- Scrollbox1.Visible := False;
- try
- Rescale;
- if Image1.Width > Scrollbox1.Width then
- begin
- Zoom := -Trunc((Image1.Width / Scrollbox1.Width) + 0.5);
- Rescale;
- end;
- if Image1.Height > Scrollbox1.Height then
- begin
- Zoom := Zoom - Trunc((Image1.Height / ScrollBox1.Height) + 0.5);
- Rescale;
- end;
- finally
- Scrollbox1.Visible := True;
- end;
- end;
-
- procedure TImgViewForm.UpdateProgressBar(Sender: TObject; Action: TProgressAction;
- PercentComplete: Longint);
- begin
- case Action of
- paStart: Screen.Cursor := crHourGlass;
- paRunning:
- begin
- StatusBar1.SimpleText :=
- Format('Decompressing: %d%% complete.', [PercentComplete]);
- StatusBar1.Update;
- end;
- paEnd:
- begin
- Screen.Cursor := crDefault;
- StatusBar1.SimpleText := '';
- end;
- end;
- end;
-
- end.
-