示例#1
0
文件: CJLRVBF.cs 项目: demonzhq/JLR
            public static byte[] LZSS_ExpandData(byte[] mInput)
            {

                /** Current window position */

                int winPos = 1;

                /** Byte to write to output buffer */

                byte outByte = 0;

                /** Length of the data match found */

                int matchLen = 0;

                /** Position in the window of the data match */

                int matchPos = 0;

                /** Indicator of End Of Stream reached */

                bool eosReached = false;



                //Private Virable

                BitQuery BQ = new BitQuery(mInput);

                List<byte> Result = new List<byte>();

                byte[] LZSS_window = new byte[LZSS_WINDOW_SIZE];

                try
                {
                    while (!eosReached)

                    {

                        /* If next bit is 1, next byte is uncompressed*/

                        if (BQ.GetBit() == 1)

                        {

                            /* Get uncompressed byte */

                            outByte = Convert.ToByte(BQ.GetByte());

                            /* Output byte*/

                            Result.Add(outByte);

                            /* Add byte in window */

                            LZSS_window[winPos] = outByte;

                            /* Increase window position */

                            winPos = (winPos + 1) & (LZSS_WINDOW_SIZE - 1);

                        }

                        /* If next bit is 0, compressed data follows */

                        else

                        {

                            /* Get compressed data as window position of match*/

                            matchPos = BQ.GetBit(LZSS_INDEX_BIT_COUNT);

                            /* If end of stream, exit */

                            if (matchPos == LZSS_END_OF_STREAM)

                            {

                                eosReached = true;

                            }

                            else

                            {

                                /* Get length of string match */

                                matchLen = BQ.GetBit(LZSS_LENGTH_BIT_COUNT);

                                /* Add break even + 1 to get the correct length. Length zero and

                                * the break even value are subtracted from the length during

                                * compression to save space. */

                                matchLen = matchLen + (LZSS_BREAK_EVEN + 1);

                                /* For every byte in match */

                                for (int i = 0; i < matchLen; i++)

                                {

                                    /* Get matching byte from window */

                                    outByte = LZSS_window[(matchPos + i) & (LZSS_WINDOW_SIZE - 1)];

                                    /* Output byte */

                                    Result.Add(outByte);

                                    /* Add matched byte to current window position */

                                    LZSS_window[winPos] = outByte;

                                    /* Increase window position */

                                    winPos = (winPos + 1) & (LZSS_WINDOW_SIZE - 1);

                                }

                            }

                        }

                    }
                }
                catch
                {
                    return null;
                }


                return Result.ToArray<byte>();

            }
示例#2
0
文件: Form1.cs 项目: demonzhq/JLR
        private void WriteCompressFile(byte[] mInput, string File)
        {
            StreamWriter SW = new StreamWriter(File);
            BitQuery BQ = new BitQuery(mInput);
            int Symble = BQ.GetBit();
            while (Symble >= 0)
            {
                if (Symble == 1)
                {
                    SW.Write("1 ");
                    for (int i = 0; i < 8; i++)
                    {
                        SW.Write(BQ.GetBit());
                    }
                    SW.Write("\r\n");
                }
                else
                {
                    SW.Write("0 ");
                    for (int i = 0; i < 10; i++)
                    {
                        SW.Write(BQ.GetBit());
                    }
                    SW.Write(" ");
                    for (int i = 0; i < 4; i++)
                    {
                        SW.Write(BQ.GetBit());
                    }
                    SW.Write("\r\n");
                }

                Symble = BQ.GetBit();
            }
            SW.Close();

        }