summaryrefslogtreecommitdiffstats
path: root/baseline/source/huff_enc
diff options
context:
space:
mode:
authorJoshua Bakita <bakitajoshua@gmail.com>2019-10-07 19:13:39 -0400
committerJoshua Bakita <bakitajoshua@gmail.com>2019-10-07 19:13:39 -0400
commit386b7d3366f1359a265da207a9cafa3edf553b64 (patch)
treec76120c2c138faed822e4ae386be6ef22a738a78 /baseline/source/huff_enc
parent54a3f7091a2146b29c73a6fdc4b62a5c4ad7a3d8 (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.txt27
-rw-r--r--baseline/source/huff_enc/compress.txt1107
-rw-r--r--baseline/source/huff_enc/huff_enc.c589
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 @@
1File: huff_enc.c
2Original provenience: David Bourgin (David.Bourgin@ufrima.imag.fr)
3
42017-04-18:
5- Annotated huff_enc_main as entry-point for timing analysis
6
72016-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
222016-05-24:
23- Changed type of j to unsigned to avoid warning
24- Removed static declarations
25
262016-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 ------
10This file (compress.txt) is copyrighted. (c) David Bourgin - 1994
11Permission to use this documentation for any purpose other than
12its incorporation into a commercial product is hereby granted without fee.
13Permission to copy and distribute this documentation only for non-commercial use
14is also granted without fee, provided, however, that the above copyright notice
15appears in all copies, that both that copyright notice and this permission notice appear in supporting documentation. The author makes no representations about
16the suitability of this documentation for any purpose. It is provided "as is"
17without express or implied warranty.
18
19The source codes you obtain with this file are *NOT* covered by the same
20copyright, because you can include them for both commercial and non-commercial
21use. See below for more infos.
22
23The source code files (codrl1.c, dcodrl1.c, codrle2.c, dcodrle2.c, codrle3.c,
24dcodrle3.c, codrle4.c, dcodrle4.c, codhuff.c, dcodhuff.c) are copyrighted.
25They have been uploaded on ftp in turing.imag.fr (129.88.31.7):/pub/compression
26on 22/5/94 and have been modified on 22/9/94.
27(c) David Bourgin - 1994
28The source codes I provide have no buggs (!) but being that I make them
29available for free I have some notes to make. They can change at any time
30without notice. I assume no responsability or liability for any errors or
31inaccurracies, make no warranty of any kind (express, implied or statutory)
32with respect to this publication and expressly disclaim any and all warranties
33of merchantability, fitness for particular purposes. Of course, if you have
34some problems to use the information presented here, I will try to help you if
35I can.
36
37If 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
39excutable 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
41a must, because some applications must remain secret)
42- Whenever you gain money with your application, I would like to receive a very
43little part in order to be encouraged to update my source codes and to develop
44new schemes (this item is not a must)
45 ---------------------
46
47There are several means to compress data. Here, we are only going to deal with
48the losslessy schemes. These schemes are also called non-destructive because
49you always recover the initial data you had, and this, as soon as you need them.
50With losslessy schemes, you won't never lose any informations (except perhaps
51when you store or transmit your data but this is another problem...).
52
53In 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
58For the novice, a compresser is a program able to read several data (e.g. bytes)
59in input and to write several data in output. The data you obtain from the
60output (also called compressed data) will - of course - take less space than
61the the input data. This is true in most of cases, if the compresser works
62and if the type of the data is correct to be compressed with the given scheme.
63The codec (coder-decoder) enables you to save space on your hard disk and/or
64to save the communication costs because you always store/transmit the compressed
65data. You'll use the decompresser as soon as you need to recover your initial
66useful data. Note that the compressed data are useless if you have not
67the decoder...
68
69You are doubtless asking "How can I reduce the data size without losing some
70informations?". It's easy to answer to this question. I'll only take an example.
71I'm sure you have heard about the morse. This system established in the 19th
72century use a scheme very close to the huffman one. In the morse you encode
73the letters to transmit with two kinds of signs. If you encode these two sign
74possibilities in one bit, the symbol 'e' is transmitted in a single bit and
75the symbols 'y' and 'z' need four bits. Look at the symbols in the text you are
76reading, you'll fast understand the compression ratio...
77
78Important: The source codes associated to the algorithms I present are
79completely adaptative on what you need to compress. They all use basical
80macros 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
89These allow the programmer to modify only a little part of the header
90of the source codes in order to compress as well memory as files.
91
92beginning_of_data(): Macro used to set the program so that the next read_byte()
93call will read the first byte to compress.
94end_of_data(): Returns a boolean to know whether there is no more bytes to read
95from the input stream. Return 0 if there is no more byte to compress, another
96non-zero value otherwise.
97read_byte(): Returns a byte read from the input stream if available.
98write_byte(x): Writes the byte 'x' to the output stream.
99read_block(...) and write_block(...): Same use as read_byte and write_byte(x)
100but these macros work on blocks of bytes and not only on a single byte.
101
102If you want to compress *from* the memory, before entering in a xxxcoding
103procedure ('xxx' is the actual extension to replace with a given codec), you
104have to add a pointer set up to the beginning of the zone to compress. Note
105that the following pointer 'source_memory_base' is not to add, it is just given
106here to specify a name to the address of the memory zone you are going to
107encode or decode. That is the same about source_memory_end which can be either
108a pointer to create or an existing pointer.
109
110unsigned 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 */
114void pre_start()
115{ source_ptr=source_memory_base;
116 xxxcoding();
117}
118
119end_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
124If 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
126a pointer. Note that the pointer 'dest_memory_base' is not to add, it is just
127given there to specify the address of the destination memory zone you are
128going to encode or decode.
129
130unsigned char *dest_memory_base, /* Base of the destination memory */
131 *dest_ptr; /* Used in the xxxcoding procedure */
132void pre_start()
133{ dest_ptr=dest_memory_base;
134 xxxcoding();
135}
136
137Of course, you can combine both from and to memory in the pre_start() procedure.
138The files dest_file and source_file handled in the main() function are
139to remove...
140
141void pre_start()
142{ source_ptr=source_memory_base;
143 dest_ptr=dest_memory_base;
144 xxxcoding();
145}
146
147In fact, to write to memory, the problem is in the write_byte(x) procedure.
148This problem exists because your destination zone can either be a static
149zone or a dynamically allocated zone. In the two cases, you have to check
150if there is no overflow, especially if the coder is not efficient and must
151produce more bytes than you reserved in memory.
152
153In the first case, with a *static* zone, write_byte(x) macro should look like