| 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" |
| 11 #include "SkSampledCodec.h" |
| 12 |
| 11 #ifdef SK_CODEC_DECODES_RAW | 13 #ifdef SK_CODEC_DECODES_RAW |
| 12 #include "SkRawAdapterCodec.h" | 14 #include "SkRawAdapterCodec.h" |
| 13 #endif | 15 #endif |
| 14 #include "SkSampledCodec.h" | 16 #ifdef SK_CODEC_DECODES_WEBP |
| 15 #include "SkWebpAdapterCodec.h" | 17 #include "SkWebpAdapterCodec.h" |
| 18 #endif |
| 16 | 19 |
| 17 static bool is_valid_sample_size(int sampleSize) { | 20 static bool is_valid_sample_size(int sampleSize) { |
| 18 // FIXME: As Leon has mentioned elsewhere, surely there is also a maximum sa
mpleSize? | 21 // FIXME: As Leon has mentioned elsewhere, surely there is also a maximum sa
mpleSize? |
| 19 return sampleSize > 0; | 22 return sampleSize > 0; |
| 20 } | 23 } |
| 21 | 24 |
| 22 SkAndroidCodec::SkAndroidCodec(SkCodec* codec) | 25 SkAndroidCodec::SkAndroidCodec(SkCodec* codec) |
| 23 : fInfo(codec->getInfo()) | 26 : fInfo(codec->getInfo()) |
| 24 , fCodec(codec) | 27 , fCodec(codec) |
| 25 {} | 28 {} |
| 26 | 29 |
| 27 SkAndroidCodec* SkAndroidCodec::NewFromStream(SkStream* stream, SkPngChunkReader
* chunkReader) { | 30 SkAndroidCodec* SkAndroidCodec::NewFromStream(SkStream* stream, SkPngChunkReader
* chunkReader) { |
| 28 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream, chunkReader)); | 31 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream, chunkReader)); |
| 29 if (nullptr == codec) { | 32 if (nullptr == codec) { |
| 30 return nullptr; | 33 return nullptr; |
| 31 } | 34 } |
| 32 | 35 |
| 33 switch (codec->getEncodedFormat()) { | 36 switch (codec->getEncodedFormat()) { |
| 37 #ifdef SK_CODEC_DECODES_WEBP |
| 34 case kWEBP_SkEncodedFormat: | 38 case kWEBP_SkEncodedFormat: |
| 35 return new SkWebpAdapterCodec((SkWebpCodec*) codec.detach()); | 39 return new SkWebpAdapterCodec((SkWebpCodec*) codec.detach()); |
| 40 #endif |
| 41 #ifdef SK_CODEC_DECODES_PNG |
| 36 case kPNG_SkEncodedFormat: | 42 case kPNG_SkEncodedFormat: |
| 43 return new SkSampledCodec(codec.detach()); |
| 44 #endif |
| 45 #ifdef SK_CODEC_DECODES_JPEG |
| 37 case kJPEG_SkEncodedFormat: | 46 case kJPEG_SkEncodedFormat: |
| 47 return new SkSampledCodec(codec.detach()); |
| 48 #endif |
| 49 #ifdef SK_CODEC_DECODES_WBMP |
| 38 case kWBMP_SkEncodedFormat: | 50 case kWBMP_SkEncodedFormat: |
| 51 return new SkSampledCodec(codec.detach()); |
| 52 #endif |
| 53 #ifdef SK_CODEC_DECODES_BMP |
| 39 case kBMP_SkEncodedFormat: | 54 case kBMP_SkEncodedFormat: |
| 55 return new SkSampledCodec(codec.detach()); |
| 56 #endif |
| 57 #ifdef SK_CODEC_DECODES_GIF |
| 40 case kGIF_SkEncodedFormat: | 58 case kGIF_SkEncodedFormat: |
| 59 return new SkSampledCodec(codec.detach()); |
| 60 #endif |
| 61 #ifdef SK_CODEC_DECODES_ICO |
| 41 case kICO_SkEncodedFormat: | 62 case kICO_SkEncodedFormat: |
| 42 return new SkSampledCodec(codec.detach()); | 63 return new SkSampledCodec(codec.detach()); |
| 64 #endif |
| 43 #ifdef SK_CODEC_DECODES_RAW | 65 #ifdef SK_CODEC_DECODES_RAW |
| 44 case kRAW_SkEncodedFormat: | 66 case kRAW_SkEncodedFormat: |
| 45 return new SkRawAdapterCodec((SkRawCodec*)codec.detach()); | 67 return new SkRawAdapterCodec((SkRawCodec*)codec.detach()); |
| 46 #endif | 68 #endif |
| 47 default: | 69 default: |
| 48 return nullptr; | 70 return nullptr; |
| 49 } | 71 } |
| 50 } | 72 } |
| 51 | 73 |
| 52 SkAndroidCodec* SkAndroidCodec::NewFromData(SkData* data, SkPngChunkReader* chun
kReader) { | 74 SkAndroidCodec* SkAndroidCodec::NewFromData(SkData* data, SkPngChunkReader* chun
kReader) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 204 } |
| 183 } | 205 } |
| 184 | 206 |
| 185 return this->onGetAndroidPixels(info, pixels, rowBytes, *options); | 207 return this->onGetAndroidPixels(info, pixels, rowBytes, *options); |
| 186 } | 208 } |
| 187 | 209 |
| 188 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void*
pixels, | 210 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void*
pixels, |
| 189 size_t rowBytes) { | 211 size_t rowBytes) { |
| 190 return this->getAndroidPixels(info, pixels, rowBytes, nullptr); | 212 return this->getAndroidPixels(info, pixels, rowBytes, nullptr); |
| 191 } | 213 } |
| OLD | NEW |