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 "SkAndroidCodec.h" | 8 #include "SkAndroidCodec.h" |
9 #include "SkCodec.h" | 9 #include "SkCodec.h" |
10 #include "SkCodecPriv.h" | 10 #include "SkCodecPriv.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 SkAndroidCodec* SkAndroidCodec::NewFromData(SkData* data, SkPngChunkReader* chun
kReader) { | 44 SkAndroidCodec* SkAndroidCodec::NewFromData(SkData* data, SkPngChunkReader* chun
kReader) { |
45 if (!data) { | 45 if (!data) { |
46 return nullptr; | 46 return nullptr; |
47 } | 47 } |
48 | 48 |
49 return NewFromStream(new SkMemoryStream(data), chunkReader); | 49 return NewFromStream(new SkMemoryStream(data), chunkReader); |
50 } | 50 } |
51 | 51 |
| 52 SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorTyp
e) { |
| 53 SkColorType suggestedColorType = this->getInfo().colorType(); |
| 54 switch (requestedColorType) { |
| 55 case kARGB_4444_SkColorType: |
| 56 case kN32_SkColorType: |
| 57 return kN32_SkColorType; |
| 58 case kIndex_8_SkColorType: |
| 59 if (kIndex_8_SkColorType == suggestedColorType) { |
| 60 return kIndex_8_SkColorType; |
| 61 } |
| 62 break; |
| 63 case kAlpha_8_SkColorType: |
| 64 // Fall through to kGray_8. Before kGray_8_SkColorType existed, |
| 65 // we allowed clients to request kAlpha_8 when they wanted a |
| 66 // grayscale decode. |
| 67 case kGray_8_SkColorType: |
| 68 if (kGray_8_SkColorType == suggestedColorType) { |
| 69 return kGray_8_SkColorType; |
| 70 } |
| 71 break; |
| 72 case kRGB_565_SkColorType: |
| 73 if (kOpaque_SkAlphaType == this->getInfo().alphaType()) { |
| 74 return kRGB_565_SkColorType; |
| 75 } |
| 76 break; |
| 77 default: |
| 78 break; |
| 79 } |
| 80 |
| 81 return suggestedColorType; |
| 82 } |
| 83 |
| 84 SkAlphaType SkAndroidCodec::computeOutputAlphaType(bool requestedUnpremul) { |
| 85 if (kOpaque_SkAlphaType == this->getInfo().alphaType()) { |
| 86 return kOpaque_SkAlphaType; |
| 87 } |
| 88 return requestedUnpremul ? kUnpremul_SkAlphaType : kPremul_SkAlphaType; |
| 89 } |
| 90 |
52 SkISize SkAndroidCodec::getSampledDimensions(int sampleSize) const { | 91 SkISize SkAndroidCodec::getSampledDimensions(int sampleSize) const { |
53 if (!is_valid_sample_size(sampleSize)) { | 92 if (!is_valid_sample_size(sampleSize)) { |
54 return SkISize::Make(0, 0); | 93 return SkISize::Make(0, 0); |
55 } | 94 } |
56 | 95 |
57 // Fast path for when we are not scaling. | 96 // Fast path for when we are not scaling. |
58 if (1 == sampleSize) { | 97 if (1 == sampleSize) { |
59 return fInfo.dimensions(); | 98 return fInfo.dimensions(); |
60 } | 99 } |
61 | 100 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 160 } |
122 } | 161 } |
123 | 162 |
124 return this->onGetAndroidPixels(info, pixels, rowBytes, *options); | 163 return this->onGetAndroidPixels(info, pixels, rowBytes, *options); |
125 } | 164 } |
126 | 165 |
127 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void*
pixels, | 166 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void*
pixels, |
128 size_t rowBytes) { | 167 size_t rowBytes) { |
129 return this->getAndroidPixels(info, pixels, rowBytes, nullptr); | 168 return this->getAndroidPixels(info, pixels, rowBytes, nullptr); |
130 } | 169 } |
OLD | NEW |