I am having trouble with a GIF Decoder that I am writing for vb.net 2003. I am using a 600 x 400 256 color image to test it. It gets about 1/4 way through then reads a end code. Any Idea what I am missing?
I use the routine bellow. I take all the bytes from the image data block and convert them to bits then process them. I have it work fine with a small 10 x 10 image, but it only has 4 colors.
I use the routine bellow. I take all the bytes from the image data block and convert them to bits then process them. I have it work fine with a small 10 x 10 image, but it only has 4 colors.
VB.NET:
Private Function GetIndexes(ByVal arrBits As ArrayList, ByVal MinimumCodeSize As Byte, ByVal ColorTable() As ColorTable) As ArrayList
Dim pbytCount As Byte = MinimumCodeSize + 1
Dim pshrtEndOfCode = CShort((2 ^ MinimumCodeSize) + 1)
Dim pshrtReinit As Short = CShort(2 ^ MinimumCodeSize)
Dim colCodeTree As New CodeIndexCollection 'The Code Tree
Dim code As New CodeIndex 'the current code
Dim CodeLast As CodeIndex 'the last code
Dim pshrtCodeIndex As Short
Dim pintLastRead As Integer = 0 'keep track of bits read
Dim arCodeIndexStream As New ArrayList 'holds the actual color indexes
Dim pintTotalBits As Integer = arrBits.Count - 1
Dim pblnFirstCode As Boolean = True
Do Until pintLastRead = pintTotalBits
pshrtCodeIndex = Me.GetValue(arrBits, pintLastRead, pbytCount - 1)
pintLastRead += pbytCount
If pshrtCodeIndex = pshrtEndOfCode Then 'DONE
Exit Do
ElseIf pshrtCodeIndex = pshrtReinit Then 'ReInit
colCodeTree.Clear()
pbytCount = MinimumCodeSize + 1
colCodeTree = InitCodeTable(ColorTable)
pblnFirstCode = True
GoTo reinit
Else
'process code
'Check for code
Dim findcode As CodeIndex = colCodeTree.FindByIndex(pshrtCodeIndex)
If pblnFirstCode Then
arCodeIndexStream.Add(pshrtCodeIndex)
Dim arVals As New ArrayList
arvals.Add(pshrtCodeIndex)
code = New CodeIndex(pshrtCodeIndex, arvals)
CodeLast = code
pblnFirstCode = False
GoTo reinit
End If
If findcode Is Nothing Then 'no code found
'get first color index of last codeindex
Dim pintLastColorIndex As Integer = CodeLast.Values(0)
Dim arVals As New ArrayList
arVals.AddRange(CodeLast.Values)
arVals.Add(pintLastColorIndex)
code = New CodeIndex(colCodeTree.Count, arVals)
arCodeIndexStream.AddRange(code.Values)
colCodeTree.Add(code)
'get more bits next time?
If code.Index = (2 ^ pbytCount) - 1 Then
pbytCount += 1
End If
CodeLast = code
Else 'Code Found
arCodeIndexStream.AddRange(findcode.Values)
Dim pintNewColorIndex As Integer = findcode.Values(0)
Dim arVals As New ArrayList
arVals.AddRange(CodeLast.Values)
arVals.Add(pintNewColorIndex)
code = New CodeIndex(colCodeTree.Count, arVals)
colCodeTree.Add(code)
'get more bits next time?
If code.Index = (2 ^ pbytCount) - 1 Then
pbytCount += 1
End If
CodeLast = findcode
End If
End If
ReInit:
Loop
Return arCodeIndexStream
End Function