亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cpipedeflate.cpp

?? 研讀AxCrypt對加解密的處理方法
?? CPP
字號:
/*! \file
    \brief Implementation of AxPipe::Stock::CPipeDeflate

    @(#) $Id$

    AxPipe - Binary Stream Framework

    Copyright (C) 2005 Svante Seleborg/Axon Data, All rights reserved.

    This program is free software; you can redistribute it and/or modify it under the terms
    of the GNU General Public License as published by the Free Software Foundation;
    either version 2 of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along with this program;
    if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
    Boston, MA 02111-1307 USA

    The author may be reached at mailto:axpipe@axondata.se and http://axpipe.sourceforge.net

    Why is this framework released as GPL and not LGPL? See http://www.gnu.org/philosophy/why-not-lgpl.html

----
\verbatim
    E-mail                          YYYY-MM-DD              Reason
    axpipe@axantum.com              2005-11-04              Initial
\endverbatim
*/
#include "stdafx.h"
#include "CPipeDeflate.h"
#include "AxAssert.h"
#define AXLIB_ASSERT_FILE "CPipeDeflate.cpp"

// Can't use this for convenient notation below:
// using AxPipe::Stock::CPipeInflate;
// because the Doxygen get's confused.

namespace AxPipe {
    namespace Stock {
        static voidpf zalloc OF((voidpf opaque, uInt items, uInt size)) {
            // The semantics of zalloc are a bit unclear, so we always zero the memory...
            return memset(new unsigned char[items * size], 0, items * size);
        }

        static void zfree OF((voidpf opaque, voidpf address)) {
            delete[] static_cast<unsigned char *>(address);
        }

        /// \brief Initialize member variables
        CPipeDeflate::CPipeDeflate() {
            m_cbChunkSize = 0;
            m_cbFlushInterval = 0;
            m_pOutSeg = NULL;
            m_cbIn = 0;
            m_cbOut = 0;
            ZeroMemory(&m_Zstream, sizeof m_Zstream);
        }

        ///< \brief Initialize the flush interval
        /// \param cbChunkSize The size we output in. Collect this much before outputting.
        /// \param cbFlushInterval The frequence with which we make resync possible at decompression time. 0 means never.
        CPipeDeflate *CPipeDeflate::Init(int nSaveRatioForCompress, size_t cbChunkSize, size_t cbFlushInterval) {
            m_nSaveRatioForCompress = nSaveRatioForCompress;
            m_cbChunkSize = cbChunkSize;
            m_cbFlushInterval = cbFlushInterval;
            return this;
        }

        /// Clean up if necessary, should only need
        /// work to be done on error.
        CPipeDeflate::~CPipeDeflate() {
            if (m_pOutSeg) {
                m_pOutSeg->Release();
            }
        }

        /// Private helper to send the current segment onwards. m_pOutSeg is
        /// always NULL at return.
        void
        CPipeDeflate::SendOut() {
            if (m_pOutSeg) {
                // Update statistics
                m_cbOut += m_Zstream.total_out;
                m_Zstream.total_out = 0;

                m_pOutSeg->Len(m_pOutSeg->Len() - m_Zstream.avail_out);
                Pump(m_pOutSeg);
                m_pOutSeg = NULL;
            }
        }

        /// Allocate a new segment to deflate to, and update the z_stream structure accordingly
        void
        CPipeDeflate::AllocNew() {
            // Get a new segment, either of the chunk size, or the available in plus 6 (see zlib docs)
            m_pOutSeg = new AxPipe::CSeg(m_cbChunkSize ? m_cbChunkSize : (m_Zstream.avail_in/2 + 6));
            ASSPTR(m_pOutSeg);

            m_Zstream.next_out = m_pOutSeg->PtrWr();
            m_Zstream.avail_out = static_cast<UINT>(m_pOutSeg->Size());
        }

        /// Initialize the z_stream structure, including memory allocation functions
        /// \param pZstream Pointer to a z_stream structure
        void
        CPipeDeflate::InitZstream(z_stream *pZstream) {
            memset(pZstream, 0, sizeof *pZstream);
            pZstream->zalloc = zalloc;      // Use our custom alloc()
            pZstream->zfree = zfree;        // Use our custom free()

            if (deflateInit(pZstream, Z_DEFAULT_COMPRESSION) != Z_OK) {
                SetError(ERROR_CODE_STOCK, _T("ZLIB initialization error"));
            }
        }

        longlong CPipeDeflate::GetOutputSize() {
            return m_cbOut;
        }

        longlong CPipeDeflate::GetInputSize() {
            return m_cbIn;
        }

