OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCodec.h" | 8 #include "SkCodec.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const { | 101 SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const { |
102 return kWBMP_SkEncodedFormat; | 102 return kWBMP_SkEncodedFormat; |
103 } | 103 } |
104 | 104 |
105 SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, | 105 SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, |
106 void* dst, | 106 void* dst, |
107 size_t rowBytes, | 107 size_t rowBytes, |
108 const Options& options, | 108 const Options& options, |
109 SkPMColor ctable[], | 109 SkPMColor ctable[], |
110 int* ctableCount) { | 110 int* ctableCount, |
| 111 int* incompleteScanlines) { |
111 if (!this->rewindIfNeeded()) { | 112 if (!this->rewindIfNeeded()) { |
112 return kCouldNotRewind; | 113 return kCouldNotRewind; |
113 } | 114 } |
114 if (options.fSubset) { | 115 if (options.fSubset) { |
115 // Subsets are not supported. | 116 // Subsets are not supported. |
116 return kUnimplemented; | 117 return kUnimplemented; |
117 } | 118 } |
118 if (info.dimensions() != this->getInfo().dimensions()) { | 119 if (info.dimensions() != this->getInfo().dimensions()) { |
119 return kInvalidScale; | 120 return kInvalidScale; |
120 } | 121 } |
(...skipping 12 matching lines...) Expand all Loading... |
133 return kInvalidConversion; | 134 return kInvalidConversion; |
134 } | 135 } |
135 | 136 |
136 // Perform the decode | 137 // Perform the decode |
137 SkISize size = info.dimensions(); | 138 SkISize size = info.dimensions(); |
138 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); | 139 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); |
139 void* dstRow = dst; | 140 void* dstRow = dst; |
140 for (int y = 0; y < size.height(); ++y) { | 141 for (int y = 0; y < size.height(); ++y) { |
141 Result rowResult = this->readRow(src.get()); | 142 Result rowResult = this->readRow(src.get()); |
142 if (kSuccess != rowResult) { | 143 if (kSuccess != rowResult) { |
| 144 *incompleteScanlines = size.height() - y; |
143 return rowResult; | 145 return rowResult; |
144 } | 146 } |
145 swizzler->swizzle(dstRow, src.get()); | 147 swizzler->swizzle(dstRow, src.get()); |
146 dstRow = SkTAddOffset<void>(dstRow, rowBytes); | 148 dstRow = SkTAddOffset<void>(dstRow, rowBytes); |
147 } | 149 } |
148 return kSuccess; | 150 return kSuccess; |
149 } | 151 } |
150 | 152 |
151 bool SkWbmpCodec::IsWbmp(SkStream* stream) { | 153 bool SkWbmpCodec::IsWbmp(SkStream* stream) { |
152 return read_header(stream, nullptr); | 154 return read_header(stream, nullptr); |
153 } | 155 } |
154 | 156 |
155 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { | 157 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { |
156 SkAutoTDelete<SkStream> streamDeleter(stream); | 158 SkAutoTDelete<SkStream> streamDeleter(stream); |
157 SkISize size; | 159 SkISize size; |
158 if (!read_header(stream, &size)) { | 160 if (!read_header(stream, &size)) { |
159 return nullptr; | 161 return nullptr; |
160 } | 162 } |
161 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), | 163 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), |
162 kGray_8_SkColorType, kOpaque_SkAlphaType); | 164 kGray_8_SkColorType, kOpaque_SkAlphaType); |
163 return new SkWbmpCodec(info, streamDeleter.detach()); | 165 return new SkWbmpCodec(info, streamDeleter.detach()); |
164 } | 166 } |
165 | 167 |
166 class SkWbmpScanlineDecoder : public SkScanlineDecoder { | 168 class SkWbmpScanlineDecoder : public SkScanlineDecoder { |
167 public: | 169 public: |
168 /* | 170 /* |
169 * Takes ownership of all pointer paramters. | 171 * Takes ownership of all pointer paramters. |
170 */ | 172 */ |
171 SkWbmpScanlineDecoder(SkWbmpCodec* codec) | 173 SkWbmpScanlineDecoder(SkWbmpCodec* codec) |
172 : INHERITED(codec->getInfo()) | 174 : INHERITED(codec, codec->getInfo()) |
173 , fCodec(codec) | 175 , fCodec(codec) |
174 , fColorTable(nullptr) | 176 , fColorTable(nullptr) |
175 , fSwizzler(nullptr) | 177 , fSwizzler(nullptr) |
176 , fSrcBuffer(codec->fSrcRowBytes) | 178 , fSrcBuffer(codec->fSrcRowBytes) |
177 {} | 179 {} |
178 | 180 |
179 SkCodec::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) ove
rride { | 181 uint32_t onGetScanlines(void* dst, int count, size_t dstRowBytes) override { |
180 void* dstRow = dst; | 182 void* dstRow = dst; |
181 for (int y = 0; y < count; ++y) { | 183 for (int y = 0; y < count; ++y) { |
182 SkCodec::Result rowResult = fCodec->readRow(fSrcBuffer.get()); | 184 SkCodec::Result rowResult = fCodec->readRow(fSrcBuffer.get()); |
183 if (SkCodec::kSuccess != rowResult) { | 185 if (SkCodec::kSuccess != rowResult) { |
184 return rowResult; | 186 return y; |
185 } | 187 } |
186 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); | 188 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); |
187 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); | 189 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); |
188 } | 190 } |
189 return SkCodec::kSuccess; | 191 return count; |
190 } | 192 } |
191 | 193 |
192 SkCodec::Result onStart(const SkImageInfo& dstInfo, | 194 SkCodec::Result onStart(const SkImageInfo& dstInfo, |
193 const SkCodec::Options& options, SkPMColor inputColorTable[], | 195 const SkCodec::Options& options, SkPMColor inputColorTable[], |
194 int* inputColorCount) { | 196 int* inputColorCount) { |
195 if (!fCodec->rewindIfNeeded()) { | 197 if (!fCodec->rewindIfNeeded()) { |
196 return SkCodec::kCouldNotRewind; | 198 return SkCodec::kCouldNotRewind; |
197 } | 199 } |
198 if (options.fSubset) { | 200 if (options.fSubset) { |
199 // Subsets are not supported. | 201 // Subsets are not supported. |
(...skipping 25 matching lines...) Expand all Loading... |
225 } | 227 } |
226 | 228 |
227 return SkCodec::kSuccess; | 229 return SkCodec::kSuccess; |
228 } | 230 } |
229 | 231 |
230 SkEncodedFormat onGetEncodedFormat() const { | 232 SkEncodedFormat onGetEncodedFormat() const { |
231 return kWBMP_SkEncodedFormat; | 233 return kWBMP_SkEncodedFormat; |
232 } | 234 } |
233 | 235 |
234 private: | 236 private: |
235 SkAutoTDelete<SkWbmpCodec> fCodec; | 237 SkWbmpCodec* fCodec; // Owned by parent class |
236 SkAutoTUnref<SkColorTable> fColorTable; | 238 SkAutoTUnref<SkColorTable> fColorTable; |
237 SkAutoTDelete<SkSwizzler> fSwizzler; | 239 SkAutoTDelete<SkSwizzler> fSwizzler; |
238 SkAutoTMalloc<uint8_t> fSrcBuffer; | 240 SkAutoTMalloc<uint8_t> fSrcBuffer; |
239 | 241 |
240 typedef SkScanlineDecoder INHERITED; | 242 typedef SkScanlineDecoder INHERITED; |
241 }; | 243 }; |
242 | 244 |
243 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { | 245 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { |
244 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( | 246 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( |
245 SkWbmpCodec::NewFromStream(stream))); | 247 SkWbmpCodec::NewFromStream(stream))); |
246 if (!codec) { | 248 if (!codec) { |
247 return nullptr; | 249 return nullptr; |
248 } | 250 } |
249 | 251 |
250 // Return the new scanline decoder | 252 // Return the new scanline decoder |
251 return new SkWbmpScanlineDecoder(codec.detach()); | 253 return new SkWbmpScanlineDecoder(codec.detach()); |
252 } | 254 } |
OLD | NEW |