| 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 "SkBitmapRegionCanvas.h" | 8 #include "SkBitmapRegionCanvas.h" |
| 9 #include "SkBitmapRegionCodec.h" | 9 #include "SkBitmapRegionCodec.h" |
| 10 #include "SkBitmapRegionDecoder.h" | 10 #include "SkBitmapRegionDecoder.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 SkStreamRewindable* stream, Strategy strategy) { | 23 SkStreamRewindable* stream, Strategy strategy) { |
| 24 SkAutoTDelete<SkStreamRewindable> streamDeleter(stream); | 24 SkAutoTDelete<SkStreamRewindable> streamDeleter(stream); |
| 25 switch (strategy) { | 25 switch (strategy) { |
| 26 case kCanvas_Strategy: { | 26 case kCanvas_Strategy: { |
| 27 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(streamDeleter.de
tach())); | 27 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(streamDeleter.de
tach())); |
| 28 if (nullptr == codec) { | 28 if (nullptr == codec) { |
| 29 SkCodecPrintf("Error: Failed to create decoder.\n"); | 29 SkCodecPrintf("Error: Failed to create decoder.\n"); |
| 30 return nullptr; | 30 return nullptr; |
| 31 } | 31 } |
| 32 | 32 |
| 33 if (SkEncodedFormat::kWEBP_SkEncodedFormat == codec->getEncodedForma
t()) { | 33 SkEncodedFormat format = codec->getEncodedFormat(); |
| 34 // FIXME: Support webp using a special case. Webp does not supp
ort | 34 switch (format) { |
| 35 // scanline decoding. | 35 case SkEncodedFormat::kJPEG_SkEncodedFormat: |
| 36 return nullptr; | 36 case SkEncodedFormat::kPNG_SkEncodedFormat: |
| 37 break; |
| 38 default: |
| 39 // FIXME: Support webp using a special case. Webp does not
support |
| 40 // scanline decoding. |
| 41 return nullptr; |
| 37 } | 42 } |
| 38 | 43 |
| 39 switch (codec->getScanlineOrder()) { | 44 // If the image is a jpeg or a png, the scanline ordering should alw
ays be |
| 40 case SkCodec::kTopDown_SkScanlineOrder: | 45 // kTopDown or kNone. It is relevant to check because this implemen
tation |
| 41 case SkCodec::kNone_SkScanlineOrder: | 46 // only supports these two scanline orderings. |
| 42 break; | 47 SkASSERT(SkCodec::kTopDown_SkScanlineOrder == codec->getScanlineOrde
r() || |
| 43 default: | 48 SkCodec::kNone_SkScanlineOrder == codec->getScanlineOrder())
; |
| 44 SkCodecPrintf("Error: Scanline ordering not supported.\n"); | 49 |
| 45 return nullptr; | |
| 46 } | |
| 47 return new SkBitmapRegionCanvas(codec.detach()); | 50 return new SkBitmapRegionCanvas(codec.detach()); |
| 48 } | 51 } |
| 49 case kAndroidCodec_Strategy: { | 52 case kAndroidCodec_Strategy: { |
| 50 SkAutoTDelete<SkAndroidCodec> codec = | 53 SkAutoTDelete<SkAndroidCodec> codec = |
| 51 SkAndroidCodec::NewFromStream(streamDeleter.detach()); | 54 SkAndroidCodec::NewFromStream(streamDeleter.detach()); |
| 52 if (NULL == codec) { | 55 if (nullptr == codec) { |
| 53 SkCodecPrintf("Error: Failed to create codec.\n"); | 56 SkCodecPrintf("Error: Failed to create codec.\n"); |
| 54 return NULL; | 57 return NULL; |
| 55 } | 58 } |
| 59 |
| 60 SkEncodedFormat format = codec->getEncodedFormat(); |
| 61 switch (format) { |
| 62 case SkEncodedFormat::kJPEG_SkEncodedFormat: |
| 63 case SkEncodedFormat::kPNG_SkEncodedFormat: |
| 64 case SkEncodedFormat::kWEBP_SkEncodedFormat: |
| 65 break; |
| 66 default: |
| 67 return nullptr; |
| 68 } |
| 69 |
| 56 return new SkBitmapRegionCodec(codec.detach()); | 70 return new SkBitmapRegionCodec(codec.detach()); |
| 57 } | 71 } |
| 58 default: | 72 default: |
| 59 SkASSERT(false); | 73 SkASSERT(false); |
| 60 return nullptr; | 74 return nullptr; |
| 61 } | 75 } |
| 62 } | 76 } |
| OLD | NEW |