| 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" |
| 11 #include "SkWebpCodec.h" | 11 #include "SkWebpCodec.h" |
| 12 | 12 |
| 13 | 13 |
| 14 SkCodec* SkScaledCodec::NewFromStream(SkStream* stream) { | 14 SkCodec* SkScaledCodec::NewFromStream(SkStream* stream) { |
| 15 bool isWebp = SkWebpCodec::IsWebp(stream); | 15 bool isWebp = SkWebpCodec::IsWebp(stream); |
| 16 if (!stream->rewind()) { | 16 if (!stream->rewind()) { |
| 17 return NULL; | 17 return nullptr; |
| 18 } | 18 } |
| 19 if (isWebp) { | 19 if (isWebp) { |
| 20 // Webp codec supports scaling and subsetting natively | 20 // Webp codec supports scaling and subsetting natively |
| 21 return SkWebpCodec::NewFromStream(stream); | 21 return SkWebpCodec::NewFromStream(stream); |
| 22 } | 22 } |
| 23 | 23 |
| 24 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(SkScanlineDecoder::NewFromS
tream(stream)); | 24 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(SkScanlineDecoder::NewFromS
tream(stream)); |
| 25 if (NULL == scanlineDecoder) { | 25 if (nullptr == scanlineDecoder) { |
| 26 return NULL; | 26 return nullptr; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // wrap in new SkScaledCodec | 29 // wrap in new SkScaledCodec |
| 30 return new SkScaledCodec(scanlineDecoder.detach()); | 30 return new SkScaledCodec(scanlineDecoder.detach()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 SkCodec* SkScaledCodec::NewFromData(SkData* data) { | 33 SkCodec* SkScaledCodec::NewFromData(SkData* data) { |
| 34 if (!data) { | 34 if (!data) { |
| 35 return NULL; | 35 return nullptr; |
| 36 } | 36 } |
| 37 return NewFromStream(new SkMemoryStream(data)); | 37 return NewFromStream(new SkMemoryStream(data)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 SkScaledCodec::SkScaledCodec(SkScanlineDecoder* scanlineDecoder) | 40 SkScaledCodec::SkScaledCodec(SkScanlineDecoder* scanlineDecoder) |
| 41 : INHERITED(scanlineDecoder->getInfo(), NULL) | 41 : INHERITED(scanlineDecoder->getInfo(), nullptr) |
| 42 , fScanlineDecoder(scanlineDecoder) | 42 , fScanlineDecoder(scanlineDecoder) |
| 43 {} | 43 {} |
| 44 | 44 |
| 45 SkScaledCodec::~SkScaledCodec() {} | 45 SkScaledCodec::~SkScaledCodec() {} |
| 46 | 46 |
| 47 // returns a scaled dimension based on the original dimension and the sampleSize | 47 // returns a scaled dimension based on the original dimension and the sampleSize |
| 48 // NOTE: we round down here for scaled dimension to match the behavior of SkImag
eDecoder | 48 // NOTE: we round down here for scaled dimension to match the behavior of SkImag
eDecoder |
| 49 static int get_scaled_dimension(int srcDimension, int sampleSize) { | 49 static int get_scaled_dimension(int srcDimension, int sampleSize) { |
| 50 if (sampleSize > srcDimension) { | 50 if (sampleSize > srcDimension) { |
| 51 return 1; | 51 return 1; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 result = fScanlineDecoder->skipScanlines(sampleY - 1); | 258 result = fScanlineDecoder->skipScanlines(sampleY - 1); |
| 259 if (kSuccess != result) { | 259 if (kSuccess != result) { |
| 260 return result; | 260 return result; |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 dst = SkTAddOffset<void>(dst, rowBytes); | 263 dst = SkTAddOffset<void>(dst, rowBytes); |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 return kSuccess; | 266 return kSuccess; |
| 267 } | 267 } |
| OLD | NEW |