home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / SDI.ZIP / SDIMAGE.DOC < prev    next >
Encoding:
Text File  |  1988-11-26  |  14.9 KB  |  372 lines

  1.                           SDIMAGE V1.02
  2.                          by Michael Day
  3.                      as of 25 November 1988
  4.  
  5.  
  6.      SDImage is a Turbo Pascal unit designed to allow saving  any 
  7. BGI screen to disk. SDImage uses GetImage and PutImage to do  the 
  8. save.  The Program works by using an intermediate buffer to  save 
  9. the image. The size of the buffer is user definable. 
  10.  
  11.  
  12.  
  13. Image Buffer:
  14.    
  15.      There  are 20 image buffers available for use.  At  startup, 
  16. the  buffers  are  not allocated on the  heap,  only  the  buffer 
  17. headers  exist.  This keeps memory usage at a minimum  since  the 
  18. buffers  are  only allocated when they are needed. You  can  also 
  19. release a buffer at any time to pick up the heap space it uses.
  20.  
  21.      You  can either predefine a buffer to the size you want,  or 
  22. the Image buffer will be automatically allocated when the  buffer 
  23. is used. Although 20 buffers should be more than enough for  most 
  24. applications, you can specify more (or fewer) buffers by changing 
  25. the constant "MaxImageBuf" to the desired value. 
  26.  
  27.      Buffers  are used by direct reference in the  command.  This 
  28. makes  buffer usage unambiguous. When a buffer is  referenced  in 
  29. the  SaveImage command, it is first checked to see if it  already 
  30. has an image stored in it. If there is an image in the buffer, it 
  31. is immediately flushed to disk. 
  32.  
  33.      If  the  buffer  does not have an image in it,  then  it  is 
  34. checked  to see if the buffer has not been allocated yet. If  the 
  35. buffer  has not been allocated, then a buffer of default size  is 
  36. allocated.  Currently the default buffer size is 5000,  but  this 
  37. can  be redefined by changing the constant "MaxRawImage"  to  the 
  38. desired  default buffer size. Alternately, the individual  buffer 
  39. sizes  can  be changed at run time by using  the  "AllocImageBuf" 
  40. function.
  41.  
  42.      Once a buffer has been assured to be clean and defined it is 
  43. tested  to see if the image can completely fit in the buffer.  If 
  44. the image can fit in the buffer, then it is placed in the  buffer 
  45. and no further action taken. 
  46.  
  47.      If the image cannot be completely placed in the buffer, then 
  48. a  disk save is performed. The image is moved into the buffer  in 
  49. pieces and flushed to disk until then entire image has been saved 
  50. to disk. The buffer is left empty after a disk save.
  51.  
  52.  
  53.  
  54.  
  55.  
  56. Disk Files:
  57.  
  58.      When   an  image  cannot  fit  in  a  buffer  it   will   be 
  59. automatically  saved to disk instead. Alternately, the image  can 
  60. be  forced to always be directed to the disk (see the section  on 
  61. buffer control).
  62.  
  63.      Images  are  referenced  by an image  reference  number  (or 
  64. handle).  You define the image reference number to be  used  with 
  65. SaveImage  or DisplayImage. This number is used to keep track  of 
  66. the image. If you use the same number for an image, then it  will 
  67. normally be overwritten. An exception to this is if the image  is 
  68. in  a  different buffer. There are no checks made to  see  if  an 
  69. image is in another buffer. 
  70.  
  71.      When an image is written to disk, a file is created using  a 
  72. name  built from the image reference number. An image  file  uses 
  73. the  first three letters "SDI" followed by a leading zero  filled 
  74. number which is the reference number that was passed, followed by 
  75. the file extension of ".IMG". 
  76.  
  77.      An  image  file  will  remain on disk  until  it  is  either 
  78. explictly  erased,  or the DisplayImage function is  called  with 
  79. ImgClr  =  true which will cause the image  to  be  automatically 
  80. erased after the image has been displayed.
  81.  
  82.      Because  an  image  will remain  on  disk  unless  explictly 
  83. erased, it can be very easy to clutter up the disk with old image 
  84. files. For this reason it is recommended that you place the image 
  85. files in their own subdirectory. the "SetImagePath" function  has 
  86. been provided for this purpose.
  87.  
  88.      An  advantage  of having images on disk  referenced  by  the 
  89. image  reference  number  is that images can be  created  in  one 
  90. program  and  displayed in another. A disadvantage  is  that  the 
  91. image  is  saved using the BGI GetImage  and  PutImage  functions 
  92. which means that the display must be the same as the display used 
  93. to create the image.
  94.  
  95.      Saving  images  to  disk allows for a  much  smaller  memory 
  96. requirement  within a program to save images. This can be a  real 
  97. boon  when a program grows too large and you are forced  to  find 
  98. ways  to reduce the amount of memory usage. The  disadvantage  is 
  99. that it is much slower to save an image to disk because you  have 
  100. to deal with the physical access time of the disk drive. This can 
  101. cause  some  problems in the sluggishness of  the  display  while 
  102. saving  or displaying images to/from disk. To help relieve  this, 
  103. SDImage uses special effects to make the display look more active 
  104. and thus giving the user a feeling that the computer is  actually 
  105. doing something to the display while it is busy working with  the 
  106. disk.
  107.  
  108.  
  109.  
  110.  
  111. Special Effects:
  112.  
  113.      Displaying images from disk can take a while to perform,  so 
  114. to  help  liven  things  up  some  special  effects  options  are 
  115. provided.
  116.  
  117.      The special effects work in conjunction with disk  accesses. 
  118. When  an  image  is  being read from disk,  it  usually  must  do 
  119. multiple  buffer writes. By controlling where those writes  occur 
  120. on the screen, special effects can be incorporated into the image 
  121. display.  To do this requires that the image be saved  originally 
  122. in the desired format.
  123.  
  124.      Since   the  special  effects  are  tied  directly  to   the 
  125. disk/buffer transfer, special effects are not operational when an 
  126. image stays in the buffer, or when there is only one buffer image 
  127. in  the disk file. Multiple image segments must be used  to  have 
  128. the  proper  special  effects. Since  only  large  images  really 
  129. benifit from special effects this usually is no problem.
  130.  
  131.      Remember,  the smaller the buffer, the smoother the  special 
  132. effect,  but  at the same time the effect will become  slower  as 
  133. well. This can be compensated for by using a ram-disk instead  of 
  134. a hard disk to store the images.
  135.  
  136.      The  Special  effects are controlled by the  "Style"  option 
  137. word  that is passed to the SaveImage function. The  DisplayImage 
  138. function cannot control special effects. The image must be stored 
  139. with the desired effect for it to be active.
  140.  
  141.      The  lower  four  Style bits  control  the  special  effects 
  142. operation. Bit 2 controls whether the image will be displayed  as 
  143. a "Pull" or via an Expand/Merge operation. Bit 1 controls whether 
  144. the image will grow in the Horizontal or vertical direction.  Bit 
  145. 0 controls the edge that the image will grow from, or whether  it 
  146. will expand or merge. Bit 3 is currently unused.
  147.  
  148.  
  149.                        Style
  150.      +---+-----+---------+------+-------------+ 
  151.      |bit|  3  |    2    |  1   |      0      | 
  152.      +---+-----+---------+------+-------------+ 
  153.      | 1 | --- | Xpd/Mrg | Horz | Xpd/Left/Dn | 
  154.      +---+-----+---------+------+-------------+ 
  155.      | 0 | --- |  Pull   | Vert | Mrg/Rght/Up | 
  156.      +---+-----+---------+------+-------------+ 
  157.  
  158.           0=Pull Down
  159.           1=Pull Up
  160.           2=Pull Right 
  161.           3=Pull Left 
  162.           4=Merge Vertical
  163.           5=Expand Vertical
  164.           6=Merge Horizontal
  165.           7=Expand Horizontal
  166.  
  167. Note:  Special effects only operate when the image is  read  from 
  168. the disk, in fact it works because it uses the disk buffering  as 
  169. an inherent part of the effects control. 
  170.  
  171.  
  172.      
  173.  
  174. Buffer Control:
  175.  
  176.      The  upper  four bits of the Style byte control  the  buffer 
  177. operation. Bit 7 controls the Disk, and bit 6 controls the EMS.
  178.  
  179.  
  180.    -->     EMS is not currently supported in SDImage.     <--
  181.  
  182.  
  183.      If bit 7 is on, then the image will always be saved to disk. 
  184. If bit 7 is off, then the image will try to stay in the buffer if 
  185. possible.
  186.  
  187.      Bit 6 is intended for EMS control. The intent is that if Bit 
  188. 6  is on, then the image will be directed to the EMS  instead  of 
  189. disk.  If  bit 6 is off, then the Disk will be  used.  In  either 
  190. case, bit 7 controls buffering activity.
  191.  
  192.  
  193.                       Style
  194.          +---+------+-------+-----+-----+ 
  195.          |bit|  7   |   6   |  5  |  4  | 
  196.          +---+------+-------+-----+-----+ 
  197.          | 1 | Disk |  EMS  | --- | --- | 
  198.          +---+------+-------+-----+-----+ 
  199.          | 0 | Auto | NoEMS | --- | --- | 
  200.          +---+------+-------+-----+-----+ 
  201.  
  202.  
  203.      The image flow is controlled as follows:
  204.  
  205.           $00  -> Buffer -> Disk
  206.           $40  -> Buffer -> EMS -> Disk
  207.           $80  -> Disk
  208.           $C0  -> EMS -> Disk
  209.  
  210.  
  211.      Another mechanism that can be used is to refer to a ram disk 
  212. for  the images instead of a hard disk. This allows  the  special 
  213. effects associated with disk operation to be used as well as  the 
  214. reduced program memory requirements while still keeping as fast a 
  215. file access as possible. And since a ram disk can be installed in
  216. EMS memory, this would be one way to get around the current  lack 
  217. of EMS support in SDImage.
  218.  
  219.  
  220.  
  221. Buffer Notes:
  222.  
  223.      Although you can define just about any size buffer you wish, 
  224. there  are some limitations. The maximum buffers size is  limited 
  225. to  65521, and the minimum buffer size is limited to one  row  of 
  226. the saved image, or the buffer size of a saved image being read.
  227.  
  228.      If you change the size of a buffer while an image is in  the 
  229. buffer, the buffer will be flushed and the image will be lost.
  230.  
  231.      If a buffer does not exist or is too small for the operation 
  232. it will be automatically resized to an acceptable value.
  233.  
  234.      If  an  image will not fit in the buffer, then  it  will  be 
  235. placed on the disk. If the image is placed on the disk, then  the 
  236. buffer will be left empty at the end of the operation.
  237.  
  238.  
  239. Disk Notes:
  240.  
  241.      When  an image is saved to disk a filename is created  based 
  242. on the image reference number. The filename consists of the three 
  243. letters  "SDI", followed by a left zero filled five digit  number 
  244. which is the image reference number used, followed by an filename 
  245. extension of ".IMG". 
  246.  
  247.      Normally  an image will not be placed on the disk unless  it 
  248. cannot  fit  in the image buffer. Sometimes it  is  desirable  to 
  249. create a disk image for later recall in another program or in the 
  250. same  program  at  a later time. A disk save  can  be  forced  by 
  251. setting  bit  4  ($10) of the "Style"  option  in  the  SaveImage 
  252. function. 
  253.  
  254.      Disk  images use one file per image. Because of  this  there 
  255. can be a lot of image files hanging around if there are a lot  of 
  256. images  saved. It is recommended that the  images  be  placed  in 
  257. their own subdirectory.  This  will  have  the added advantage of 
  258. speeding  things  up a bit  since the directory search won't have 
  259. all the other program files to deal with.
  260.  
  261.      Disk images will be left on the disk if the "ImgClr"  option 
  262. in the "DisplayImage" function is false. If ImgClr is provided as 
  263. true, then the image will be erased from the disk (and/or buffer) 
  264. after it has been displayed. 
  265.  
  266.      If  an image file exists on the disk by the  same  reference 
  267. number  then it will be overwritten by the new image when  it  is 
  268. saved.
  269.  
  270.      You should be aware that if you don't delete the image  file 
  271. while  the program is running it will still be on the disk  after 
  272. the  program has been run. This was done purposely so that  image 
  273. files could be created to be read by other programs or at a later 
  274. date  with the same program. This can however cause a clutter  of 
  275. IMG files if you don't pay attention to this.
  276.  
  277.      You  can  remove  a image file by  just  erasing  the  file. 
  278. Alternately  you  can use the DeleteImage function  to  delete  a 
  279. specific image. 
  280.  
  281.      If   an  image  file  is  requested  and  not   found,   the 
  282. DisplayImage function is aborted and returns a false condition.
  283.  
  284.      If  a  image  file cannot be  created,  then  the  SaveImage 
  285. function will be aborted and returns a false condition.
  286.  
  287.  
  288.  
  289.  
  290.  
  291. SDImage Functions:
  292.  
  293.  
  294.  
  295. AllocImageBuf(Buf:word; Size:word):boolean
  296.  
  297.      Allocates  a specified amount of heap memory to the  buffer. 
  298. The buffer is automatically allocated to the default size if  you 
  299. don't  allocate  the buffer before use. You  can  reallocate  the 
  300. buffer size at anytime. If the buffer number is invalid, or there 
  301. is  not enough heap space to allocated the specified  buffer  the 
  302. function will return false. 
  303.  
  304.  
  305.  
  306.  
  307. ReleaseImageBuf(Buf:word):boolean
  308.  
  309.      Releases the heap space used by the buffer. You can  release 
  310. the  buffer  space at anytime. If the buffer is  deallocated  the 
  311. next  time  you  try to use it, then  it  will  be  automatically 
  312. reallocated  to the default size. If the buffer number  given  is 
  313. invalid the function will return false.
  314.  
  315.  
  316.  
  317.  
  318. SetImagePath(Path:string):boolean
  319.  
  320.      You  can  specify that the images be placed  in  a  separate 
  321. subdirectory  by using this function. It is recommended that  you 
  322. place images in a separate directory if you are saving more  than 
  323. a couple of images to keep directory clutter to a minimum. If the 
  324. Path  could not be found, then the subdirectory will be made.  If 
  325. the subdirectory could not be made, then the function will return 
  326. false. You can preceed the path with a drive letter to direct the 
  327. image  to another drive. When specifying a new path, do  not  use 
  328. the  trailing  '\' SDImage will handle that. Example: 'D:\SDI'.
  329. You  can use the default drive by dropping the drive  letter  and 
  330. colon from the path designation.
  331.  
  332. SaveImage(Img,Buf:word; x1,y1,x2,y2:integer; Style:word):boolean
  333.  
  334.      Use  this  function to save an image to  the  buffer  and/or 
  335. disk.  "Img" specifies the Img reference number, "Buf"  specifies 
  336. the buffer to use, "x1,y1,x2,y2" specifies the area of the screen 
  337. to  save,  and "Style" specifies how to save the  image.  If  the 
  338. Image could not be saved, then SaveImage will return false.
  339.  
  340.  
  341.  
  342.  
  343. DisplayImage(Img,Buf:word; ImgClr:boolean):boolean
  344.  
  345.      Use this function to display the image. "Img" specifies  the 
  346. image  reference  number to find. "Buf" specifies the  buffer  to 
  347. use, and ImgClr specifies whether to delete the image after it is 
  348. used. If ImgClr is false, then the image will not be deleted  and 
  349. DisplayImage  can  refer  to it again at a  later  date.  If  the 
  350. specified  image  is  not found, then  DisplayImage  will  return 
  351. false.
  352.  
  353.  
  354.  
  355.  
  356. FlushImage(Buf:word):boolean
  357.  
  358.      Flushes  an  image to disk from the buffer if  there  is  an 
  359. image in the buffer. You can use this before changing a buffer to 
  360. insure that no images are lost. If the image could not be flushed 
  361. (such as due to a disk error), the function will return false.
  362.  
  363.  
  364.  
  365.  
  366. DeleteImage(Img,Buf:word):boolean
  367.  
  368.      This  deletes an image from the buffer and/or disk.  If  the 
  369. specified image was not found the function will return false.
  370.  
  371. <eof>
  372.