        int CPipeDeflate::TryDeflateLoop(AxPipe::CSeg *pSeg, z_stream *pZstream) {
            int iZerror;
            do {
                // We now have updated available input, so we call deflate and check the result...
                iZerror = deflate(pZstream, Z_FINISH);
                switch (iZerror) {
                    case Z_OK:
                        // re-use the buffer - we're not really interested in the data as such
                        pZstream->next_out = const_cast<unsigned char *>(pSeg->PtrRd());
                        pZstream->avail_out = static_cast<uInt>(pSeg->Len());
                        break;
                    case Z_STREAM_END:
                        break;
                    case Z_BUF_ERROR:
                    case Z_STREAM_ERROR:
                    default:
                        SetError(ERROR_CODE_STOCK, _T("ZLIB sequence error in CPipeDeflate::TryDeflate()"));
                        return iZerror;
                }
            } while (iZerror != Z_STREAM_END);
            return iZerror;
        }

        /// Try deflation of a memory buffer and return the resulting size
        /// \param p Pointer to data to try to deflate
        /// \param cb The number of bytes in the data buffer
        /// \return The total number of bytes necessary, including overhead
        size_t
        CPipeDeflate::TryDeflate(const void *p, size_t cb) {
            z_stream Zstream;
            InitZstream(&Zstream);

            // Allocate a reasonable buffer, at least 6 bytes large (to make room for header)
            AxPipe::CSeg *pSeg = new AxPipe::CSeg(cb/2+6);
            Zstream.next_in = const_cast<unsigned char *>(static_cast<const unsigned char *>(p));
            Zstream.avail_in = static_cast<uInt>(cb);
            Zstream.next_out = const_cast<unsigned char *>(pSeg->PtrRd());
            Zstream.avail_out = static_cast<uInt>(pSeg->Len());

            int iZerror = TryDeflateLoop(pSeg, &Zstream);
            pSeg->Release();

            // Clean up memory allocations etc
            if (deflateEnd(&Zstream) != Z_OK) {
                SetError(ERROR_CODE_DERIVED, _T("ZLIB error in deflateEnd error"));
                return 0;
            }

            if (iZerror != Z_STREAM_END) {
                return 0;
            }
            return Zstream.total_out;
        }

        bool
        CPipeDeflate::IsDeflatable(AxPipe::CSeg *pSeg, int nSaveRatioForCompress) {
            size_t nDeflatedForPercent = TryDeflate(pSeg->PtrRd(), pSeg->Len());
            size_t nOriginalForPercent = pSeg->Len();
            if (nDeflatedForPercent < (~size_t(0))/size_t(100)) {
                nDeflatedForPercent *= 100;
            } else {
                nOriginalForPercent /= 100;
                if (nOriginalForPercent == 0) {
                    // Avoid division by zero
                    nOriginalForPercent = 1;
                }
            }
            int nSaveRatio = 100 - static_cast<int>(nDeflatedForPercent/nOriginalForPercent);
            if (nSaveRatio < 0) {
                nSaveRatio = 0;
            }
            return nSaveRatio >= m_nSaveRatioForCompress;
        }

        bool 
        CPipeDeflate::IsDeflating() {
            return m_fDeflate;
        }

        /// Initialize zlib for this deflation.
        /// \return true to continue cascading of Open()
        bool
        CPipeDeflate::OutOpen() {
            bool fReturn = CPipe::OutOpen();        // Open base first, like constructor
            m_cbOut = 0;                            // Total output bytes counter
            m_cbIn = 0;                             // Total input bytes counter
            m_cbRemainBeforeFlush = 0;
            m_fDeflate = true;                      // Default is to deflate
            InitZstream(&m_Zstream);                // Since we're assuming we're actually to deflate...
            AllocNew();
            ASSPTR(m_pOutSeg);

            return fReturn;                         // Return the saved return code.
        }

