# Thread: GIF Decoder (SZW Compression)

1. ## GIF Decoder (SZW Compression)

I can find the image block in GIF file and the tabular data block it gives me the byte size as 254 after that i must have SZW compressed data(pixel information) where i get 128, the table size is 128 i. th index must fall between 0-127(inclusive), the minimum bit to represent initial character is given 7.

the coded data is like 128,0,3,5,4.........

128 is unexpected i guess...

2. Huh!?

3. ## sorry if i could not make myself clear

SZW coded code is 128,0,3,4,5.....
and the initial representetion of character is of 7 bit...

is it possible to have 128 at the first position?

4. A character is 7bits as per the original ASCII standard yes, the 8th bit was used for parity checking -- no longer the case (I think ) hence the set has been extended & you can use the 8th bit.

Unsigned that means you can represent, (2^8) - 1 = 0 to 255 inclusive (unsigned) and -128 to 127 signed (-2^7 to 2^7 - 1). That's assuming CHAR_BITS = 8

BTW, what is SZW compression!? Do you mean LZW?

Originally Posted by Dr. Dobb's Journal (LZW Fundamentals)
The code that the LZW algorithm outputs can be of any arbitrary length, but it must have more bits in it than a single character. The first 256 codes (when using eight bit characters) are by default assigned to the standard character set. The remaining codes are assigned to strings as the algorithm proceeds. The sample program runs as shown with 12 bit codes. This means codes 0-255 refer to individual bytes, while codes 256-4095 refer to substrings.

5. yes i meant LZW

6. ## again disturbing you

there can be only 128 diffrent characters in the original file but when we use the compression technique we can have any character excluding the initial set of characters.. lets represent like this

original file contains character having represented by 7 bit but what i m getting at 1st postion is 128 which needs 8 bits to represent, my question is any szw coded data may start with any character not belonging to the original set of characters..

I have seen many lzw compressed data, all starts with the original text...
M I Right?

7. Originally Posted by kapil1089thekin
there can be only 128 diffrent characters in the original file but when we use the compression technique we can have any character excluding the initial set of characters.. lets represent like this

original file contains character having represented by 7 bit but what i m getting at 1st postion is 128 which needs 8 bits to represent, my question is any szw coded data may start with any character not belonging to the original set of characters..

I have seen many lzw compressed data, all starts with the original text...
M I Right?
You've acknowledged that you mean LZW, but then said szw again. There is no such thing.

You seem to have described that the LZW compression tree starts with only 0-127 in it and thus the first code contains 7 bits and the next 128 subsequent codes contain 8 bits, then codes of length 9 begin.
It would therefore be impossible to read in a code of 128 for the first value. You're only supposed to read in 7 bits for the first value, and you can't get 128 out of 7 bits, so clearly you are incorrectly reading 8 bits.