home *** CD-ROM | disk | FTP | other *** search
- { Project Optim.DPR Delphi 2.0 Demos
-
- Description:- Optim.Dpr Project:-
-
- Demonstrates the use of:
-
- 1) 'OptimizePal'
- 2) 'RemapPal'
- 3) 'Dither'
-
- Date of Origin: 17/04/96
- Original Author: Andrew Hutchison
- Modification History:
-
- Date Person Change
- ----------------------------------------------------
- 17/04/96 A Hutchison Created
-
- (c) Copyright Media Architects Inc. 1996.
- All rights reserved. No part of this program may be
- photocopied, reproduced, translated to another programming
- language or transported to any computer system without the
- prior written consent of Media Architects Inc.}
-
- unit UOptim;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Menus, OleCtrls, ImageKnife32, StdCtrls, Buttons;
-
- type
- TForm1 = class(TForm)
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- LoadSourceImage1: TMenuItem;
- LoadSourceImage2: TMenuItem;
- LoadDestinationImage: TMenuItem;
- N1: TMenuItem;
- Exit: TMenuItem;
- OpenDialog: TOpenDialog;
- GroupBox1: TGroupBox;
- GroupBox2: TGroupBox;
- GroupBox3: TGroupBox;
- Picbufsrc1: TPicbuf;
- Picbufsrc2: TPicbuf;
- Picbufdest: TPicbuf;
- RemapSrc1: TSpeedButton;
- DitherSrc1: TSpeedButton;
- RemapSrc2: TSpeedButton;
- DitherSrc2: TSpeedButton;
- Optimize: TSpeedButton;
- procedure LoadImage(Sender: TObject);
- procedure ExitClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure RemapSrc1Click(Sender: TObject);
- procedure DitherSrc1Click(Sender: TObject);
- procedure RemapSrc2Click(Sender: TObject);
- procedure DitherSrc2Click(Sender: TObject);
- procedure OptimizeClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- {--------------------------------------------------------------------------------}
- {Load an Image into the Correct Picbuf Control. Please note the use of a single
- event handler for more that one menu item. This saves multiple instances of
- identical code. Each Menu Item for loading is linked to the event 'LoadImage'.
- To do this simply open the menu designer, add the Menu Items. Go to the first
- Menu Item - just Highlite it, do not double click it, and then using Object
- inspector, pick the Events Page for the Menu Item. Locate the 'OnClick' heading,
- and type in the Name of the Handler you wish to call - in this case 'LoadImage'.
- You can then double click the Item, and you will see Delphi creates the 'LoadImage'
- handler for you. To add other Menus to the same event, just highlite the one you
- wish to add, go to the events page, loacte the OnClick event, and using the drop
- down arrow options, pick the event handler you wish to link the menu to, again
- in this case 'LoadImage'.
-
- The final step is to allocate a number to the 'TAG' prperty of each menu item so
- you can identify which Menu Item sent the Click, in this example we have used
- 0,1,2 for Load Source 1, Load Source 2 and Load Destination. }
- procedure TForm1.LoadImage(Sender: TObject);
- begin
- {Display Common Dialog}
- if OpenDialog.Execute then
- begin
- Application.ProcessMessages; {Catch Up}
- {Make sure the Sender parameter is a 'TMenuItem' - in our Case it will be one of
- three. Either Load Source 1, Source 2 or Destination Image}
- With Sender as TMenuItem do
- Case Tag of {Reference TAG value of the MenuItem sending the Click}
- 0: {Load Source 1 Menu Item}
- begin
- PicbufSrc1.Filename:=OpenDialog.FileName; {Set FileName}
- PicbufSrc1.Load; {Load Image}
- end;
- 1: {Load Source 2 Menu Item}
- begin
- PicbufSrc2.Filename:=OpenDialog.FileName; {Set FileName}
- PicbufSrc2.Load; {Load Image}
- end;
- 2: {Load Destination Menu Item}
- begin
- PicbufDest.Filename:=OpenDialog.FileName; {Set FileName}
- PicbufDest.Load; {Load Image}
- end;
- end;
- end;
- end;
-
- {--------------------------------------------------------------------------------}
- {Exit Application}
- procedure TForm1.ExitClick(Sender: TObject);
- begin
- Halt;
- end;
-
- {--------------------------------------------------------------------------------}
- {Set Defaults}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Application.HintPause:=10;
- Application.HintColor:=clAqua;
- end;
-
- {--------------------------------------------------------------------------------}
- {Map 'Source1' Palette to 'Destination'}
- procedure TForm1.RemapSrc1Click(Sender: TObject);
- begin
- {This code remaps the Image in 'Source1' to the Palette of the Destination Image.}
- PicbufSrc1.RemapPal(PicbufDest.OLEOBJECT);
- end;
-
- {--------------------------------------------------------------------------------}
- {Dither 'Source1' Palette to 'Destination' Palette}
- procedure TForm1.DitherSrc1Click(Sender: TObject);
- begin
- {This code dithers the Image in 'Source1' to the Palette of the Destination Image.}
- PicbufSrc1.DitherPal(PicbufDest.OLEOBJECT);
- end;
-
- {--------------------------------------------------------------------------------}
- {Map 'Source2' Palette to 'Destination'}
- procedure TForm1.RemapSrc2Click(Sender: TObject);
- begin
- {This code remaps the image in Source2 to the palette of the destination image.}
- PicbufSrc2.RemapPal(PicbufDest.OLEOBJECT);
- end;
-
- {--------------------------------------------------------------------------------}
- {Dither 'Source2' Palette to 'Destination' Palette}
- procedure TForm1.DitherSrc2Click(Sender: TObject);
- begin
- {This code dithers the image in Source2 to the palette of the destination image.}
- PicbufSrc2.DitherPal(PicbufDest.OLEOBJECT);
- end;
-
-
- {This function not supported as yet by Delphi. Will require the ImageKnife header
- file to be adjusted}
- procedure TForm1.OptimizeClick(Sender: TObject);
- begin
- {------------------ ? ----------------------}
- {Type
- Image = ^PicbufImageArray;
- PicbufImageArray = array[0..1] of Variant;
- var
- ImageArray : PicbufImageArray;
- or
- ImageArray : array[0..1] of Variant;}
- {----------------- ? -----------------------}
- {MyArray : Variant;
- begin
- MyArray := vararraycreate([0,1],varvariant);
- MyArray[0]:= PicbufSrc1.Oleobject;
- MyArray[1]:= PicbufSrc2.Oleobject;
- PicbufDest.OptimizePal(MyArray, 2, 256 );
- {----------------- ? -----------------------}
- end;
-
-
- end.
-