        /// Compress output as it arrives. We also produce Z_FULL_FLUSH periodically to
        /// ensure that there is a certain redundancy. We always consume all data that is
        /// input, but it may be sent onwards in multiple segments.
        /// \param pSeg A segment with compressed data, and no trailing if last
        void
        CPipeDeflate::Out(AxPipe::CSeg *pSeg) {
            // If we're asked to try before compression, test once
            if (m_nSaveRatioForCompress) {
                m_fDeflate = IsDeflatable(pSeg, m_nSaveRatioForCompress);
                m_nSaveRatioForCompress = 0;
            }

            // If we're not deflating, just pass the segment onwards.
            if (!m_fDeflate) {
                m_cbIn = m_cbOut += pSeg->Len();
                Pump(pSeg);
                return;
            }

            size_t cb = pSeg->Len();
            unsigned char *p = const_cast<unsigned char *>(pSeg->PtrRd());
            while (cb) {
                m_Zstream.next_in = p;
                size_t cbThisCall = cb;
                if (m_cbFlushInterval) {
                    if (m_cbRemainBeforeFlush == 0) {
                        m_cbRemainBeforeFlush = m_cbFlushInterval;
                    }
                    cbThisCall = cb > m_cbRemainBeforeFlush ? m_cbRemainBeforeFlush : cb;
                    m_cbRemainBeforeFlush -= cbThisCall;
                }

                // The amount to consume is determined by how much is available, and the flush interval
                m_Zstream.avail_in = static_cast<uInt>(cbThisCall);
                p += cbThisCall;
                cb -= cbThisCall;

                while (m_Zstream.avail_in) {
                    do {
                        if (m_Zstream.avail_out == 0) {
                            SendOut();
                            AllocNew();
                        }

                        // We now have updated available input, so we call deflate and check the result...
                        int iZerror = deflate(&m_Zstream, (m_cbFlushInterval && (m_cbRemainBeforeFlush == 0)) ? Z_FULL_FLUSH : 0);
                        switch (iZerror) {
                            case Z_OK:
                                break;
                            case Z_BUF_ERROR:
                            case Z_STREAM_END:
                            case Z_STREAM_ERROR:
                            default:
                                SetError(ERROR_CODE_STOCK, _T("ZLIB sequence error in CPipeDeflate::Out()"));
                                return;
                        }
                    } while (m_Zstream.avail_out == 0);
                    m_cbIn += m_Zstream.total_in;
                    m_Zstream.total_in = 0;
                }
            }
        }

