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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 return false; | 54 return false; |
55 | 55 |
56 uint8_t* input = (uint8_t*)src->getMemoryBase(); | 56 uint8_t* input = (uint8_t*)src->getMemoryBase(); |
57 size_t inputLength = src->getLength(); | 57 size_t inputLength = src->getLength(); |
58 if (input == NULL || inputLength == 0) { | 58 if (input == NULL || inputLength == 0) { |
59 input = NULL; | 59 input = NULL; |
60 flateData.next_in = inputBuffer; | 60 flateData.next_in = inputBuffer; |
61 flateData.avail_in = 0; | 61 flateData.avail_in = 0; |
62 } else { | 62 } else { |
63 flateData.next_in = input; | 63 flateData.next_in = input; |
64 flateData.avail_in = inputLength; | 64 flateData.avail_in = SkToUInt(inputLength); |
65 } | 65 } |
66 | 66 |
67 rc = Z_OK; | 67 rc = Z_OK; |
68 while (true) { | 68 while (true) { |
69 if (flateData.avail_out < kBufferSize) { | 69 if (flateData.avail_out < kBufferSize) { |
70 if (!dst->write(outputBuffer, kBufferSize - flateData.avail_out)) { | 70 if (!dst->write(outputBuffer, kBufferSize - flateData.avail_out)) { |
71 rc = Z_BUF_ERROR; | 71 rc = Z_BUF_ERROR; |
72 break; | 72 break; |
73 } | 73 } |
74 flateData.next_out = outputBuffer; | 74 flateData.next_out = outputBuffer; |
75 flateData.avail_out = kBufferSize; | 75 flateData.avail_out = kBufferSize; |
76 } | 76 } |
77 if (rc != Z_OK) | 77 if (rc != Z_OK) |
78 break; | 78 break; |
79 if (flateData.avail_in == 0) { | 79 if (flateData.avail_in == 0) { |
80 if (input != NULL) | 80 if (input != NULL) |
81 break; | 81 break; |
82 size_t read = src->read(&inputBuffer, kBufferSize); | 82 size_t read = src->read(&inputBuffer, kBufferSize); |
83 if (read == 0) | 83 if (read == 0) |
84 break; | 84 break; |
85 flateData.next_in = inputBuffer; | 85 flateData.next_in = inputBuffer; |
86 flateData.avail_in = read; | 86 flateData.avail_in = SkToUInt(read); |
87 } | 87 } |
88 if (compress) | 88 if (compress) |
89 rc = deflate(&flateData, Z_NO_FLUSH); | 89 rc = deflate(&flateData, Z_NO_FLUSH); |
90 else | 90 else |
91 rc = inflate(&flateData, Z_NO_FLUSH); | 91 rc = inflate(&flateData, Z_NO_FLUSH); |
92 } | 92 } |
93 while (rc == Z_OK) { | 93 while (rc == Z_OK) { |
94 if (compress) | 94 if (compress) |
95 rc = deflate(&flateData, Z_FINISH); | 95 rc = deflate(&flateData, Z_FINISH); |
96 else | 96 else |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 131 } |
132 return false; | 132 return false; |
133 } | 133 } |
134 | 134 |
135 // static | 135 // static |
136 bool SkFlate::Inflate(SkStream* src, SkWStream* dst) { | 136 bool SkFlate::Inflate(SkStream* src, SkWStream* dst) { |
137 return doFlate(false, src, dst); | 137 return doFlate(false, src, dst); |
138 } | 138 } |
139 | 139 |
140 #endif | 140 #endif |
OLD | NEW |