Adaptive Huffman and Lossless Compression Techniques - Documentation

Click here to load reader

  • date post

    14-May-2015
  • Category

    Software

  • view

    311
  • download

    3

Embed Size (px)

description

The doc discusses Adaptive Huffman for data encryption (by Ismaeel Abu-Abdalla). Adaptive Huffman is used for video encryption to pass it on a stream and synchronously be played in the other end other stream. VLC Player API has been used for this (by Mehdi Zonji). This doc also discusses the implementation of different lossless compression techniques (by me) in multimedia; RLE (compression and decompression for any data type; specific technique is used for images.) RLE Quad Tree compress images according to their color bulks. The engine implements also the lossless techniques based on adaptive dictionaries; i.e. LZ77(for text and images, using windows and lookahead buffers) and LZW (for text and images, using a dictionary). Arithmetic coding algorithm is also implemented (by Hasan Sarhan.)

Transcript of Adaptive Huffman and Lossless Compression Techniques - Documentation

  • 1.4/28/2012 MULTIMEDIA ASSIGNMENT #2 | JAEGER & ZGTR & HASSNOV & POD 2102 LOSSLESS COMPRESSION ENGINE

2. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] Adaptive Hoffman 1 Contents 1Adaptive Hoffman...................................................................................................................3 1.1....................................................................................................................................3 1.1.1.....................................................................................................................................3 1.1.1....................................................................................................................3 1.1.3..............................................................................................................................3 1.1.1......................................................................................................................3 1.1.....................................................................................................................3 1.3........................................................................................................................................3 2.......................................................................................................1 1.1VLC Player:................................................................................................................5 3..................................................................................................................6 ..................................................................................................................................................6 3.1RLE(RLEBasic)......................................................................................................7 3.1.1........................................................................................................................7 3.1.2....................................................................................................8 3.1Method1RLE...................................................................................................................9 3.2.1.....................................................................................................................9 3.2.2...............................................................................................................11 3.3Method2RLE.................................................................................................................11 3.3.1.......................................................................................................11 3.3.2..................................................................................................................11 3.1QuadTreeRLE................................................................................................................11 3.4.1.......................................................................................................................11 3.4.2..................................................................................................................13 3.5Adaptive Dictionary.......................................13 3.5.1LZ77........................................................................................................................13 Window....................................................................................................................................13 Buffer.....................................................................................................................11 Buffer..............................................................................................................................11 3.5.1LZW........................................................................................................................15 3.6Arithmetic coding.........................................................................................................17 1().........................................................................................................18 3. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] Adaptive Hoffman 2 5) (......................................................................................................11 4. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] Adaptive Hoffman 3 1Adaptive Hoffman Adaptive Huffman . 1.1 - : 1.1.1 1.1.1 1 ( New. ) 1.1.1 ( Huffman Tree ) ) ( . 1.1.1 ) ( . 1.1 . 1.1 511 156 5. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] 4 . ( 156 )Dictionary . 1 Decoder , , . Components - - VLC Player . . , , . VLC Player , ( , ) , VLC Player c++ dotnet P/Invoke [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] public static extern void libvlc_media_player_play(IntPtr player, ref libvlc_exception_t ex); 6. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] 5 DllImport . extern . : 1.1 VLC Player: 1. Instance VLC libvlc_new 1. media libvlc_media_new 3.( player ) libvlc_media_player_new_from_media 4. libvlc_media_player_play Libvlc_media_player_stop:. Libvlc_media_player_pause:. Libvlc_media_player_get_position: [0,1] Libvlc_media_player_set_position: Libvlc_media_player_set_drawable: 7. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] 6 1 (Lossless Compression) . ( Encode/Decode) static stream stream. 8. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] 7 1.1RLE( RLEBasic) 8 8. RLEDataUnit: 1.1.1 private static Stream EncodeStream(Stream streamOfIds) { Stream compressedStream; Stream miniCompressedStream; flagStr = ("00000000"); int counterFlag = 0; for (int i = 0; i < streamOfIds.Count; i++) { counterFlag++; if (ShouldInsertFlag(counterFlag)) { compressedStream.AddRange(flagStr); compressedStream.AddRange(miniCompressedStream); counterFlag = 1; flagStr = ("00000000"); } DataUnit dataUnit = CatchNextTokenEncode(streamOfIds, i); if (dataUnit.RepeatCounter > 1) { miniCompressedStream.Add(dataUnit.RepeatCounter); flagStr[counterFlag] = '1'; i += dataUnit.RepeatCounter - 1; } miniCompressedStream.Add(dataUnit.Id); } return compressedStream; } DataUnit { byte Id; int RepeatCounter; } 9. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] 8 1.1.1 private static Stream Decode (Stream OfIds) { Stream original; string currentFlagStr = ; int counterFlag = 0; for (int i = 0; i < OfIds.Count; i++) { if (ShouldRetrieveFlag(counterFlag)) { currentFlagStr = GetString(OfIds, i, 8); counterFlag = 8; i += 7; } else { Stream nextTokenList = CatchNextTokenDecode(OfIds, i, currentFlagStr[8-ounterFlag]); original.AddRange(nextTokenList); if (nextTokenList.Count > 2) { i++; } } counterFlag--; } return original; } 10. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] 9 1.1Method1RLE DataUnits 1.1.1 : public static List> EncodeImage(Bitmap imageToEncode, ref CompressionDataInfo info) { TimeChecker timeChecker = new TimeChecker(); timeChecker.S1(); List> compressedStream = new List>(); List> colorArr = ImageManipulator.GetBitmapList(imageToEncode); for (int i = 0; i < colorArr.Count; i++) { Stream currentRow = colorArr[i].Select(color => color.ToArgb().ToString()).ToList(); List currentRowTokens = TokenizeRow(currentRow); compressedStream.Add(currentRowTokens); } info.EncodingStreamCount = compressedStream.Count; info.TimeEncoding = timeChecker.S2(); return compressedStream; } private static List TokenizeRow(Stream currentRow) { List listToReturn = new List(); for (int i = 0; i < currentRow.Count; i++) { DataUnit dataUnit = RLEBasic.CatchNextTokenEncode(currentRow, i); listToReturn.Add(dataUnit); if (dataUnit.RepeatCounter > 1) { i += dataUnit.RepeatCounter - 1; } } return listToReturn; } 11. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] 10 1.1.1 DataUnits 1.1Method2RLE DataUnits RLE Method1 index . Stream . 1.1.1 ( index Wrapping around lines) public static List EncodeImage(Bitmap imageToEncode, ref CompressionDataInfo info) { TimeChecker timeChecker = new TimeChecker(); timeChecker.S1(); List compressedStream = new List(); List colorArr = RLEMethod2.WrapDataUnitsAroundCorners(ImageManipulator.GetBitmapList(imageToEncode)); List currentRow = colorArr.Select(color => color.ToArgb().ToString()).ToList(); List currentRowTokens = TokenizeRow(currentRow); compressedStream.AddRange(currentRowTokens); info.EncodingStreamCount = compressedStream.Count; info.TimeEncoding = timeChecker.S2(); return compressedStream; } 12. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] 11 1.1.1 DataUnitStream Stream ( .Decoder .) 1.1QuadTreeRLE Block . : private static List WrapDataUnitsAroundCorners(List> listOfDataUnits) { List listOfWrappedUnits = new List(); bool isLineEven = true; for (int i = 0; i < listOfDataUnits.Count; i++) { if (isLineEven) { listOfWrappedUnits.AddRange(listOfDataUnits[i]); isLineEven = false; } else { for (int j = listOfDataUnits[i].Count - 1; j >= 0; j--) { listOfWrappedUnits.Add(listOfDataUnits[i][j]); } isLineEven = true; } } return listOfWrappedUnits; } RLETreeNode { RLETreeNode[] _childs; Color _color; bool _isArea; int _i; int _j; int _subArrDim; int _level; Area _area; } 13. April 28, 2012 [LOSSLESS COMPRESSION ENGINE] 12 . 1.1.1