        /// Flush all data and end the deflation run.
        /// \return true to cascade the closing of the stream
        bool
        CPipeDeflate::OutClose() {
            if (!GetErrorCode() && m_fDeflate) {
                int iZerror;
                do {
                    iZerror = deflate(&m_Zstream, Z_FINISH);
                    switch (iZerror) {
                        case Z_OK:
                            SendOut();
                            AllocNew();
                            break;
                        case Z_STREAM_END:
                            break;
                        case Z_BUF_ERROR:
                        case Z_STREAM_ERROR:
                        default:
                            SetError(ERROR_CODE_STOCK, _T("ZLIB sequence error in CPipeDeflate::OutClose()"));
                            return false;
                    }
                } while (iZerror != Z_STREAM_END);

                // Final output
                SendOut();
            }

            // Clean up memory allocations etc
            if (deflateEnd(&m_Zstream) != Z_OK) {
                SetError(ERROR_CODE_DERIVED, _T("ZLIB error in deflateEnd error"));
            }

            return base::OutClose();
        }
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区欧美一区| 激情综合一区二区三区| 国产suv精品一区二区三区| 欧美一级欧美一级在线播放| 亚洲欧美日韩电影| 波多野结衣中文字幕一区| 久久久久国产精品人| 国产一区二区三区免费看| 欧美丰满美乳xxx高潮www| 五月天中文字幕一区二区| 精品视频一区 二区 三区| 亚洲综合免费观看高清在线观看| 99久久久国产精品| 亚洲精品中文字幕乱码三区| 色综合久久综合网欧美综合网| 国产精品天干天干在观线| 日本强好片久久久久久aaa| 欧美日韩一区 二区 三区 久久精品 | 国精产品一区一区三区mba桃花 | 亚洲国产日产av| 在线亚洲人成电影网站色www| 日韩一区日韩二区| 91片黄在线观看| 一区二区在线看| 欧美日韩精品一区视频| 日韩成人免费看| 日韩一本二本av| 国产伦精品一区二区三区免费迷 | 亚洲一二三四久久| 欧美久久一二区| 美美哒免费高清在线观看视频一区二区| 日韩亚洲欧美一区| 亚洲一区二区在线视频| 欧美男同性恋视频网站| 麻豆91在线播放免费| 欧美本精品男人aⅴ天堂| 日本成人中文字幕在线视频| 久久综合丝袜日本网| av在线综合网| 亚洲天堂久久久久久久| 欧美日韩国产一区| 午夜精品成人在线| 91精品国产手机| 国模冰冰炮一区二区| 亚洲欧美日韩国产另类专区| 欧美丰满嫩嫩电影| 成人av影视在线观看| 亚洲狠狠爱一区二区三区| 精品伦理精品一区| 91猫先生在线| 激情小说欧美图片| 亚洲日韩欧美一区二区在线| 色天使久久综合网天天| 精品一区二区三区免费视频| 亚洲男同1069视频| 精品99999| 欧美丝袜丝nylons| 床上的激情91.| 蜜桃一区二区三区四区| 一区二区三区不卡在线观看| 日韩三级视频在线看| 色999日韩国产欧美一区二区| 九一久久久久久| 亚洲国产成人av好男人在线观看| 久久亚洲影视婷婷| 欧美日高清视频| 99re这里只有精品首页| 麻豆精品国产传媒mv男同| 亚洲综合丝袜美腿| 精品国产凹凸成av人导航| 欧美日韩精品一区视频| 99久久综合狠狠综合久久| 黄色日韩三级电影| 日韩电影在线观看电影| 亚洲综合色自拍一区| 综合精品久久久| 久久综合久久综合九色| 欧美中文字幕一区| 狠狠色丁香九九婷婷综合五月| 亚洲va欧美va人人爽| 亚洲欧美激情一区二区| 国产精品国产三级国产普通话蜜臀 | 国产精品国产自产拍在线| 久久综合九色综合97婷婷女人| 欧美精品免费视频| 成人高清伦理免费影院在线观看| 亚洲国产一二三| 亚洲一区二区三区中文字幕| 亚洲免费电影在线| 亚洲欧美日韩在线| 亚洲人一二三区| 亚洲欧洲精品成人久久奇米网| 日韩一级免费一区| 欧美久久久久久久久久| 337p亚洲精品色噜噜狠狠| 欧美日韩中文一区| 欧美蜜桃一区二区三区| 欧美日韩国产123区| 欧美剧情电影在线观看完整版免费励志电影| 91首页免费视频| 色综合久久综合网欧美综合网| hitomi一区二区三区精品| 成人激情开心网| av一区二区不卡| 91免费国产在线| 成人av动漫网站| 国产露脸91国语对白| 成人精品视频一区二区三区| 国产 日韩 欧美大片| www.欧美色图| 日本精品一区二区三区高清| 欧美体内she精高潮| 欧美日韩免费电影| 日韩精品一区二区三区在线| 26uuu国产一区二区三区| 欧美国产97人人爽人人喊| 国产精品麻豆一区二区 | 在线看国产一区二区| 欧美午夜精品一区二区三区| 欧美高清视频不卡网| 日韩欧美久久一区| 欧美日韩精品一区二区三区| 欧美在线影院一区二区| 日韩一级视频免费观看在线| 久久影院视频免费| 国产精品初高中害羞小美女文| 欧美激情综合在线| 亚洲国产成人av好男人在线观看| 日本特黄久久久高潮| 成人网男人的天堂| 精品视频全国免费看| 欧美人与禽zozo性伦| 欧美精品久久久久久久久老牛影院| 不卡高清视频专区| 成人免费的视频| 欧美日韩色综合| 国产精品久久久久影院色老大| 日韩激情在线观看| 91成人看片片| 久久精品亚洲精品国产欧美kt∨| 最新成人av在线| 伦理电影国产精品| av一二三不卡影片| 久久久久久久久伊人| 亚洲成av人片www| 99久久精品国产一区| 日韩一区二区电影在线| 午夜激情久久久| 97久久久精品综合88久久| 日韩午夜三级在线| 亚洲国产精品天堂| 在线观看网站黄不卡| 中文字幕av不卡| 久久爱www久久做| 欧美午夜电影一区| 久久久国产精华| 国产精品一线二线三线| 91精品国产欧美一区二区成人| 最新中文字幕一区二区三区| 激情综合网av| 精品日韩99亚洲| 美国十次综合导航| 欧美老女人第四色| 亚洲一级片在线观看| 欧美日韩久久不卡| 亚洲一区二区三区中文字幕在线| 成人高清视频在线| 久久久久久久综合日本| 国产精品一线二线三线| 精品国产乱码久久久久久浪潮 | 亚洲免费观看在线观看| 韩国三级中文字幕hd久久精品| 欧美日韩免费不卡视频一区二区三区| 中文字幕一区二区不卡| 成人免费观看av| 国产欧美日本一区二区三区| www.视频一区| 日韩美女视频19| 99久久99精品久久久久久| 制服丝袜在线91| 精品一区二区三区在线播放视频| 日韩三级视频中文字幕| 日韩精品亚洲一区二区三区免费| 精品视频1区2区| 精品一区二区日韩| 精品国产网站在线观看| 韩国女主播一区| 国产日韩欧美激情| 91欧美激情一区二区三区成人| 亚洲视频一二三| 91天堂素人约啪| 中文乱码免费一区二区| 99热国产精品| 亚洲一区二区三区四区五区黄| 色综合久久久久综合体桃花网| 国产精品欧美极品| 欧美日韩国产成人在线免费| 日本va欧美va精品| 精品久久久久久久人人人人传媒| 国产91丝袜在线播放九色|