home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / packages / win32ada / data.z / Pcxops.adb < prev    next >
Encoding:
Text File  |  1995-12-16  |  18.7 KB  |  593 lines

  1. -- $Source: /home/harp/1/proto/monoBANK/winnt/pcxops.adb,v $ 
  2. -- $Revision: 1.3 $ $Date: 95/12/15 16:49:39 $ $Author: mg $ 
  3. -- $Id: pcxops.adb 1.4 1995/02/08 18:30:50 mps Exp mps $
  4. --
  5. -- This package performs operations on PCX files. 
  6. -- It uses 'use' clauses like the other package bodies.  Only pcx main does
  7. -- not use 'use' clauses.
  8. --
  9.  
  10. with PcxChild;
  11. with Win32.WinDef;
  12. with Win32.WinBase;
  13. with Win32.WinUser;
  14. with Win32.WinGdi;
  15. with Interfaces.C;
  16. with Unchecked_Conversion;
  17.  
  18. use Win32;
  19. use Win32.WinDef;
  20.  
  21.  
  22. package body PcxOps is
  23.  
  24. use type Win32.INT;
  25. use type Win32.LONG;
  26.  
  27. --
  28. -- These are file operations performed with the PCX file.
  29. --
  30. rd_only      : constant := 0;
  31. open_default : constant := 8#644#; -- -rw--r--r--
  32. seek_set     : constant := 0; -- set file pointer = OFFSET bytes
  33. seek_cur     : constant := 1; -- set file pointer = current + OFFSET 
  34. seek_end     : constant := 2; -- set file pointer = EOF + OFFSET 
  35.  
  36.  
  37. function Open(PATH  : LPCSTR;
  38.               OFLAG : INT;
  39.               MODE  : INT:= open_default) return INT;
  40. pragma Interface(C, open);
  41. pragma Interface_Name(open, "_open"); 
  42.  
  43. -- returns -1 if error
  44. function Close(FILE_DES : INT) return INT;
  45. pragma Interface(C, close);
  46. pragma Interface_Name(Close, "_close");
  47.  
  48. -- returns number of bytes actually read
  49. function Read(FILE_DESC     : INT;
  50.               BUFFER        : System.ADDRESS;
  51.               BYTES_TO_READ : INT) return INT;
  52. pragma Interface(C, read);
  53. pragma Interface_Name(Read, "_read");
  54.  
  55. -- returns file pointer value
  56. function Lseek(FILE_DESC : INT;
  57.                OFFSET    : INT;
  58.                WHENCE    : INT) return INT;
  59. pragma Interface(C, lseek);
  60. pragma Interface_Name(Lseek, "_lseek");
  61. --
  62. --
  63. -- This is the PCX header and associated types/constants for processing the
  64. -- file.
  65. --
  66. black             : constant COLORREF := 0;
  67. repeat_signature  : constant := 16#C0#;
  68. repeat_count_mask : constant := 16#3F#;
  69.  
  70. type PALETTEYPE  is array(0..47) of BYTE;
  71. type RESERVEDYPE is array(0..57) of BYTE;
  72.  
  73. type PCX_HEADER_RECORD is record
  74.   MANUFACTURER        : BYTE;
  75.   VERSION             : BYTE;
  76.   ENCODING            : BYTE;
  77.   BITS_PER_PIXEL      : BYTE;
  78.   XMIN                : SHORT;
  79.   YMIN                : SHORT;
  80.   XMAX                : SHORT;
  81.   YMAX                : SHORT;
  82.   HRES                : SHORT;
  83.   VRES                : SHORT;
  84.   PALETTE             : PALETTEYPE;
  85.   RESERVED_1          : BYTE;
  86.   NUM_PLANES          : BYTE;
  87.   BYTES_PER_LINE      : SHORT;
  88.   TYPE_OF_PALETTE     : SHORT;
  89.   RESERVED_2          : RESERVEDYPE;
  90. end record;
  91.  
  92. --
  93. -- This is for keeping the PCX file in memory.  Note that it stays in compressed
  94. -- form.
  95. --
  96. max_pcx_file : constant := 500000;
  97. type PCX_BYTES_ARRAY is array(0..max_pcx_file) of BYTE;
  98.  
  99. --
  100. -- This type is used to keep the level of zoom.  
  101. --
  102. type ZOOM_TYPE is delta 2.0 ** (-16) range -32_767.0..32_767.0;
  103.  
  104. --
  105. -- This type is used to keep a stack of the zoom levels.  This allows easy 
  106. -- zoom in/zoom out.
  107. --
  108. type STACK_ELEMENT is record
  109.   X_OFFSET : INT;
  110.   Y_OFFSET : INT;
  111.   X_SIZE   : INT;
  112.   Y_SIZE   : INT;
  113. end record;
  114. max_stack : constant := PcxChild.max_images;
  115. type STACK_TYPE is array(1..max_stack) of STACK_ELEMENT;
  116.  
  117.  
  118. --
  119. -- Keeps track of the various image display parameters.
  120. --
  121. type INSTANCE_RECORD is record
  122.   CHILDHWND     : HWND;
  123.   PCX_BYTES     : PCX_BYTES_ARRAY;
  124.   PCX_HEADER    : PCX_HEADER_RECORD;
  125.   X_OFFSET      : INT;
  126.   Y_OFFSET      : INT;
  127.   X_SIZE        : INT;
  128.   Y_SIZE        : INT;
  129.   X_SCALE       : ZOOM_TYPE;
  130.   Y_SCALE       : ZOOM_TYPE;
  131.   STACK         : STACK_TYPE;
  132.   STACK_PTR     : INTEGER;
  133.   BITS_PER_LINE : INT;
  134. end record;
  135.  
  136. type INSTANCE_ARRAY is array(1..PcxChild.max_images) of INSTANCE_RECORD;
  137.  
  138. INSTANCE      : INSTANCE_ARRAY;
  139. MAX_WINDOWS   : INTEGER := 0;
  140.  
  141. -- aliased for function Push
  142. --
  143. zoom_msg  : aliased constant Win32.CHAR_Array := "Zoom stack full" & Nul;
  144. error_msg : aliased constant Win32.CHAR_Array := "Pcx Error" & Nul;
  145.  
  146. -- aliased for function Pop
  147. zoom_msg2 : aliased constant Win32.CHAR_Array := "Zoomed all the way out" & Nul;
  148. info_msg2 : aliased constant Win32.CHAR_Array := "Pcx Information" & Nul;
  149.  
  150. -- aliased for procedure Display
  151. CLIENT_RECT     : aliased RECT;
  152.  
  153. -- aliased for procedure Zoom_In
  154. info_msg3  : aliased constant Win32.CHAR_Array := "Pcx Information" & Nul;
  155. zoom_err   : aliased constant Win32.CHAR_Array := "Zoom Scale Set to 1" & Nul;
  156.                        
  157. -- aliased for procedure Initial_Display
  158. error_msg2 : aliased constant Win32.CHAR_Array := "PCX file too big" & Nul;
  159. title_msg  : aliased constant Win32.CHAR_Array := "Pcx Error" & Nul;
  160.  
  161.  
  162. function CP(S : Win32.CHAR_Array) return Win32.LPCSTR is
  163.     function UC is new Ada.Unchecked_Conversion(System.Address,Win32.LPCSTR);
  164. begin
  165.     return UC(S(S'First)'Address);
  166. end CP;
  167.  
  168. --
  169. -- Unchecked_Conversions.
  170. -- This function translates from an HDC to a WPARAM for SendMessage.
  171. --
  172. function Hdc_To_Wparam is new Unchecked_Conversion(HDC, WPARAM);
  173.  
  174. --
  175. -- Find_Instance returns the index of the array element associated with 
  176. -- the HWND passed in.
  177. --
  178. function Find_Instance(HWND : HWND) return INTEGER is
  179.  
  180.     use type System.Address;
  181.  
  182.     INDEX : INTEGER;
  183.  
  184. begin
  185.   INDEX := 1;
  186.   for I in 1..MAX_WINDOWS loop
  187.     if HWND = INSTANCE(I).CHILDHWND then
  188.       INDEX := I;
  189.       exit;
  190.     end if;
  191.   end loop;
  192.   return INDEX;
  193. end Find_Instance;
  194.  
  195. --
  196. -- Saves the state of X_OFFSET, Y_OFFSET, X_SIZE and Y_SIZE.
  197. --
  198. function Push(INDEX : INTEGER) return BOOLEAN is
  199.  
  200.     STACK_PTR : INTEGER;
  201.     IRESULT   : INT;
  202.  
  203. begin
  204.   if INSTANCE(INDEX).STACK_PTR < max_stack then
  205.     STACK_PTR := INSTANCE(INDEX).STACK_PTR;
  206.     INSTANCE(INDEX).STACK(STACK_PTR).X_OFFSET := INSTANCE(INDEX).X_OFFSET;
  207.     INSTANCE(INDEX).STACK(STACK_PTR).Y_OFFSET := INSTANCE(INDEX).Y_OFFSET;
  208.     INSTANCE(INDEX).STACK(STACK_PTR).X_SIZE   := INSTANCE(INDEX).X_SIZE;
  209.     INSTANCE(INDEX).STACK(STACK_PTR).Y_SIZE   := INSTANCE(INDEX).Y_SIZE;
  210.     INSTANCE(INDEX).STACK_PTR := INSTANCE(INDEX).STACK_PTR + 1;
  211.     return TRUE;
  212.   else
  213.     IRESULT := Win32.WinUser.MessageBox(Win32.WinUser.GetFocus,
  214.                                         CP(zoom_msg),
  215.                                         CP(error_msg),
  216.                                         Win32.WinUser.MB_ICONSTOP);
  217.     return FALSE;
  218.   end if;
  219. end Push;
  220.     
  221. --
  222. -- Restores the previous state of X_OFFSET, Y_OFFSET, X_SIZE and Y_SIZE.
  223. --
  224. function Pop(INDEX : INTEGER) return BOOLEAN is
  225.  
  226.     STACK_PTR : INTEGER;
  227.     IRESULT   : INT;
  228.  
  229. begin
  230.   if INSTANCE(INDEX).STACK_PTR > 1 then
  231.     INSTANCE(INDEX).STACK_PTR := INSTANCE(INDEX).STACK_PTR - 1;
  232.     STACK_PTR := INSTANCE(INDEX).STACK_PTR;
  233.     INSTANCE(INDEX).X_OFFSET := INSTANCE(INDEX).STACK(STACK_PTR).X_OFFSET;
  234.     INSTANCE(INDEX).Y_OFFSET := INSTANCE(INDEX).STACK(STACK_PTR).Y_OFFSET;
  235.     INSTANCE(INDEX).X_SIZE   := INSTANCE(INDEX).STACK(STACK_PTR).X_SIZE;
  236.     INSTANCE(INDEX).Y_SIZE   := INSTANCE(INDEX).STACK(STACK_PTR).Y_SIZE;
  237.     return TRUE;
  238.   else
  239.     IRESULT := Win32.WinUser.MessageBox(Win32.WinUser.GetFocus, 
  240.                                         CP(zoom_msg),
  241.                                         CP(info_msg2),
  242.                                         Win32.WinUser.MB_ICONINFORMATION);
  243.     return FALSE;
  244.   end if;
  245. end Pop;
  246.     
  247. --
  248. -- For speed, this function mulitplies a ZOOM_TYPE in assembly.
  249. --
  250. function Scale(NUM    : INT; 
  251.                FACTOR : ZOOM_TYPE) return INT;
  252. pragma Import(C, Scale, "scale");
  253.  
  254.  
  255.  
  256.   bit_7 : constant := 2**7;
  257.   bit_6 : constant := 2**6;
  258.   bit_5 : constant := 2**5;
  259.   bit_4 : constant := 2**4;
  260.   bit_3 : constant := 2**3;
  261.   bit_2 : constant := 2**2;
  262.   bit_1 : constant := 2**1;
  263.   bit_0 : constant := 2**0;
  264.  
  265.   R : BOOL;
  266.  
  267. procedure Display_Byte(HDC            : HDC; 
  268.                        INSTANCE_INDEX : INTEGER;
  269.                        BITS           : BYTE; 
  270.                        X,Y            : INT) is
  271.                        
  272.     use type Interfaces.C.UNSIGNED_CHAR;
  273.  
  274.     WX      : INT;
  275.     X_SCALE : ZOOM_TYPE;
  276.  
  277. begin
  278.   X_SCALE := INSTANCE(INSTANCE_INDEX).X_SCALE;
  279.   if (BITS and bit_7) =0 then 
  280.     WX := Scale(X, X_SCALE);
  281.     R := Win32.WinGdi.SetPixelV(HDC,WX  ,Y,black);
  282.   end if;
  283.  
  284.   if (BITS and bit_3) = 0 then
  285.     WX := Scale(X+4, X_SCALE);
  286.     R := Win32.WinGdi.SetPixelV(HDC,WX,Y,black); 
  287.   end if;
  288.  
  289.   if X_SCALE < 0.3 then return; end if;
  290.  
  291.   if (BITS and bit_6) =0 then
  292.     WX := Scale(X+1, X_SCALE);
  293.     R := Win32.WinGdi.SetPixelV(HDC,WX,Y,black); 
  294.   end if;
  295.   if (BITS and bit_5) =0 then
  296.     WX := Scale(X+2, X_SCALE);
  297.     R := Win32.WinGdi.SetPixelV(HDC,WX,Y,black); 
  298.   end if;
  299.   if (BITS and bit_4) =0 then
  300.     WX := Scale(X+3, X_SCALE);
  301.     R := Win32.WinGdi.SetPixelV(HDC,WX,Y,black); 
  302.   end if;
  303.  
  304.   if (BITS and bit_2) =0 then
  305.     WX := Scale(X+5, X_SCALE);
  306.     R := Win32.WinGdi.SetPixelV(HDC,WX,Y,black); 
  307.   end if;
  308.   if (BITS and bit_1) =0 then
  309.     WX := Scale(X+6, X_SCALE);
  310.     R := Win32.WinGdi.SetPixelV(HDC,WX,Y,black); 
  311.   end if;
  312.   if (BITS and bit_0) =0 then
  313.     WX := Scale(X+7, X_SCALE);
  314.     R := Win32.WinGdi.SetPixelV(HDC,WX,Y,black); 
  315.   end if;
  316. end Display_Byte;
  317. pragma Inline(Display_Byte);
  318.  
  319. --
  320. -- This procedure displays the PCX file according to the current x and y 
  321. -- offsets and scales.
  322. --
  323. procedure Display(HWND : HWND) is
  324.  
  325.     use type Interfaces.C.UNSIGNED_CHAR;
  326.  
  327.     DISPLAY_HDC     : HDC;
  328.     BRESULT         : BOOL;
  329.     IRESULT         : INT;
  330.     LRESULT         : LONG;
  331.     WY              : INT;
  332.     INDEX           : INTEGER;
  333.     X               : INT;
  334.     VALUE           : BYTE;
  335.     COUNT           : BYTE;
  336.     X_LIMIT         : INT;
  337.     Y_LIMIT         : INT;
  338.     INSTANCE_INDEX  : INTEGER;
  339.  
  340. begin
  341.   null;
  342. --
  343. -- Find the occurence of this image.
  344. --
  345.   INSTANCE_INDEX := Find_Instance(HWND);
  346. --
  347. -- Erase the previous image.
  348. --
  349.   DISPLAY_HDC := Win32.WinUser.GetDC(HWND);
  350.   LRESULT := Win32.WinUser.SendMessage(HWND, 
  351.                                        Win32.WinUser.WM_ERASEBKGND, 
  352.                                        Hdc_To_Wparam(DISPLAY_HDC),
  353.                                        0);
  354. --
  355. -- get dimensions of client window, and compute scale factors
  356. --
  357.   BRESULT := Win32.WinUser.GetClientRect(HWND, CLIENT_RECT'access);
  358.   INSTANCE(INSTANCE_INDEX).X_SCALE := ZOOM_TYPE(CLIENT_RECT.RIGHT) / 
  359.                                      ZOOM_TYPE(INSTANCE(INSTANCE_INDEX).X_SIZE);
  360.   INSTANCE(INSTANCE_INDEX).Y_SCALE := ZOOM_TYPE(CLIENT_RECT.BOTTOM) / 
  361.                                      ZOOM_TYPE(INSTANCE(INSTANCE_INDEX).Y_SIZE);
  362.   X_LIMIT := INSTANCE(INSTANCE_INDEX).X_OFFSET + 
  363.                                      INSTANCE(INSTANCE_INDEX).X_SIZE;
  364.   Y_LIMIT := INSTANCE(INSTANCE_INDEX).Y_OFFSET + 
  365.                                      INSTANCE(INSTANCE_INDEX).Y_SIZE;
  366.  
  367.   INDEX := 0;
  368.   for ROW in 0..Y_LIMIT loop
  369.     WY := Scale(ROW-INSTANCE(INSTANCE_INDEX).Y_OFFSET, 
  370.                 INSTANCE(INSTANCE_INDEX).Y_SCALE);
  371.     X := 0;
  372.     loop
  373.       VALUE := INSTANCE(INSTANCE_INDEX).PCX_BYTES(INDEX);
  374.       INDEX := INDEX + 1;
  375.       if (VALUE and repeat_signature) = repeat_signature then
  376.         COUNT := VALUE and repeat_count_mask;
  377.         if ROW >= INSTANCE(INSTANCE_INDEX).Y_OFFSET then
  378.           VALUE := INSTANCE(INSTANCE_INDEX).PCX_BYTES(INDEX);
  379.           for I in 1..COUNT loop
  380.             if X >= INSTANCE(INSTANCE_INDEX).X_OFFSET and 
  381.                X < X_LIMIT then
  382.               Display_Byte(DISPLAY_HDC,
  383.                            INSTANCE_INDEX,
  384.                            VALUE,
  385.                            X-INSTANCE(INSTANCE_INDEX).X_OFFSET,
  386.                            WY);
  387.             end if;
  388.             X := X + 8;
  389.           end loop;
  390.         else                        -- not in the Y_OFFSET range yet
  391.           X := X + 8 * INT(COUNT);
  392.         end if;
  393.         INDEX := INDEX + 1;
  394.       else
  395.         if ROW >= INSTANCE(INSTANCE_INDEX).Y_OFFSET and 
  396.            X >= INSTANCE(INSTANCE_INDEX).X_OFFSET and 
  397.            X < X_LIMIT then
  398.           Display_Byte(DISPLAY_HDC,
  399.                        INSTANCE_INDEX,
  400.                        VALUE,
  401.                        X-INSTANCE(INSTANCE_INDEX).X_OFFSET,
  402.                        WY);
  403.         end if;
  404.         X := X + 8;
  405.       end if;
  406.       exit when X >= INSTANCE(INSTANCE_INDEX).BITS_PER_LINE;
  407.     end loop;
  408.   end loop;
  409.  
  410.   IRESULT := Win32.WinUser.ReleaseDC(HWND, DISPLAY_HDC);
  411. end Display;
  412.  
  413. --
  414. -- Zoom to the new RECT provided.  This RECT refers to the small rectangle used
  415. -- to select the image.
  416. --
  417. procedure Zoom_In(HWND : HWND;
  418.                   RECT : RECT) is
  419.  
  420.     PUSH_OK         : BOOLEAN;
  421.     INSTANCE_INDEX  : INTEGER;
  422.     IRESULT   : INT;
  423.  
  424. begin
  425.   null;
  426. --
  427. -- Find the occurence of this image.
  428. --
  429.   INSTANCE_INDEX := Find_Instance(HWND);
  430.   PUSH_OK := Push(INSTANCE_INDEX);
  431.   if PUSH_OK then
  432.  
  433.     if INSTANCE(INSTANCE_INDEX).X_SCALE < 0.01 or
  434.        INSTANCE(INSTANCE_INDEX).Y_SCALE < 0.01
  435.     then
  436.       IRESULT := Win32.WinUser.MessageBox(Win32.WinUser.GetFocus, 
  437.                                           CP(zoom_err),
  438.                                           CP(info_msg3),
  439.                                           Win32.WinUser.MB_ICONINFORMATION);
  440.       INSTANCE(INSTANCE_INDEX).X_SCALE := 1.0;
  441.       INSTANCE(INSTANCE_INDEX).Y_SCALE := 1.0;
  442.     end if;
  443.      
  444.     INSTANCE(INSTANCE_INDEX).X_OFFSET := INT(ZOOM_TYPE(RECT.LEFT) /
  445.        INSTANCE(INSTANCE_INDEX).X_SCALE) + INSTANCE(INSTANCE_INDEX).X_OFFSET;
  446.     INSTANCE(INSTANCE_INDEX).Y_OFFSET := INT(ZOOM_TYPE(RECT.TOP) /
  447.        INSTANCE(INSTANCE_INDEX).Y_SCALE) + INSTANCE(INSTANCE_INDEX).Y_OFFSET;
  448.  
  449.     INSTANCE(INSTANCE_INDEX).X_SIZE := INT(ZOOM_TYPE(RECT.RIGHT - RECT.LEFT) / 
  450.        INSTANCE(INSTANCE_INDEX).X_SCALE);
  451.     INSTANCE(INSTANCE_INDEX).X_SIZE := 
  452.       (INSTANCE(INSTANCE_INDEX).X_SIZE / 8) * 8;
  453.     INSTANCE(INSTANCE_INDEX).Y_SIZE := INT(ZOOM_TYPE(RECT.BOTTOM - RECT.TOP) / 
  454.        INSTANCE(INSTANCE_INDEX).Y_SCALE);
  455.  
  456.     Display(HWND);
  457.   end if;
  458. end Zoom_In;
  459.  
  460. --
  461. -- Zoom to the previous level.
  462. --
  463. procedure Zoom_Out(HWND : HWND) is
  464.  
  465.     POP_OK          : BOOLEAN;
  466.     INSTANCE_INDEX  : INTEGER;
  467.  
  468. begin
  469.   null;
  470. --
  471. -- Find the occurence of this image.
  472. --
  473.   INSTANCE_INDEX := Find_Instance(HWND);
  474.   POP_OK := Pop(INSTANCE_INDEX);
  475.   if POP_OK then
  476.     Display(HWND);
  477.   end if;
  478. end Zoom_Out;
  479.  
  480.                   
  481. --
  482. -- This procedure displays the initial PCX image in a child window.
  483. --
  484. procedure Initial_Display(HINST        : HINSTANCE;
  485.                           HWND         : HWND;
  486.                           PCX_FILENAME : LPCSTR) is
  487.  
  488.     use type Interfaces.C.SIZE_T;
  489.  
  490.     LEN            : Win32.Strings.SIZE_T;
  491.     PCX_HANDLE     : INT;
  492.     BYTES_READ     : INT;
  493.     LOCATION       : INT;
  494.     FILE_SIZE      : INT;
  495.     BYTES_TO_READ  : INT;
  496.     BRESULT        : BOOL;
  497.     IRESULT        : INT;
  498.     CLIENT_RECT    : aliased RECT;
  499.     WINWIDTH_X     : INT;
  500.     WINWIDTH_Y     : INT;
  501.     ASPECT         : FLOAT;
  502.     SCREENMAX_X    : INT;
  503.     SCREENMAX_Y    : INT;
  504.     CHILDHWND      : Win32.WinDef.HWND;
  505.     INSTANCE_INDEX : INTEGER;
  506.  
  507. begin
  508. --
  509. -- Open the file.
  510. --
  511.   LEN := Win32.Strings.StrLen(PCX_FILENAME);
  512.   if LEN /= 0 then
  513.     PCX_HANDLE := Open(PCX_FILENAME, rd_only);
  514.     MAX_WINDOWS := MAX_WINDOWS + 1;
  515.     INSTANCE_INDEX := MAX_WINDOWS;
  516.     INSTANCE(INSTANCE_INDEX).STACK_PTR := 1;
  517. --
  518. -- Read in the header and the bytes of the PCX file.
  519. --
  520.     BYTES_READ := Read(PCX_HANDLE, INSTANCE(INSTANCE_INDEX).PCX_HEADER'address, 
  521.                               INSTANCE(INSTANCE_INDEX).PCX_HEADER'size / 8);  
  522.     LOCATION  := Lseek(PCX_HANDLE, 0, seek_cur);
  523.     FILE_SIZE := Lseek(PCX_HANDLE, 0, seek_end);
  524.     LOCATION  := Lseek(PCX_HANDLE, LOCATION, seek_set);
  525.     BYTES_TO_READ := FILE_SIZE - INSTANCE(INSTANCE_INDEX).PCX_HEADER'size / 8;
  526.     if BYTES_TO_READ > max_pcx_file then
  527.       IRESULT := Win32.WinUser.MessageBox(HWND, 
  528.                                           CP(error_msg2),
  529.                                           CP(title_msg),
  530.                                           Win32.WinUser.MB_OK);
  531.       return;
  532.     end if;
  533.     BYTES_READ := Read(PCX_HANDLE, 
  534.                        INSTANCE(INSTANCE_INDEX).PCX_BYTES'address, 
  535.                        BYTES_TO_READ);
  536.     IRESULT := Close(PCX_HANDLE);
  537. --
  538. -- Init the display parameters.
  539. --
  540.     INSTANCE(INSTANCE_INDEX).X_OFFSET := 0;
  541.     INSTANCE(INSTANCE_INDEX).Y_OFFSET := 0;
  542.     INSTANCE(INSTANCE_INDEX).X_SIZE := (INT(
  543.                             INSTANCE(INSTANCE_INDEX).PCX_HEADER.XMAX) / 8) * 8;
  544.     INSTANCE(INSTANCE_INDEX).Y_SIZE := INT(
  545.                             INSTANCE(INSTANCE_INDEX).PCX_HEADER.YMAX);
  546.     INSTANCE(INSTANCE_INDEX).BITS_PER_LINE := INT(
  547.                        INSTANCE(INSTANCE_INDEX).PCX_HEADER.BYTES_PER_LINE) * 8;
  548.  
  549. --
  550. -- Create a new window to display the PCX file.
  551. --
  552.     WINWIDTH_X := INT(INSTANCE(INSTANCE_INDEX).PCX_HEADER.XMAX) / 3;
  553.     WINWIDTH_Y := INT(INSTANCE(INSTANCE_INDEX).PCX_HEADER.YMAX) / 3;
  554.     ASPECT := FLOAT(INSTANCE(INSTANCE_INDEX).PCX_HEADER.XMAX) / 
  555.               FLOAT(INSTANCE(INSTANCE_INDEX).PCX_HEADER.YMAX);
  556.     SCREENMAX_X := Win32.WinUser.GetSystemMetrics(Win32.WinUser.SM_CXSCREEN);
  557.     SCREENMAX_Y := Win32.WinUser.GetSystemMetrics(Win32.WinUser.SM_CYSCREEN);
  558.     if WINWIDTH_Y > SCREENMAX_Y then
  559.       WINWIDTH_Y := SCREENMAX_Y;
  560.       WINWIDTH_X := INT(FLOAT(WINWIDTH_Y) * ASPECT);
  561.     end if;
  562.     if WINWIDTH_X > SCREENMAX_X then
  563.       WINWIDTH_X := SCREENMAX_X;
  564.       WINWIDTH_Y := INT(FLOAT(WINWIDTH_X) / ASPECT);
  565.     end if;
  566.     INSTANCE(INSTANCE_INDEX).X_SCALE := ZOOM_TYPE(WINWIDTH_X) / 
  567.                                      ZOOM_TYPE(INSTANCE(INSTANCE_INDEX).X_SIZE);
  568.     INSTANCE(INSTANCE_INDEX).Y_SCALE := ZOOM_TYPE(WINWIDTH_Y) / 
  569.                                      ZOOM_TYPE(INSTANCE(INSTANCE_INDEX).Y_SIZE);
  570.     INSTANCE(INSTANCE_INDEX).CHILDHWND := PcxChild.CreateWindow(HINST, 
  571.                                                                 HWND, 
  572.                                                                 WINWIDTH_X, 
  573.                                                                 WINWIDTH_Y,
  574.                                                                 PCX_FILENAME);
  575.   end if;
  576. end Initial_Display;
  577.  
  578. -------------------------------------------------------------------------------
  579. --
  580. -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS FURNISHED "AS IS" WITHOUT 
  581. -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
  582. -- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR 
  583. -- PURPOSE.  The user assumes the entire risk as to the accuracy and the 
  584. -- use of this file.
  585. --
  586. -- Copyright (c) Intermetrics, Inc. 1995
  587. -- Royalty-free, unlimited, worldwide, non-exclusive use, modification, 
  588. -- reproduction and further distribution of this file is permitted.
  589. --
  590. -------------------------------------------------------------------------------
  591.  
  592. end PcxOps;
  593.