This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:discrete:fall2022:projects:rle0 [2022/09/06 01:34] – [ALGORITHM: RLE] abarbcal | notes:discrete:fall2022:projects:rle0 [2022/09/07 22:57] (current) – [PROGRAM] abarbcal | ||
---|---|---|---|
Line 18: | Line 18: | ||
The RLE algorithm will encode this data by replacing the repeated characters with a count number and a single value. | The RLE algorithm will encode this data by replacing the repeated characters with a count number and a single value. | ||
- | < | + | < |
There are 4 a's (0x61), 2 b' | There are 4 a's (0x61), 2 b' | ||
Line 28: | Line 28: | ||
4 a 2 b 1 c 1 d 1 e 1 f 5 g | 4 a 2 b 1 c 1 d 1 e 1 f 5 g | ||
</ | </ | ||
+ | NOTE: While this example is in readable characters in our eyes, outside of sample0 in the project other samples will not be as readable to you and I. However, rest be assured that the same algorithm will still apply throughout all the samples. The program' | ||
+ | |||
Please reference the image below to find the hexadecimal value of the ASCII symbols: | Please reference the image below to find the hexadecimal value of the ASCII symbols: | ||
{{ : | {{ : | ||
+ | |||
+ | NOTE: Use chars as they will give a hex-byte value as opposed to any kind of string or integer values that they may be converted to from other data types. | ||
=====SPECIFICATIONS===== | =====SPECIFICATIONS===== | ||
- | Our task is to ask questions on Discord or in class, document our findings on this wiki page, and implement the RLE encoding/ | + | Our task is to ask questions on Discord or in class, document our findings on this wiki page, and implement the RLE encoding/ |
+ | |||
+ | To use xxd within lab46: | ||
+ | < | ||
+ | USERNAME@lab46: | ||
+ | </ | ||
+ | To use xxd inside vim: | ||
+ | < | ||
+ | :%!xxd | ||
+ | </ | ||
+ | |||
+ | The decoder should be able to take the output of the encoder and give back the file initially inputted to the encoder. The decoder should make use of the header to find the filename alongside the contents of the file to decode the file. | ||
+ | Furthermore, | ||
+ | |||
+ | **NOTE:** The encoder and decoder are two separate programs. | ||
+ | |||
+ | While fetching data from the source file, use the function feof() from stdlib.h to ensure the end of file has been found; This will help you avoid any false positives resulting in unpredictable behavior. | ||
+ | |||
+ | Example: | ||
+ | <code c> | ||
+ | while ( !feof( in ) ) | ||
+ | { | ||
+ | data = fgetc( in ); | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | *The in_file should be taken from the user as argv[1]. | ||
+ | |||
+ | *The out_file should also be taken from the user as argv[2]. | ||
====DATA HEADER SPECIFICATIONS==== | ====DATA HEADER SPECIFICATIONS==== | ||
- | Header Format:\\ | + | Header Format: |
byte 0: 0x72\\ | byte 0: 0x72\\ | ||
Line 49: | Line 81: | ||
byte 9: 0x01 (version)\\ | byte 9: 0x01 (version)\\ | ||
byte 10: 0x01 (stride value)\\ | byte 10: 0x01 (stride value)\\ | ||
- | byte 11: 0xArgv source file name length (not including NULL terminator)\\ | + | byte 11: 0xArgv |
- | byte 12: source file name + through byte 11 value minus 1 | + | (how many characters in Argv - 1)\\ |
+ | byte 12: The name of the source file, not including the NULL terminator\\ | ||
- | ==Info== | + | ===Info=== |
- | Byte 8 - Reserved for a future project. | + | Byte 8 - Reserved for a future project.\\ |
- | Byte 9 - Version number, this week is version 1. | + | Byte 9 - Version number, this week is version 1.\\ |
- | Byte A - Width of comparison. 1 byte for this week's project. | + | Byte A - Width of comparison. 1 byte for this week's project.\\ |
- | Byte B - ' | + | Byte B - ' |
In the case of ' | In the case of ' | ||
=====PROGRAM===== | =====PROGRAM===== | ||
- | encode | + | Encode |
<cli> | <cli> | ||
./encode INFILE | ./encode INFILE | ||
Line 69: | Line 102: | ||
./encode sample0.txt sample0.txt.rle | ./encode sample0.txt sample0.txt.rle | ||
</ | </ | ||
+ | Encoder will output a file with a name equivalent to the second argument. | ||
- | decode | + | Decode |
<cli> | <cli> | ||
- | ./decode INFILE | + | ./decode INFILE |
- | | + | |
- | ./decode sample0.txt.rle | + | ./decode sample0.txt.rle |
</ | </ | ||
+ | The decoder should be able to read the header and find out the filename if a second argument is not given. If a second argument is given it will use the second argument instead of taking the filename from the header. | ||
+ | Decode will output a file of similar name without the .rle extension after running your decoder. | ||
=====OUTPUT SPECIFICATIONS===== | =====OUTPUT SPECIFICATIONS===== | ||
+ | Program should be able to encode a file such as sample0.txt and successfully output sample0.txt.rle in a similar manner to the file given to you when you initially grabbed the project. Checksums should be identical to each other. Similar to encoding, decoding should be identical with an input of sample0.txt.rle for example, it should output a file sample0.txt with a checksum equivalent to that of sample0.txt when you first grabbed the project. | ||
+ | |||
+ | Output some data after a successful run of the program with information of how many characters were encoded and how many characters were printed into the output file with a comparison percentage in regards to file compression. | ||
+ | |||
+ | < | ||
+ | Encoded: xxx bytes | ||
+ | Decoded: xxx bytes | ||
+ | File compression: | ||
+ | |||
+ | </ | ||
=====VERIFICATION===== | =====VERIFICATION===== | ||
Line 94: | Line 140: | ||
</ | </ | ||
+ | |||
+ | Verify your program' | ||
+ | |||
+ | **NOTE:** This is not the full make check output, this is pending a full successful make check so if one is achieved feel free to delete this. | ||
+ | Verification adds the in/ to the input file name argument, as well as the out/ for the output file name argument. | ||
+ | <cli> | ||
+ | USERNAME@lab46: | ||
+ | ================================================= | ||
+ | = PHASE 0: Raw -> Encode data verification test = | ||
+ | ================================================= | ||
+ | in/ | ||
+ | in/ | ||
+ | in/ | ||
+ | in/ | ||
+ | |||
+ | ================================================= | ||
+ | = PHASE 1: Decode -> Raw data verification test = | ||
+ | ================================================= | ||
+ | in/ | ||
+ | in/ | ||
+ | in/ | ||
+ | in/ | ||
+ | |||
+ | ================================================ | ||
+ | = PHASE 2: Raw -> Encode -> Decode -> Raw test = | ||
+ | ================================================ | ||
+ | in/ | ||
+ | in/ | ||
+ | in/ | ||
+ | in/ | ||
+ | |||
+ | ============================================= | ||
+ | = PHASE 3: Decode -> Raw -> Encode Raw test = | ||
+ | ============================================= | ||
+ | in/ | ||
+ | in/ | ||
+ | in/ | ||
+ | in/ | ||
+ | </ |