What is up steemians? I've brought you a source code I made as a project about a month ago, I'll proceed to explain the thing, I'll also link the code for anyone who wants to try it. It's in spanish, but there's not much text displayed while the program is running so you should be fine. It's made in assembler, IA32 to be exact, notation AT&T. You can compile it using Linux, with "gcc -o thing.s thing" then run it with "./thing" and it should start. You'll need a PBM file which is a type of image file, but black and white, I'll link that too. Also, If you want to decompress a file, you'll need a RLEI file, but i don't know if that can be found outside of this project.
The project is pretty straightforward, you have to make a code in assembler that can compress or decompress a file that's being input by the user. If you compress, it asks a PBM file, and outputs a RLEI file that should be lighter, viceversa if you want to decompress. It starts with 3 options, the 2 I just mentioned and Exit, once the user wants to do either, the program asks for 2 files, one that HAS to exist and the other that could but doesn't need to.
The user needs to write the name of the first file (with extension included) and then input the name of the output file. The program will start by verifying if the file is indeed a legit PBM/RLEI (depending of what it's doing) and it will start making the output file. The procedure of compressing a file is counting how many bytes of the file are the same in the current string, so it has a counter that stops when the program finds a byte different from the last one. After that, it prints the counter into the output file, prints the byte that stopped repeating, resets the counter and start counting again with the new byte it's reading now. This process will go on until calling feof (which returns 1 when the pointer to file is at the End of File) returns 1 and it stops.
You see, one of the things we have to print in the output file for compressing is the amount of bytes in the file after the header (header being a group of bytes at the start that write P1 if PBM and RLE if RLEI, then 4 bytes with the height and weight of the file) with a variable we'll call N. The only way I got to do this was counting every print in the output and then doing a Rewind IF the input file was read only once, so it goes back to the beginning and does everything again but now we got an N we can print after the header of the output file.
Decompressing is kind of like the opposite, you need to read the counter in the input file, then the next byte of the input file will be printed counter-times in the output file, and then read the next counter and so on.
There are a lot of stuff that make no sense (it's assembler, what did you expect?). One of the requirements was using 2 bytes for the counter, and that was a pain, I had to understand how sarl and sall work, and that's hard to find anywhere. In the end they move bytes in variables (kind of like moving to the side, sarl to the right, sall to the left, but when you have to read 2 bytes and make them work as 1 variable you have to use 2 variables and add them together into one variable).
Also, the program can't process a file with an N bigger than 65535, before this limit, it would split vertically any image bigger than this.
You can look what's on a RLEI and on a PBM with the hexdump command on linux, it goes like "hexdump -C thing.pbm" or "hexdump -C thing.rle"
That's all for now, if you have any questions ask right away.
Program (it's a .s file): https://mega.nz/#!aFQE2IyD!vnOd565pmTtvcWCF6oradEazHVlwU-2bRrsTVm0v9sQ
PBMs, image to pbm converter and PBM viewer: https://mega.nz/#F!DFQ13ZYY!hM1t9GncFX-jmlghpkfd6g
You can read more into PBMs here, and find more user friendly PBM viewers: https://www.lifewire.com/pbm-file-2622169
I enjoy your post. thanks
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You're welcome!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit