home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name UTUNSQZ - Uncompress a screen image.
- *
- * Synopsis length = utunsqz(psource, pdestination,
- * source_length, destination_length);
- *
- * int length The number of bytes actually
- * used by the unsqueezed image.
- * const char *psource The address of the squeezed
- * image to be uncompressed.
- * char far *pdestination The target address for the
- * uncompressed image to be placed.
- * int source_length The length in bytes of the
- * compressed screen image.
- * int destination_length The maximum length in bytes of
- * the uncompressed image. This is
- * the size of the destination
- * buffer.
- *
- * Description UTUNSQZ expands a screen image compressed by UTSQZSCN.
- * For details of the technique used to compress the image,
- * see UTSQZSCN. If the length of the destination buffer
- * is smaller than the uncompressed image, UTUNSQZ will
- * uncompress only as much of the image as will fit in the
- * destination buffer, but will still return the length
- * required for the complete uncompressed image.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1989
- *
- **/
- #include <butil.h>
-
- int utunsqz(psource, pdestination, source_length, destination_length)
- const char *psource;
- char far *pdestination;
- int source_length;
- int destination_length;
- {
- unsigned char char_key;
- unsigned char attr_key;
- int source_index, destination_index;
- int character_count;
- int expanded_len;
- unsigned char current_attr = 0;
- unsigned char current_byte;
-
- if ((psource == NIL) || (pdestination == NIL))
- return(0);
-
- current_attr = 0;
-
- attr_key = psource[0];
- char_key = psource[1];
-
- expanded_len = *((int *) &psource[2]);
-
- source_index = 4;
- destination_index = 0;
-
- /* Now pass through the compressed image. If an attribute key is */
- /* found, the current attribute is altered to the attribute value.*/
- /* If a character key is found, the number of copies of the */
- /* character is output (together with the current attribute). If */
- /* a key is found at the end of the source, it is treated as a */
- /* normal character. */
-
- while (source_index < source_length)
- {
- current_byte = psource[source_index];
-
- if (current_byte == attr_key)
- {
- if (source_index < (source_length - 1))
- {
- source_index++;
- current_attr = psource[source_index];
- }
- else
- {
- pdestination[destination_index++] = current_attr;
- pdestination[destination_index++] = current_byte;
- }
- }
- else
- {
- if ((current_byte == char_key) && ((source_index + 3)
- < source_length))
- {
- source_index++;
- character_count = *((int *) &psource[source_index]);
- source_index += sizeof(int);
- current_byte = psource[source_index];
- }
- else
- character_count = 1;
-
- while (character_count--)
- {
- if (destination_index >= (destination_length - 1))
- return(expanded_len);
-
- pdestination[destination_index++] = current_byte;
- pdestination[destination_index++] = current_attr;
- }
- }
-
- source_index++;
- }
-
- return(expanded_len);
- }