| 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 "SkWebpCodec.h" | 9 #include "SkWebpCodec.h" | 
| 9 #include "SkTemplates.h" | 10 #include "SkTemplates.h" | 
| 10 | 11 | 
| 11 // A WebP decoder on top of (subset of) libwebp | 12 // A WebP decoder on top of (subset of) libwebp | 
| 12 // For more information on WebP image format, and libwebp library, see: | 13 // For more information on WebP image format, and libwebp library, see: | 
| 13 //   https://code.google.com/speed/webp/ | 14 //   https://code.google.com/speed/webp/ | 
| 14 //   http://www.webmproject.org/code/#libwebp-webp-image-library | 15 //   http://www.webmproject.org/code/#libwebp-webp-image-library | 
| 15 //   https://chromium.googlesource.com/webm/libwebp | 16 //   https://chromium.googlesource.com/webm/libwebp | 
| 16 | 17 | 
| 17 // If moving libwebp out of skia source tree, path for webp headers must be | 18 // If moving libwebp out of skia source tree, path for webp headers must be | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 74 | 75 | 
| 75 SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { | 76 SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { | 
| 76     SkAutoTDelete<SkStream> streamDeleter(stream); | 77     SkAutoTDelete<SkStream> streamDeleter(stream); | 
| 77     SkImageInfo info; | 78     SkImageInfo info; | 
| 78     if (webp_parse_header(stream, &info)) { | 79     if (webp_parse_header(stream, &info)) { | 
| 79         return SkNEW_ARGS(SkWebpCodec, (info, streamDeleter.detach())); | 80         return SkNEW_ARGS(SkWebpCodec, (info, streamDeleter.detach())); | 
| 80     } | 81     } | 
| 81     return NULL; | 82     return NULL; | 
| 82 } | 83 } | 
| 83 | 84 | 
| 84 static bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) 
     { | 85 // This version is slightly different from SkCodecPriv's version of conversion_p
     ossible. It | 
|  | 86 // supports both byte orders for 8888. | 
|  | 87 static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo& 
     src) { | 
| 85     if (dst.profileType() != src.profileType()) { | 88     if (dst.profileType() != src.profileType()) { | 
| 86         return false; | 89         return false; | 
| 87     } | 90     } | 
|  | 91 | 
|  | 92     if (!valid_alpha(dst.alphaType(), src.alphaType())) { | 
|  | 93         return false; | 
|  | 94     } | 
|  | 95 | 
| 88     switch (dst.colorType()) { | 96     switch (dst.colorType()) { | 
| 89         // Both byte orders are supported. | 97         // Both byte orders are supported. | 
| 90         case kBGRA_8888_SkColorType: | 98         case kBGRA_8888_SkColorType: | 
| 91         case kRGBA_8888_SkColorType: | 99         case kRGBA_8888_SkColorType: | 
| 92             break; | 100             return true; | 
| 93         case kRGB_565_SkColorType: | 101         case kRGB_565_SkColorType: | 
| 94             if (src.alphaType() == kOpaque_SkAlphaType | 102             return src.alphaType() == kOpaque_SkAlphaType; | 
| 95                 && dst.alphaType() == kOpaque_SkAlphaType) |  | 
| 96             { |  | 
| 97                 return true; |  | 
| 98             } |  | 
| 99         default: | 103         default: | 
| 100             return false; | 104             return false; | 
| 101     } | 105     } | 
| 102     if (dst.alphaType() == src.alphaType()) { |  | 
| 103         return true; |  | 
| 104     } |  | 
| 105     return kPremul_SkAlphaType == dst.alphaType() && |  | 
| 106             kUnpremul_SkAlphaType == src.alphaType(); |  | 
| 107 } | 106 } | 
| 108 | 107 | 
| 109 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const { | 108 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const { | 
| 110     SkISize dim = this->getInfo().dimensions(); | 109     SkISize dim = this->getInfo().dimensions(); | 
| 111     // SkCodec treats zero dimensional images as errors, so the minimum size | 110     // SkCodec treats zero dimensional images as errors, so the minimum size | 
| 112     // that we will recommend is 1x1. | 111     // that we will recommend is 1x1. | 
| 113     dim.fWidth = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fWidth)); | 112     dim.fWidth = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fWidth)); | 
| 114     dim.fHeight = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fHeight)); | 113     dim.fHeight = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fHeight)); | 
| 115     return dim; | 114     return dim; | 
| 116 } | 115 } | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 158             return kCouldNotRewind; | 157             return kCouldNotRewind; | 
| 159         case kRewound_RewindState: | 158         case kRewound_RewindState: | 
| 160             // Rewound to the beginning. Since creation only does a peek, the st
     ream is at the | 159             // Rewound to the beginning. Since creation only does a peek, the st
     ream is at the | 
| 161             // correct position. | 160             // correct position. | 
| 162             break; | 161             break; | 
| 163         case kNoRewindNecessary_RewindState: | 162         case kNoRewindNecessary_RewindState: | 
| 164             // Already at the right spot for decoding. | 163             // Already at the right spot for decoding. | 
| 165             break; | 164             break; | 
| 166     } | 165     } | 
| 167 | 166 | 
| 168     if (!conversion_possible(dstInfo, this->getInfo())) { | 167     if (!webp_conversion_possible(dstInfo, this->getInfo())) { | 
| 169         return kInvalidConversion; | 168         return kInvalidConversion; | 
| 170     } | 169     } | 
| 171 | 170 | 
| 172     WebPDecoderConfig config; | 171     WebPDecoderConfig config; | 
| 173     if (0 == WebPInitDecoderConfig(&config)) { | 172     if (0 == WebPInitDecoderConfig(&config)) { | 
| 174         // ABI mismatch. | 173         // ABI mismatch. | 
| 175         // FIXME: New enum for this? | 174         // FIXME: New enum for this? | 
| 176         return kInvalidInput; | 175         return kInvalidInput; | 
| 177     } | 176     } | 
| 178 | 177 | 
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 253                 // Break out of the switch statement. Continue the loop. | 252                 // Break out of the switch statement. Continue the loop. | 
| 254                 break; | 253                 break; | 
| 255             default: | 254             default: | 
| 256                 return kInvalidInput; | 255                 return kInvalidInput; | 
| 257         } | 256         } | 
| 258     } | 257     } | 
| 259 } | 258 } | 
| 260 | 259 | 
| 261 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) | 260 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) | 
| 262     : INHERITED(info, stream) {} | 261     : INHERITED(info, stream) {} | 
| OLD | NEW | 
|---|