aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkFlate.h
blob: 35f18499efe7c8bccfdc4a6793b3b791a2851ca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

/*
 * Copyright 2010 The Android Open Source Project
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#ifndef SkFlate_DEFINED
#define SkFlate_DEFINED

#include "SkTypes.h"

#ifndef Sk_NO_FLATE

#include "SkStream.h"
class SkData;

/** \class SkFlate
    A class to provide access to the flate compression algorithm.
*/
class SkFlate {
public:
    /**
     *  Use the flate compression algorithm to compress the data in src,
     *  putting the result into dst.  Returns false if an error occurs.
     */
    static bool Deflate(SkStream* src, SkWStream* dst);

    /**
     *  Use the flate compression algorithm to compress the data in src,
     *  putting the result into dst.  Returns false if an error occurs.
     */
    static bool Deflate(const void* src, size_t len, SkWStream* dst);

    /**
     *  Use the flate compression algorithm to compress the data,
     *  putting the result into dst.  Returns false if an error occurs.
     */
    static bool Deflate(const SkData*, SkWStream* dst);

    /** Use the flate compression algorithm to decompress the data in src,
        putting the result into dst.  Returns false if an error occurs.
     */
    static bool Inflate(SkStream* src, SkWStream* dst);
};

/**
  * Wrap a stream in this class to compress the information written to
  * this stream using the Deflate algorithm.  Uses Zlib's
  * Z_DEFAULT_COMPRESSION level.
  *
  * See http://en.wikipedia.org/wiki/DEFLATE
  */
class SkDeflateWStream : public SkWStream {
public:
    /** Does not take ownership of the stream. */
    SkDeflateWStream(SkWStream*);

    /** The destructor calls finalize(). */
    ~SkDeflateWStream();

    /** Write the end of the compressed stream.  All subsequent calls to
        write() will fail. Subsequent calls to finalize() do nothing. */
    void finalize();

    // The SkWStream interface:
    bool write(const void*, size_t) override;
    size_t bytesWritten() const override;

private:
    struct Impl;
    SkAutoTDelete<Impl> fImpl;
};

#endif  // SK_NO_FLATE
#endif  // SkFlate_DEFINED