home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / olympus / ik32_15t / delphi2.shr / UOPTIM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-01  |  6.7 KB  |  193 lines

  1. {  Project Optim.DPR Delphi 2.0 Demos
  2.  
  3.    Description:- Optim.Dpr Project:-
  4.  
  5.    Demonstrates the use of:
  6.  
  7.    1) 'OptimizePal'
  8.    2) 'RemapPal'
  9.    3) 'Dither'
  10.  
  11.    Date of Origin: 17/04/96
  12.    Original Author: Andrew Hutchison
  13.    Modification History:
  14.  
  15.    Date        Person                            Change
  16.    ----------------------------------------------------
  17.    17/04/96    A Hutchison                       Created
  18.  
  19.    (c) Copyright Media Architects Inc. 1996.
  20.    All rights reserved.   No part of this program may be
  21.    photocopied, reproduced, translated to another programming
  22.    language or transported to any computer system without the
  23.    prior written consent of Media Architects Inc.}
  24.  
  25. unit UOptim;
  26.  
  27. interface
  28.  
  29. uses
  30.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  31.   Menus, OleCtrls, ImageKnife32, StdCtrls, Buttons;
  32.  
  33. type
  34.   TForm1 = class(TForm)
  35.     MainMenu1: TMainMenu;
  36.     File1: TMenuItem;
  37.     LoadSourceImage1: TMenuItem;
  38.     LoadSourceImage2: TMenuItem;
  39.     LoadDestinationImage: TMenuItem;
  40.     N1: TMenuItem;
  41.     Exit: TMenuItem;
  42.     OpenDialog: TOpenDialog;
  43.     GroupBox1: TGroupBox;
  44.     GroupBox2: TGroupBox;
  45.     GroupBox3: TGroupBox;
  46.     Picbufsrc1: TPicbuf;
  47.     Picbufsrc2: TPicbuf;
  48.     Picbufdest: TPicbuf;
  49.     RemapSrc1: TSpeedButton;
  50.     DitherSrc1: TSpeedButton;
  51.     RemapSrc2: TSpeedButton;
  52.     DitherSrc2: TSpeedButton;
  53.     Optimize: TSpeedButton;
  54.     procedure LoadImage(Sender: TObject);
  55.     procedure ExitClick(Sender: TObject);
  56.     procedure FormCreate(Sender: TObject);
  57.     procedure RemapSrc1Click(Sender: TObject);
  58.     procedure DitherSrc1Click(Sender: TObject);
  59.     procedure RemapSrc2Click(Sender: TObject);
  60.     procedure DitherSrc2Click(Sender: TObject);
  61.     procedure OptimizeClick(Sender: TObject);
  62.   private
  63.     { Private declarations }
  64.   public
  65.     { Public declarations }
  66.   end;
  67.  
  68. var
  69.   Form1: TForm1;
  70.  
  71. implementation
  72.  
  73. {$R *.DFM}
  74.  
  75. {--------------------------------------------------------------------------------}
  76. {Load an Image into the Correct Picbuf Control.  Please note the use of a single
  77. event handler for more that one menu item.  This saves multiple instances of
  78. identical code.  Each Menu Item for loading is linked to the event 'LoadImage'.
  79. To do this simply open the menu designer, add the Menu Items.  Go to the first
  80. Menu Item - just Highlite it, do not double click it, and then using Object
  81. inspector, pick the Events Page for the Menu Item.  Locate the 'OnClick' heading,
  82. and type in the Name of the Handler you wish to call - in this case 'LoadImage'.
  83. You can then double click the Item, and you will see Delphi creates the 'LoadImage'
  84. handler for you.  To add other Menus to the same event, just highlite the one you
  85. wish to add, go to the events page, loacte the OnClick event, and using the drop
  86. down arrow options, pick the event handler you wish to link the menu to, again
  87. in this case 'LoadImage'.
  88.  
  89. The final step is to allocate a number to the 'TAG' prperty of each menu item so
  90. you can identify which Menu Item sent the Click, in this example we have used
  91. 0,1,2 for Load Source 1, Load Source 2 and Load Destination. }
  92. procedure TForm1.LoadImage(Sender: TObject);
  93. begin
  94. {Display Common Dialog}
  95. if OpenDialog.Execute then
  96. begin
  97. Application.ProcessMessages;                                           {Catch Up}
  98. {Make sure the Sender parameter is a 'TMenuItem' - in our Case it will be one of
  99. three. Either Load Source 1, Source 2 or Destination Image}
  100. With Sender as TMenuItem do
  101. Case Tag of               {Reference TAG value of the MenuItem sending the Click}
  102. 0:                                                      {Load Source 1 Menu Item}
  103. begin
  104. PicbufSrc1.Filename:=OpenDialog.FileName;                           {Set FileName}
  105. PicbufSrc1.Load;                                                      {Load Image}
  106. end;
  107. 1:                                                      {Load Source 2 Menu Item}
  108. begin
  109. PicbufSrc2.Filename:=OpenDialog.FileName;                          {Set FileName}
  110. PicbufSrc2.Load;                                                     {Load Image}
  111. end;
  112. 2:                                                   {Load Destination Menu Item}
  113. begin
  114. PicbufDest.Filename:=OpenDialog.FileName;                          {Set FileName}
  115. PicbufDest.Load;                                                     {Load Image}
  116. end;
  117. end;
  118. end;
  119. end;
  120.  
  121. {--------------------------------------------------------------------------------}
  122. {Exit Application}
  123. procedure TForm1.ExitClick(Sender: TObject);
  124. begin
  125. Halt;
  126. end;
  127.  
  128. {--------------------------------------------------------------------------------}
  129. {Set Defaults}
  130. procedure TForm1.FormCreate(Sender: TObject);
  131. begin
  132. Application.HintPause:=10;
  133. Application.HintColor:=clAqua;
  134. end;
  135.  
  136. {--------------------------------------------------------------------------------}
  137. {Map 'Source1' Palette to 'Destination'}
  138. procedure TForm1.RemapSrc1Click(Sender: TObject);
  139. begin
  140. {This code remaps the Image in 'Source1' to the Palette of the Destination Image.}
  141. PicbufSrc1.RemapPal(PicbufDest.OLEOBJECT);
  142. end;
  143.  
  144. {--------------------------------------------------------------------------------}
  145. {Dither 'Source1' Palette to 'Destination' Palette}
  146. procedure TForm1.DitherSrc1Click(Sender: TObject);
  147. begin
  148. {This code dithers the Image in 'Source1' to the Palette of the Destination Image.}
  149. PicbufSrc1.DitherPal(PicbufDest.OLEOBJECT);
  150. end;
  151.  
  152. {--------------------------------------------------------------------------------}
  153. {Map 'Source2' Palette to 'Destination'}
  154. procedure TForm1.RemapSrc2Click(Sender: TObject);
  155. begin
  156. {This code remaps the image in Source2 to the palette of the destination image.}
  157. PicbufSrc2.RemapPal(PicbufDest.OLEOBJECT);
  158. end;
  159.  
  160. {--------------------------------------------------------------------------------}
  161. {Dither 'Source2' Palette to 'Destination' Palette}
  162. procedure TForm1.DitherSrc2Click(Sender: TObject);
  163. begin
  164. {This code dithers the image in Source2 to the palette of the destination image.}
  165. PicbufSrc2.DitherPal(PicbufDest.OLEOBJECT);
  166. end;
  167.  
  168.  
  169. {This function not supported as yet by Delphi.  Will require the ImageKnife header
  170. file to be adjusted}
  171. procedure TForm1.OptimizeClick(Sender: TObject);
  172. begin
  173. {------------------ ? ----------------------}
  174. {Type
  175. Image = ^PicbufImageArray;
  176. PicbufImageArray = array[0..1] of Variant;
  177. var
  178. ImageArray : PicbufImageArray;
  179. or
  180. ImageArray : array[0..1] of Variant;}
  181. {----------------- ? -----------------------}
  182. {MyArray : Variant;
  183. begin
  184. MyArray := vararraycreate([0,1],varvariant);
  185. MyArray[0]:= PicbufSrc1.Oleobject;
  186. MyArray[1]:= PicbufSrc2.Oleobject;
  187. PicbufDest.OptimizePal(MyArray, 2, 256 );
  188. {----------------- ? -----------------------}
  189. end;
  190.  
  191.  
  192. end.
  193.