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 "SkWebpCodec.h" | 9 #include "SkWebpCodec.h" |
10 #include "SkTemplates.h" | 10 #include "SkTemplates.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 return true; | 73 return true; |
74 } | 74 } |
75 | 75 |
76 SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { | 76 SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { |
77 SkAutoTDelete<SkStream> streamDeleter(stream); | 77 SkAutoTDelete<SkStream> streamDeleter(stream); |
78 SkImageInfo info; | 78 SkImageInfo info; |
79 if (webp_parse_header(stream, &info)) { | 79 if (webp_parse_header(stream, &info)) { |
80 return new SkWebpCodec(info, streamDeleter.detach()); | 80 return new SkWebpCodec(info, streamDeleter.detach()); |
81 } | 81 } |
82 return NULL; | 82 return nullptr; |
83 } | 83 } |
84 | 84 |
85 // This version is slightly different from SkCodecPriv's version of conversion_p
ossible. It | 85 // This version is slightly different from SkCodecPriv's version of conversion_p
ossible. It |
86 // supports both byte orders for 8888. | 86 // supports both byte orders for 8888. |
87 static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo&
src) { | 87 static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo&
src) { |
88 if (dst.profileType() != src.profileType()) { | 88 if (dst.profileType() != src.profileType()) { |
89 return false; | 89 return false; |
90 } | 90 } |
91 | 91 |
92 if (!valid_alpha(dst.alphaType(), src.alphaType())) { | 92 if (!valid_alpha(dst.alphaType(), src.alphaType())) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 config.options.scaled_height = dstDimensions.height(); | 214 config.options.scaled_height = dstDimensions.height(); |
215 } | 215 } |
216 | 216 |
217 config.output.colorspace = webp_decode_mode(dstInfo.colorType(), | 217 config.output.colorspace = webp_decode_mode(dstInfo.colorType(), |
218 dstInfo.alphaType() == kPremul_SkAlphaType); | 218 dstInfo.alphaType() == kPremul_SkAlphaType); |
219 config.output.u.RGBA.rgba = (uint8_t*) dst; | 219 config.output.u.RGBA.rgba = (uint8_t*) dst; |
220 config.output.u.RGBA.stride = (int) rowBytes; | 220 config.output.u.RGBA.stride = (int) rowBytes; |
221 config.output.u.RGBA.size = dstInfo.getSafeSize(rowBytes); | 221 config.output.u.RGBA.size = dstInfo.getSafeSize(rowBytes); |
222 config.output.is_external_memory = 1; | 222 config.output.is_external_memory = 1; |
223 | 223 |
224 SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(NULL, 0, &confi
g)); | 224 SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &co
nfig)); |
225 if (!idec) { | 225 if (!idec) { |
226 return kInvalidInput; | 226 return kInvalidInput; |
227 } | 227 } |
228 | 228 |
229 SkAutoMalloc storage(BUFFER_SIZE); | 229 SkAutoMalloc storage(BUFFER_SIZE); |
230 uint8_t* buffer = static_cast<uint8_t*>(storage.get()); | 230 uint8_t* buffer = static_cast<uint8_t*>(storage.get()); |
231 while (true) { | 231 while (true) { |
232 const size_t bytesRead = stream()->read(buffer, BUFFER_SIZE); | 232 const size_t bytesRead = stream()->read(buffer, BUFFER_SIZE); |
233 if (0 == bytesRead) { | 233 if (0 == bytesRead) { |
234 // FIXME: Maybe this is an incomplete image? How to decide? Based | 234 // FIXME: Maybe this is an incomplete image? How to decide? Based |
235 // on the number of rows decoded? We can know the number of rows | 235 // on the number of rows decoded? We can know the number of rows |
236 // decoded using WebPIDecGetRGB. | 236 // decoded using WebPIDecGetRGB. |
237 return kInvalidInput; | 237 return kInvalidInput; |
238 } | 238 } |
239 | 239 |
240 switch (WebPIAppend(idec, buffer, bytesRead)) { | 240 switch (WebPIAppend(idec, buffer, bytesRead)) { |
241 case VP8_STATUS_OK: | 241 case VP8_STATUS_OK: |
242 return kSuccess; | 242 return kSuccess; |
243 case VP8_STATUS_SUSPENDED: | 243 case VP8_STATUS_SUSPENDED: |
244 // Break out of the switch statement. Continue the loop. | 244 // Break out of the switch statement. Continue the loop. |
245 break; | 245 break; |
246 default: | 246 default: |
247 return kInvalidInput; | 247 return kInvalidInput; |
248 } | 248 } |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) | 252 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) |
253 : INHERITED(info, stream) {} | 253 : INHERITED(info, stream) {} |
OLD | NEW |