diff options
| author | Joshua Bakita <bakitajoshua@gmail.com> | 2019-10-07 19:13:39 -0400 |
|---|---|---|
| committer | Joshua Bakita <bakitajoshua@gmail.com> | 2019-10-07 19:13:39 -0400 |
| commit | 386b7d3366f1359a265da207a9cafa3edf553b64 (patch) | |
| tree | c76120c2c138faed822e4ae386be6ef22a738a78 /baseline/source/huff_enc | |
| parent | 54a3f7091a2146b29c73a6fdc4b62a5c4ad7a3d8 (diff) | |
Reorganize and commit all the modified TACLeBench code and run scripts
Diffstat (limited to 'baseline/source/huff_enc')
| -rw-r--r-- | baseline/source/huff_enc/ChangeLog.txt | 27 | ||||
| -rw-r--r-- | baseline/source/huff_enc/compress.txt | 1107 | ||||
| -rw-r--r-- | baseline/source/huff_enc/huff_enc.c | 589 |
3 files changed, 1723 insertions, 0 deletions
diff --git a/baseline/source/huff_enc/ChangeLog.txt b/baseline/source/huff_enc/ChangeLog.txt new file mode 100644 index 0000000..020dc4f --- /dev/null +++ b/baseline/source/huff_enc/ChangeLog.txt | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | File: huff_enc.c | ||
| 2 | Original provenience: David Bourgin (David.Bourgin@ufrima.imag.fr) | ||
| 3 | |||
| 4 | 2017-04-18: | ||
| 5 | - Annotated huff_enc_main as entry-point for timing analysis | ||
| 6 | |||
| 7 | 2016-03-24: | ||
| 8 | - Replaced dynamic memory allocation by a fixed array with 514 entries | ||
| 9 | - Replaced memset() with loops | ||
| 10 | - Added source code for a special qsort() implementation without | ||
| 11 | function pointer | ||
| 12 | - Replaced file I/O by reading and writing to char arrays | ||
| 13 | - Added huff_dec_main(), huff_dec_init() and huff_dec_return() | ||
| 14 | - Added huff_dec_ prefix to all functions, types and global variables | ||
| 15 | - Changed function arguments to ANSI style | ||
| 16 | - Replaced macro definitions | ||
| 17 | - Added forward declarations of all functions | ||
| 18 | - Added generic TACLeBench header replacing previous header | ||
| 19 | - Included license from compress.txt | ||
| 20 | - Applied code formatting with astyle | ||
| 21 | |||
| 22 | 2016-05-24: | ||
| 23 | - Changed type of j to unsigned to avoid warning | ||
| 24 | - Removed static declarations | ||
| 25 | |||
| 26 | 2016-05-25: | ||
| 27 | - Precise types to avoid gcc++ warnings | ||
diff --git a/baseline/source/huff_enc/compress.txt b/baseline/source/huff_enc/compress.txt new file mode 100644 index 0000000..5966bcf --- /dev/null +++ b/baseline/source/huff_enc/compress.txt | |||
| @@ -0,0 +1,1107 @@ | |||
| 1 | +===========================================================+ | ||
| 2 | | Introduction to the losslessy compression schemes | | ||
| 3 | | Description of the codec source codes | | ||
| 4 | +-----------------------------------------------------------+ | ||
| 5 | | From David Bourgin (E-mail: david.bourgin@ufrima.imag.fr) | | ||
| 6 | | Date: 22/9/94 | | ||
| 7 | +===========================================================+ | ||
| 8 | |||
| 9 | ------ BE CARE ------ | ||
| 10 | This file (compress.txt) is copyrighted. (c) David Bourgin - 1994 | ||
| 11 | Permission to use this documentation for any purpose other than | ||
| 12 | its incorporation into a commercial product is hereby granted without fee. | ||
| 13 | Permission to copy and distribute this documentation only for non-commercial use | ||
| 14 | is also granted without fee, provided, however, that the above copyright notice | ||
| 15 | appears in all copies, that both that copyright notice and this permission notice appear in supporting documentation. The author makes no representations about | ||
| 16 | the suitability of this documentation for any purpose. It is provided "as is" | ||
| 17 | without express or implied warranty. | ||
| 18 | |||
| 19 | The source codes you obtain with this file are *NOT* covered by the same | ||
| 20 | copyright, because you can include them for both commercial and non-commercial | ||
| 21 | use. See below for more infos. | ||
| 22 | |||
| 23 | The source code files (codrl1.c, dcodrl1.c, codrle2.c, dcodrle2.c, codrle3.c, | ||
| 24 | dcodrle3.c, codrle4.c, dcodrle4.c, codhuff.c, dcodhuff.c) are copyrighted. | ||
| 25 | They have been uploaded on ftp in turing.imag.fr (129.88.31.7):/pub/compression | ||
| 26 | on 22/5/94 and have been modified on 22/9/94. | ||
| 27 | (c) David Bourgin - 1994 | ||
| 28 | The source codes I provide have no buggs (!) but being that I make them | ||
| 29 | available for free I have some notes to make. They can change at any time | ||
| 30 | without notice. I assume no responsability or liability for any errors or | ||
| 31 | inaccurracies, make no warranty of any kind (express, implied or statutory) | ||
| 32 | with respect to this publication and expressly disclaim any and all warranties | ||
| 33 | of merchantability, fitness for particular purposes. Of course, if you have | ||
| 34 | some problems to use the information presented here, I will try to help you if | ||
| 35 | I can. | ||
| 36 | |||
| 37 | If you include the source codes in your application, here are the conditions: | ||
| 38 | - You have to put my name in the header of your source file (not in the | ||
| 39 | excutable program if you don't want) (this item is a must) | ||
| 40 | - I would like to see your resulting application, if possible (this item is not | ||
| 41 | a must, because some applications must remain secret) | ||
| 42 | - Whenever you gain money with your application, I would like to receive a very | ||
| 43 | little part in order to be encouraged to update my source codes and to develop | ||
| 44 | new schemes (this item is not a must) | ||
| 45 | --------------------- | ||
| 46 | |||
| 47 | There are several means to compress data. Here, we are only going to deal with | ||
| 48 | the losslessy schemes. These schemes are also called non-destructive because | ||
| 49 | you always recover the initial data you had, and this, as soon as you need them. | ||
| 50 | With losslessy schemes, you won't never lose any informations (except perhaps | ||
| 51 | when you store or transmit your data but this is another problem...). | ||
| 52 | |||
| 53 | In this introduction, we are going to see: | ||
| 54 | - The RLE scheme (with different possible algorithms) | ||
| 55 | - The Huffman schemes (dynamical scheme) | ||
| 56 | - And the LZW scheme | ||
| 57 | |||
| 58 | For the novice, a compresser is a program able to read several data (e.g. bytes) | ||
| 59 | in input and to write several data in output. The data you obtain from the | ||
| 60 | output (also called compressed data) will - of course - take less space than | ||
| 61 | the the input data. This is true in most of cases, if the compresser works | ||
| 62 | and if the type of the data is correct to be compressed with the given scheme. | ||
| 63 | The codec (coder-decoder) enables you to save space on your hard disk and/or | ||
| 64 | to save the communication costs because you always store/transmit the compressed | ||
| 65 | data. You'll use the decompresser as soon as you need to recover your initial | ||
| 66 | useful data. Note that the compressed data are useless if you have not | ||
| 67 | the decoder... | ||
| 68 | |||
| 69 | You are doubtless asking "How can I reduce the data size without losing some | ||
| 70 | informations?". It's easy to answer to this question. I'll only take an example. | ||
| 71 | I'm sure you have heard about the morse. This system established in the 19th | ||
| 72 | century use a scheme very close to the huffman one. In the morse you encode | ||
| 73 | the letters to transmit with two kinds of signs. If you encode these two sign | ||
| 74 | possibilities in one bit, the symbol 'e' is transmitted in a single bit and | ||
| 75 | the symbols 'y' and 'z' need four bits. Look at the symbols in the text you are | ||
| 76 | reading, you'll fast understand the compression ratio... | ||
| 77 | |||
| 78 | Important: The source codes associated to the algorithms I present are | ||
| 79 | completely adaptative on what you need to compress. They all use basical | ||
| 80 | macros on the top of the file. Usually the macros to change are: | ||
| 81 | |||
| 82 | - beginning_of_data | ||
| 83 | - end_of_data | ||
| 84 | - read_byte | ||
| 85 | - read_block | ||
| 86 | - write_byte | ||
| 87 | - write_block | ||
| 88 | |||
| 89 | These allow the programmer to modify only a little part of the header | ||
| 90 | of the source codes in order to compress as well memory as files. | ||
| 91 | |||
| 92 | beginning_of_data(): Macro used to set the program so that the next read_byte() | ||
| 93 | call will read the first byte to compress. | ||
| 94 | end_of_data(): Returns a boolean to know whether there is no more bytes to read | ||
| 95 | from the input stream. Return 0 if there is no more byte to compress, another | ||
| 96 | non-zero value otherwise. | ||
| 97 | read_byte(): Returns a byte read from the input stream if available. | ||
| 98 | write_byte(x): Writes the byte 'x' to the output stream. | ||
| 99 | read_block(...) and write_block(...): Same use as read_byte and write_byte(x) | ||
| 100 | but these macros work on blocks of bytes and not only on a single byte. | ||
| 101 | |||
| 102 | If you want to compress *from* the memory, before entering in a xxxcoding | ||
| 103 | procedure ('xxx' is the actual extension to replace with a given codec), you | ||
| 104 | have to add a pointer set up to the beginning of the zone to compress. Note | ||
| 105 | that the following pointer 'source_memory_base' is not to add, it is just given | ||
| 106 | here to specify a name to the address of the memory zone you are going to | ||
| 107 | encode or decode. That is the same about source_memory_end which can be either | ||
| 108 | a pointer to create or an existing pointer. | ||
| 109 | |||
| 110 | unsigned char *source_memory_base, /* Base of the source memory */ | ||
| 111 | *source_memory_end, /* Last address to read. | ||
| 112 | source_memory_end=source_memory_base+source_zone_length-1 */ | ||
| 113 | *source_ptr; /* Used in the xxxcoding procedure */ | ||
| 114 | void pre_start() | ||
| 115 | { source_ptr=source_memory_base; | ||
| 116 | xxxcoding(); | ||
| 117 | } | ||
| 118 | |||
| 119 | end_of_data() and read_byte() are also to modify to compress *from* memory: | ||
| 120 | |||
| 121 | #define end_of_data() (source_ptr>source_memory_end) | ||
| 122 | #define read_byte() (*(source_ptr++)) | ||
| 123 | |||
| 124 | If you want to compress *to* memory, before entering in a xxxcoding procedure | ||
| 125 | ('xxx' is the actual extension to replace with a given codec), you have to add | ||
| 126 | a pointer. Note that the pointer 'dest_memory_base' is not to add, it is just | ||
| 127 | given there to specify the address of the destination memory zone you are | ||
| 128 | going to encode or decode. | ||
| 129 | |||
| 130 | unsigned char *dest_memory_base, /* Base of the destination memory */ | ||
| 131 | *dest_ptr; /* Used in the xxxcoding procedure */ | ||
| 132 | void pre_start() | ||
| 133 | { dest_ptr=dest_memory_base; | ||
| 134 | xxxcoding(); | ||
| 135 | } | ||
| 136 | |||
| 137 | Of course, you can combine both from and to memory in the pre_start() procedure. | ||
| 138 | The files dest_file and source_file handled in the main() function are | ||
| 139 | to remove... | ||
| 140 | |||
| 141 | void pre_start() | ||
| 142 | { source_ptr=source_memory_base; | ||
| 143 | dest_ptr=dest_memory_base; | ||
| 144 | xxxcoding(); | ||
| 145 | } | ||
| 146 | |||
| 147 | In fact, to write to memory, the problem is in the write_byte(x) procedure. | ||
| 148 | This problem exists because your destination zone can either be a static | ||
| 149 | zone or a dynamically allocated zone. In the two cases, you have to check | ||
| 150 | if there is no overflow, especially if the coder is not efficient and must | ||
| 151 | produce more bytes than you reserved in memory. | ||
| 152 | |||
| 153 | In the first case, with a *static* zone, write_byte(x) macro should look like | ||
