bytes are extracted from the image header. these bytes are then used to create huffman tables.
here are some design options:
read the image bytes from the file one at a time ... decode each byte
or
store all image bytes(in an array), close the file, then decode the image bytes
huffman table data type options:
1. store bits in the huffman lookup table similar to getBits where each temp[n] represents a bit
2. you already have code for most of this one ... use BITS array along with an array with the values(which are ints in the code). a new method is required to looks up the size found in the image data, then look up the corresponding value. this new method returns a bit representation of the value. for example, if the size(in bits) is 3 and the value is 4, then the method returns 100. if the size were 4 then 0100 is returned.
3. store and process 'bits' using StringBuffer() ... don't use String()
4. it might be possible to represent the values as an int. values with a leading bit of '0' would have to be handled separately. most values, however, start with a bit value of '1'. using this approach, the new method would return an int value of 100(one hundred) for size of 3 and a value of 4.
suggestion: you might take a look at the java tutorial and see if there are any 'int to binary' conversion methods.
regardless of the data type for the image data, parsing is done one bit at a time. start with one bit from the file. see if that 'size' is in the huffman 'size' table. repeat until a valid size is found. get another bit and see if there is a valid value anywhere in the huffman 'value' table. continue one bit at a time until a valid value is found. an exception should be thrown if a valid value is not found after 16 bits are grabbed. repeat the size-value parsing until all of the image data is processed.
Edited by bdlt, 24 September 2007 - 12:31 PM.