Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
i was reading about FPGA stuff and got so lost heh... i think i can make one with a PIC or ARM if i knew how to decode JPEGs and stuff heh.. i can do BMP so it wouldnt be that hard with that but JPEG is so confusing... Quantum crap!!
/* Basic RLE Compression
*
* Read the file, write compressed as frequency of each byte in sucession
* I.E
*
* 2, 4, 4, 1, 1, 1, 1, 5, 5, 5 compresses to:
* 1, 2, 2, 4, 4, 1, 3, 5 (1 two, 2 fours, 4 ones, 3 fives)
*
* Returns the saved fraction (* 100 = % compression)
*/
float compress(const char *fname, const char *cname)
{
fstream file; // original file
fstream compressed; // compressed file
char character; // read character
char next_character; // last character read
int fsize = 0; // file size
int frequency = 1; // unique byte values
int write_pos = 0;
file.open(fname, ios::in | ios::ate | ios::binary);
compressed.open(cname, ios::out | ios::trunc | ios::binary);
fsize = file.tellg();
for(int i = 0; i < fsize; i++)
{
file.seekg(i, ios::beg); // safety net
file.read((char*)&character, sizeof(char)); // get current character
next_character = file.peek();
if(next_character != character)
{
compressed.seekp(write_pos, ios::beg);
compressed.write((char*)&frequency, sizeof(char));
compressed.seekp(write_pos + 1, ios::beg);
compressed.write((char*)&character, sizeof(char));
write_pos += 2;
frequency = 0;
}
frequency++;
}
file.close();
compressed.close();
return (write_pos / float(fsize));
}
void decompress(const char *fname, const char *uname)
{
fstream file;
fstream ufile;
char character;
int frequency = 0;
int fsize = 0;
int write_pos = 0;
file.open(fname, ios::ate | ios::in | ios::binary);
ufile.open(uname, ios::trunc | ios::out | ios::binary);
fsize = file.tellg();
for(int i = 0; i < fsize; i += 2)
{
file.seekg(i, ios::beg);
file.read((char*)&frequency, sizeof(char));
file.seekg(i + 1, ios::beg);
file.read((char*)&character, sizeof(char));
for(int j = 0; j < frequency; j++)
{
ufile.seekp(write_pos, ios::beg);
ufile.write((char*)&character, sizeof(char));
write_pos++;
}
}
file.close();
ufile.close();
}
/* any credit to myself if you find this useful would be extremely welcolme
* as I do spend a LOT of time ensuring that code works and is useful ect...
* before I consider posting/releasing it! :) Hope you find this useful
* took a bit of time to figure out. Any comments / suggestions feel
* free to add in below! 1o0oBhP
*/
// ps this method works well on low detail bitmaps and repeated chars!
Back when I was a graphics programmer for dos applications I used to use RLE formats, they can be pretty good for 2 colour things like icons and logos that have repeated bit strings of the same colour pixel.
The good side is they are extremely easy to compress and decompress, you just replace a sequence of pixels (say 1-31 pixels) with a command like Cxxxxx where C is the bit colour and xxxxx is from 1 to 31 pixels. The pixel strings wrap from right to left sides of the icon.
It can be expanded for 16 colour and 256 colour icons, and you can even turn the RLE on/off and use it for borders etc and use 1 byte/pixel for the details. I think the original .PCX format allowed for some pixel data and some RLE data combined.
When I had my Amiga 4000/Video toaster 4000 it mainly used portable network graphics, png. A format windows also uses now for lossless compression.
heh i might just go back to the old way ... make a program for windows that decompresses the image and makes it into a format i can read faster. This will allow me to load images super fast.