1
2/*
3 * Copyright 2010 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef SkFlate_DEFINED
11#define SkFlate_DEFINED
12
13#include "SkTypes.h"
14
15#include "SkStream.h"
16class SkData;
17
18/** \class SkFlate
19    A class to provide access to the flate compression algorithm.
20*/
21class SkFlate {
22public:
23    /**
24     *  Use the flate compression algorithm to compress the data in src,
25     *  putting the result into dst.  Returns false if an error occurs.
26     */
27    static bool Deflate(SkStream* src, SkWStream* dst);
28
29    /**
30     *  Use the flate compression algorithm to compress the data in src,
31     *  putting the result into dst.  Returns false if an error occurs.
32     */
33    static bool Deflate(const void* src, size_t len, SkWStream* dst);
34
35    /**
36     *  Use the flate compression algorithm to compress the data,
37     *  putting the result into dst.  Returns false if an error occurs.
38     */
39    static bool Deflate(const SkData*, SkWStream* dst);
40
41    /** Use the flate compression algorithm to decompress the data in src,
42        putting the result into dst.  Returns false if an error occurs.
43     */
44    static bool Inflate(SkStream* src, SkWStream* dst);
45};
46
47/**
48  * Wrap a stream in this class to compress the information written to
49  * this stream using the Deflate algorithm.  Uses Zlib's
50  * Z_DEFAULT_COMPRESSION level.
51  *
52  * See http://en.wikipedia.org/wiki/DEFLATE
53  */
54class SkDeflateWStream : public SkWStream {
55public:
56    /** Does not take ownership of the stream. */
57    SkDeflateWStream(SkWStream*);
58
59    /** The destructor calls finalize(). */
60    ~SkDeflateWStream();
61
62    /** Write the end of the compressed stream.  All subsequent calls to
63        write() will fail. Subsequent calls to finalize() do nothing. */
64    void finalize();
65
66    // The SkWStream interface:
67    bool write(const void*, size_t) override;
68    size_t bytesWritten() const override;
69
70private:
71    struct Impl;
72    SkAutoTDelete<Impl> fImpl;
73};
74
75#endif  // SkFlate_DEFINED
76