home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / Basic / SDA30.ZIP / IMAGE.DOC < prev    next >
Encoding:
Text File  |  1985-01-25  |  5.4 KB  |  111 lines

  1.                    SDA Compressed Image Format
  2.  
  3.  
  4.     The binary "image" file produced by the Screen Design Aid
  5. (SDA) is actually a quite primitive format.  It is easiest to
  6. think of the image as being composed of two parts:  The field
  7. definitions, and the screen body.  The following paragraphs
  8. defined the precise format of these two parts, which are actually
  9. concatenated to form one contiguous, variable length file.
  10.  
  11. Field Definition Part:
  12.  
  13.     The first word (normal LSB, MSB sequence in memory), contains
  14. a count of the number of fields defined in this image.  The
  15. remainder of this part is composed of four bytes entries, one per
  16. defined field, where the four bytes contain the following
  17. information:
  18.  
  19.     Byte 1:  Contains the binary screen row (top = 0).
  20.     Byte 2:  Contains the binary screen column (left most = 0).
  21.     Byte 3:  Contains the length of the field in binary.
  22.     Byte 4:  Contains the display attribute of the field.
  23.  
  24. These four bytes repeat as many times as necessary to define each
  25. of the fields specified for the screen.
  26.  
  27. Screen Body:
  28.  
  29.     Immediately following the field table part, the next word of
  30. the image contains the binary length of the screen body part,
  31. including this word itself.  The remaining bytes of the body
  32. should be considered a "stream" of bytes.  When the compressed
  33. image is formed, a "scan ahead" function is used.  If more than
  34. three screen positions are found to contain identical characters
  35. AND attributes, then these duplicate characters are discarded and
  36. a special code is inserted in the image.  Similarly, when a
  37. change of attribute is noted, a code is inserted in the image.
  38.  
  39.     To decode the image is straight forward.  Simply load the
  40. "next" byte of the image.  If this byte is a hex 0FFH, the
  41. following byte is the new attribute, and will remain in effect
  42. until another 0FFH flag is encountered.  If this byte is zero,
  43. then the following byte is a "repeat count" (number of
  44. repetitions of the next data character and attribute to be
  45. output).  If the byte loaded is any other value, it is a "data"
  46. byte, and should be output using the current repeat count and the
  47. current attribute.  By setting the "repeat count" to one
  48. initially, and by re-setting it to one after each output
  49. operation, the image will be correctly expanded and displayed.
  50.  
  51.     When all of the "stream" bytes have been processed, you will
  52. have filled the full display screen, and the expand operation is
  53. complete.
  54.  
  55.  
  56.     To further clarify this expansion process, the following
  57. series of steps are provided.
  58.  
  59.     1.  Load the count of fields.
  60.     2.  Multiply the count by four, and then add two.
  61.     3.  Use the value computed as an offset into the image and
  62. load the word at this offset.  This word is the length of the
  63. body of the image INCLUDING THIS WORD.  
  64.     4.  Subtract two from this length, giving the number of bytes
  65. in the compressed image.  This value should be saved, and
  66. decremented each time a byte is loaded from the image.  The
  67. completion test is therefore a simple check to see if this count
  68. is zero.  Set the repeat count equal to one.
  69.     5.  If complete, go to end.
  70.     6.  Load the "next" byte, decrementing the count
  71.     7.  If the byte is 0FFH then load the next byte, decrementing
  72. the count.  Save the loaded byte as the "current attribute".  Go
  73. to step 5.
  74.     8.  If the byte is zero, then load the next byte,
  75. decrementing the count, and save this byte as the "repeat count".
  76. Go to step 5.
  77.     9.  For any other value, save the loaded byte as the "data"
  78. byte, and output this byte using the current attribute, as many
  79. times as the required by the "repeat count".
  80.     10. Set the repeat count = 1.
  81.     11. Go to step 5.
  82.  
  83.     It should be obvious that the first byte encountered in the
  84. compressed image is always a 0FFH, since the first function
  85. required is that of loading a "current attribute". 
  86.  
  87.     It is probably equally obvious that any character can be
  88. displayed, except 0 and 255.  These two characters are reserved
  89. to act as flags.  Neither character can be generated by SDA
  90. during screen design.  Since only one byte is available for the
  91. "repeat count", no repeat count greater than 255 is allowed.
  92. Since this value will always follow a zero byte when used as a
  93. repeat count, no confusion with the attribute flag exists.  If a
  94. character and attribute repeats more than 255 times (this is not
  95. uncommon in screens that are primarily blank), then the maximum
  96. count is set, and the character to be duplicated is inserted.
  97. This sequence is immediately followed by another "repeat count"
  98. flag, another repeat count, and the character to be duplicated.
  99. This repetitive pattern is repeated until a change of character
  100. or attribute is finally encountered, or until the "end of screen"
  101. is found.  It is slightly interesting to note that an all blank
  102. image requires approximately 26 bytes in compressed form.  This
  103. represents 4000 bytes in expanded form.  It is easy to see how
  104. compression can pay signficant storage dividends.
  105.  
  106.     The use of the "repeat count" has a hidden advantage.  BIOS
  107. does provide a call that permits outputing a character and
  108. attribute, "count times".  The form used for this compression
  109. exactly parallels this BIOS call, providing considerably greater
  110. speed than 2000 single character output calls to BIOS.
  111.