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 "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
9 #include "SkScaledCodec.h" | 9 #include "SkScaledCodec.h" |
10 #include "SkStream.h" | 10 #include "SkStream.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 SkPMColor ctable[], int* ctableCount)
{ | 181 SkPMColor ctable[], int* ctableCount)
{ |
182 | 182 |
183 if (options.fSubset) { | 183 if (options.fSubset) { |
184 // Subsets are not supported. | 184 // Subsets are not supported. |
185 return kUnimplemented; | 185 return kUnimplemented; |
186 } | 186 } |
187 | 187 |
188 Result result = fScanlineDecoder->start(requestedInfo, &options, ctable, cta
bleCount); | 188 Result result = fScanlineDecoder->start(requestedInfo, &options, ctable, cta
bleCount); |
189 if (kSuccess == result) { | 189 if (kSuccess == result) { |
190 // native decode supported | 190 // native decode supported |
| 191 uint32_t lines; |
191 switch (fScanlineDecoder->getScanlineOrder()) { | 192 switch (fScanlineDecoder->getScanlineOrder()) { |
192 case SkScanlineDecoder::kTopDown_SkScanlineOrder: | 193 case SkScanlineDecoder::kTopDown_SkScanlineOrder: |
193 case SkScanlineDecoder::kBottomUp_SkScanlineOrder: | 194 case SkScanlineDecoder::kBottomUp_SkScanlineOrder: |
194 case SkScanlineDecoder::kNone_SkScanlineOrder: | 195 case SkScanlineDecoder::kNone_SkScanlineOrder: |
195 return fScanlineDecoder->getScanlines(dst, requestedInfo.height(
), rowBytes); | 196 lines = fScanlineDecoder->getScanlines(dst, requestedInfo.height
(), rowBytes); |
| 197 if (lines != requestedInfo.height()) { |
| 198 this->setIncompleteScanlines(requestedInfo.height() - lines)
; |
| 199 return kIncompleteInput; |
| 200 } |
| 201 return kSuccess; |
196 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: { | 202 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: { |
197 for (int y = 0; y < requestedInfo.height(); y++) { | 203 for (int y = 0; y < requestedInfo.height(); y++) { |
198 int dstY = fScanlineDecoder->getY(); | 204 int dstY = fScanlineDecoder->getY(); |
199 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * dstY); | 205 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * dstY); |
200 result = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes)
; | 206 lines = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes); |
201 // FIXME (msarett): Make the SkCodec base class take care of
filling | 207 if (1 != lines) { |
202 // uninitialized pixels so we can return immediately on kInc
ompleteInput. | 208 // TODO (msarett): Can we share this code with SkGifCode
c? |
203 if (kSuccess != result && kIncompleteInput != result) { | 209 const SkImageInfo fillInfo = requestedInfo.makeWH(reques
tedInfo.width(), 1); |
204 return result; | 210 const uint32_t fillValue = this->getFillValue(fillInfo); |
| 211 for (; y < requestedInfo.height(); y++) { |
| 212 int dstY = fScanlineDecoder->getY(y); |
| 213 void* dstRow = SkTAddOffset<void>(dst, rowBytes * ds
tY); |
| 214 SkSwizzler::Fill(dstRow, fillInfo, rowBytes, fillVal
ue, |
| 215 options.fZeroInitialized); |
| 216 } |
| 217 break; |
205 } | 218 } |
206 } | 219 } |
207 return result; | 220 return result; |
208 } | 221 } |
209 } | 222 } |
210 } | 223 } |
211 | 224 |
212 if (kInvalidScale != result) { | 225 if (kInvalidScale != result) { |
213 // no scaling requested | 226 // no scaling requested |
214 return result; | 227 return result; |
(...skipping 14 matching lines...) Expand all Loading... |
229 SkImageInfo info = requestedInfo; | 242 SkImageInfo info = requestedInfo; |
230 // use original height as scanlineDecoder does not support y sampling native
ly | 243 // use original height as scanlineDecoder does not support y sampling native
ly |
231 info = info.makeWH(requestedInfo.width(), srcHeight); | 244 info = info.makeWH(requestedInfo.width(), srcHeight); |
232 | 245 |
233 // update scanlineDecoder with new info | 246 // update scanlineDecoder with new info |
234 result = fScanlineDecoder->start(info, &options, ctable, ctableCount); | 247 result = fScanlineDecoder->start(info, &options, ctable, ctableCount); |
235 if (kSuccess != result) { | 248 if (kSuccess != result) { |
236 return result; | 249 return result; |
237 } | 250 } |
238 | 251 |
| 252 uint32_t lines; |
239 switch(fScanlineDecoder->getScanlineOrder()) { | 253 switch(fScanlineDecoder->getScanlineOrder()) { |
240 case SkScanlineDecoder::kTopDown_SkScanlineOrder: { | 254 case SkScanlineDecoder::kTopDown_SkScanlineOrder: { |
241 result = fScanlineDecoder->skipScanlines(Y0); | 255 lines = fScanlineDecoder->skipScanlines(Y0); |
242 if (kSuccess != result && kIncompleteInput != result) { | 256 if (lines != Y0) { |
243 return result; | 257 this->setIncompleteScanlines(dstHeight); |
| 258 return kIncompleteInput; |
244 } | 259 } |
245 for (int y = 0; y < dstHeight; y++) { | 260 for (int y = 0; y < dstHeight; y++) { |
246 result = fScanlineDecoder->getScanlines(dst, 1, rowBytes); | 261 lines = fScanlineDecoder->getScanlines(dst, 1, rowBytes); |
247 if (kSuccess != result && kIncompleteInput != result) { | 262 if (1 != lines) { |
248 return result; | 263 this->setIncompleteScanlines(dstHeight - y); |
| 264 return kIncompleteInput; |
249 } | 265 } |
250 if (y < dstHeight - 1) { | 266 if (y < dstHeight - 1) { |
251 result = fScanlineDecoder->skipScanlines(sampleY - 1); | 267 lines = fScanlineDecoder->skipScanlines(sampleY - 1); |
252 if (kSuccess != result && kIncompleteInput != result) { | 268 if (sampleY - 1 != lines) { |
253 return result; | 269 this->setIncompleteScanlines(dstHeight - y); |
| 270 return kIncompleteInput; |
254 } | 271 } |
255 } | 272 } |
256 dst = SkTAddOffset<void>(dst, rowBytes); | 273 dst = SkTAddOffset<void>(dst, rowBytes); |
257 } | 274 } |
258 return result; | 275 return kSuccess; |
259 } | 276 } |
260 case SkScanlineDecoder::kBottomUp_SkScanlineOrder: | 277 case SkScanlineDecoder::kBottomUp_SkScanlineOrder: |
261 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: { | 278 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: { |
262 for (int y = 0; y < srcHeight; y++) { | 279 Result result = kSuccess; |
| 280 int y; |
| 281 for (y = 0; y < srcHeight; y++) { |
263 int srcY = fScanlineDecoder->getY(); | 282 int srcY = fScanlineDecoder->getY(); |
264 if (is_coord_necessary(srcY, sampleY, dstHeight)) { | 283 if (is_coord_necessary(srcY, sampleY, dstHeight)) { |
265 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_co
ord(srcY, sampleY)); | 284 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_co
ord(srcY, sampleY)); |
266 result = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes)
; | 285 lines = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes); |
267 if (kSuccess != result && kIncompleteInput != result) { | 286 if (1 != lines) { |
268 return result; | 287 result = kIncompleteInput; |
| 288 break; |
269 } | 289 } |
270 } else { | 290 } else { |
271 result = fScanlineDecoder->skipScanlines(1); | 291 lines = fScanlineDecoder->skipScanlines(1); |
272 if (kSuccess != result && kIncompleteInput != result) { | 292 if (1 != lines) { |
273 return result; | 293 result = kIncompleteInput; |
| 294 break; |
274 } | 295 } |
275 } | 296 } |
276 } | 297 } |
| 298 |
| 299 // Fill the remaining rows on an incomplete input |
| 300 if (kIncompleteInput == result) { |
| 301 const SkImageInfo fillInfo = requestedInfo.makeWH(requestedInfo.
width(), 1); |
| 302 const uint32_t fillValue = this->getFillValue(fillInfo); |
| 303 for (; y < srcHeight; y++) { |
| 304 int srcY = fScanlineDecoder->getY(y); |
| 305 if (is_coord_necessary(srcY, sampleY, dstHeight)) { |
| 306 void* dstRow = SkTAddOffset<void>(dst, |
| 307 rowBytes * get_dst_coord(srcY, sampleY)); |
| 308 SkSwizzler::Fill(dstRow, fillInfo, rowBytes, fillValue, |
| 309 options.fZeroInitialized); |
| 310 } |
| 311 } |
| 312 } |
277 return result; | 313 return result; |
278 } | 314 } |
279 case SkScanlineDecoder::kNone_SkScanlineOrder: { | 315 case SkScanlineDecoder::kNone_SkScanlineOrder: { |
280 SkAutoMalloc storage(srcHeight * rowBytes); | 316 SkAutoMalloc storage(srcHeight * rowBytes); |
281 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); | 317 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); |
282 result = fScanlineDecoder->getScanlines(storagePtr, srcHeight, rowBy
tes); | 318 int scanlines = (int) fScanlineDecoder->getScanlines(storagePtr, src
Height, rowBytes); |
283 if (kSuccess != result && kIncompleteInput != result) { | |
284 return result; | |
285 } | |
286 storagePtr += Y0 * rowBytes; | 319 storagePtr += Y0 * rowBytes; |
287 for (int y = 0; y < dstHeight; y++) { | 320 scanlines -= Y0; |
| 321 int y = 0; |
| 322 while(y < dstHeight && scanlines > 0) { |
288 memcpy(dst, storagePtr, rowBytes); | 323 memcpy(dst, storagePtr, rowBytes); |
289 storagePtr += sampleY * rowBytes; | 324 storagePtr += sampleY * rowBytes; |
290 dst = SkTAddOffset<void>(dst, rowBytes); | 325 dst = SkTAddOffset<void>(dst, rowBytes); |
| 326 scanlines -= sampleY; |
| 327 y++; |
291 } | 328 } |
292 return result; | 329 if (y < dstHeight) { |
| 330 this->setIncompleteScanlines(dstHeight - y); |
| 331 return kIncompleteInput; |
| 332 } |
| 333 return kSuccess; |
293 } | 334 } |
294 default: | 335 default: |
295 SkASSERT(false); | 336 SkASSERT(false); |
296 return kUnimplemented; | 337 return kUnimplemented; |
297 } | 338 } |
298 } | 339 } |
| 340 |
| 341 uint32_t SkScaledCodec::onGetFillValue(const SkImageInfo& dstInfo) const { |
| 342 return fScanlineDecoder->getFillValue(dstInfo); |
| 343 } |
| 344 |
| 345 void* SkScaledCodec::onGetFillDst(void* dst, size_t rowBytes, |
| 346 uint32_t decodedScanlines) const { |
| 347 return fScanlineDecoder->getFillDst(dst, rowBytes, decodedScanlines); |
| 348 } |
OLD | NEW |