-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27ef62e
commit 8c184fe
Showing
4 changed files
with
188 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Codec.Jpeg.Classes; | ||
|
||
internal class HuffmanTable | ||
{ | ||
public byte Id; | ||
|
||
public int[] MinCode { get; set; } | ||
public int[] MaxCode { get; set; } | ||
public int[] ValPtr { get; set; } | ||
public byte[] Values { get; set; } | ||
public Dictionary<int, (int code, int length)> CodeTable { get; set; } | ||
|
||
public HuffmanTable() | ||
{ | ||
MinCode = new int[16]; | ||
MaxCode = new int[16]; | ||
ValPtr = new int[16]; | ||
Values = new byte[256]; | ||
CodeTable = new Dictionary<int, (int code, int length)>(); | ||
} | ||
|
||
public (int code, int length) GetCode(int value) | ||
{ | ||
if (CodeTable.TryGetValue(value, out var codeInfo)) | ||
{ | ||
return codeInfo; | ||
} | ||
return (0, 0); | ||
} | ||
|
||
public int GetCodeLength(int value) | ||
{ | ||
if (CodeTable.TryGetValue(value, out var codeInfo)) | ||
{ | ||
return codeInfo.length; | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.