OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 The Android Open Source Project | 3 * Copyright 2010 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } | 58 } |
59 | 59 |
60 // Hide all zlib impl details. | 60 // Hide all zlib impl details. |
61 struct SkDeflateWStream::Impl { | 61 struct SkDeflateWStream::Impl { |
62 SkWStream* fOut; | 62 SkWStream* fOut; |
63 unsigned char fInBuffer[SKDEFLATEWSTREAM_INPUT_BUFFER_SIZE]; | 63 unsigned char fInBuffer[SKDEFLATEWSTREAM_INPUT_BUFFER_SIZE]; |
64 size_t fInBufferIndex; | 64 size_t fInBufferIndex; |
65 z_stream fZStream; | 65 z_stream fZStream; |
66 }; | 66 }; |
67 | 67 |
68 SkDeflateWStream::SkDeflateWStream(SkWStream* out) : fImpl(new SkDeflateWStream:
:Impl) { | 68 SkDeflateWStream::SkDeflateWStream(SkWStream* out, |
| 69 int compressionLevel, |
| 70 bool gzip) |
| 71 : fImpl(new SkDeflateWStream::Impl) { |
69 fImpl->fOut = out; | 72 fImpl->fOut = out; |
70 fImpl->fInBufferIndex = 0; | 73 fImpl->fInBufferIndex = 0; |
71 if (!fImpl->fOut) { | 74 if (!fImpl->fOut) { |
72 return; | 75 return; |
73 } | 76 } |
| 77 fImpl->fZStream.next_in = nullptr; |
74 fImpl->fZStream.zalloc = &skia_alloc_func; | 78 fImpl->fZStream.zalloc = &skia_alloc_func; |
75 fImpl->fZStream.zfree = &skia_free_func; | 79 fImpl->fZStream.zfree = &skia_free_func; |
76 fImpl->fZStream.opaque = nullptr; | 80 fImpl->fZStream.opaque = nullptr; |
77 SkDEBUGCODE(int r =) deflateInit(&fImpl->fZStream, Z_DEFAULT_COMPRESSION); | 81 SkASSERT(compressionLevel <= 9 && compressionLevel >= -1); |
| 82 SkDEBUGCODE(int r =) deflateInit2(&fImpl->fZStream, compressionLevel, |
| 83 Z_DEFLATED, gzip ? 0x1F : 0x0F, |
| 84 8, Z_DEFAULT_STRATEGY); |
78 SkASSERT(Z_OK == r); | 85 SkASSERT(Z_OK == r); |
79 } | 86 } |
80 | 87 |
81 SkDeflateWStream::~SkDeflateWStream() { this->finalize(); } | 88 SkDeflateWStream::~SkDeflateWStream() { this->finalize(); } |
82 | 89 |
83 void SkDeflateWStream::finalize() { | 90 void SkDeflateWStream::finalize() { |
84 if (!fImpl->fOut) { | 91 if (!fImpl->fOut) { |
85 return; | 92 return; |
86 } | 93 } |
87 do_deflate(Z_FINISH, &fImpl->fZStream, fImpl->fOut, fImpl->fInBuffer, | 94 do_deflate(Z_FINISH, &fImpl->fZStream, fImpl->fOut, fImpl->fInBuffer, |
(...skipping 22 matching lines...) Expand all Loading... |
110 fImpl->fInBuffer, fImpl->fInBufferIndex); | 117 fImpl->fInBuffer, fImpl->fInBufferIndex); |
111 fImpl->fInBufferIndex = 0; | 118 fImpl->fInBufferIndex = 0; |
112 } | 119 } |
113 } | 120 } |
114 return true; | 121 return true; |
115 } | 122 } |
116 | 123 |
117 size_t SkDeflateWStream::bytesWritten() const { | 124 size_t SkDeflateWStream::bytesWritten() const { |
118 return fImpl->fZStream.total_in + fImpl->fInBufferIndex; | 125 return fImpl->fZStream.total_in + fImpl->fInBufferIndex; |
119 } | 126 } |
OLD | NEW |