Click to See Complete Forum and Search --> : A compression idea but want it in code


sujitseth
June 30th, 2004, 09:28 AM
HI, i have an idea on how to compress a bitmap but i'm unable to come up with a code for it...it would be of great help if someone could tell me how to go abt it

The ideais as belowthis is the project question,

in a bitmap file information is stored for each pixel on the screen...The depth of the bitmap suggests the umber of bits representing the pixel(for eg.24bit).
Now i need to generate a program where
1)
incase the bit pattern is being repeated again for the next pixel then it wil represent the whole pattern as a 0...every time the patten changes a 1shall be added to the new pattern
for eg if we consider a bitmap having depth of 8bit
then suppose
the data for 2 consecutive pixels is
111000000 11100000
so it shall be represented after the execution of the program as
111100000 0
where the 1 in the first bit pattern indicates the start of of another bit pattern

2)
i've already developed a program that compresses the coding tree that has a high no of zeroes but in case there are more no of 1s than zeroes then the coding tree shall expand so for that i need to develop a algorithm that complements the bit sequence where no of sequence of 1s is high and shall add a bit 1 prior to the sequnce suggesting that the sequence is complemented
for eg
for a bitmap of depth 8bits
a pixel is represented as
11111110 then it should be
1000000001 after execution of the program
where the one sugests that the sequence has been complemented if it is not complemented then there wold be a zero instead of the 1
i need to develop a program to reverse the codes in both the cases too
I looked in many books and spoke to many institutions but nobody is able to help
See if u can do anything abt it

Yves M
July 22nd, 2004, 04:37 PM
If you think about your first encoding technique, you'll see that it is worse than Run Length Encoding (RLE) in many cases. If the images don't contain much repetitions, then the extra 1 bit at the start will make the file bigger by a factor of 9/8 (112.5%). In RLE, you only have to set aside a single bit pattern and if that color did turn up, then you would double the size required for that color, but the rest of the colors don't suffer from that problem. So the increase for RLE would only be about 257/256 (100.3%) if the colors turn up pretty uniformly.

For an image with a lot of repetion, your method would again be worse. Say you have an image which is entirely white. With your method, you would require 8 + (x * y) / 8 bytes, so for an 12x8 image, that's 20 bytes. With RLE, you could encode it as 3 bytes.

If you still want to implement it, then what kind of problems do you have? Do you know how to access individual bits? Or what is the difficulty?