OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010, The Android Open Source Project | 2 * Copyright 2010, The Android Open Source Project |
3 * | 3 * |
4 * Licensed under the Apache License, Version 2.0 (the "License"); | 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
5 * you may not use this file except in compliance with the License. | 5 * you may not use this file except in compliance with the License. |
6 * You may obtain a copy of the License at | 6 * You may obtain a copy of the License at |
7 * | 7 * |
8 * http://www.apache.org/licenses/LICENSE-2.0 | 8 * http://www.apache.org/licenses/LICENSE-2.0 |
9 * | 9 * |
10 * Unless required by applicable law or agreed to in writing, software | 10 * Unless required by applicable law or agreed to in writing, software |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 virtual ~SkWEBPImageDecoder() { | 104 virtual ~SkWEBPImageDecoder() { |
105 SkSafeUnref(fInputStream); | 105 SkSafeUnref(fInputStream); |
106 } | 106 } |
107 | 107 |
108 virtual Format getFormat() const SK_OVERRIDE { | 108 virtual Format getFormat() const SK_OVERRIDE { |
109 return kWEBP_Format; | 109 return kWEBP_Format; |
110 } | 110 } |
111 | 111 |
112 protected: | 112 protected: |
113 virtual bool onBuildTileIndex(SkStream *stream, int *width, int *height) SK_
OVERRIDE; | 113 virtual bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *h
eight) SK_OVERRIDE; |
114 virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) SK_OVERRI
DE; | 114 virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) SK_OVERRI
DE; |
115 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; | 115 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; |
116 | 116 |
117 private: | 117 private: |
118 /** | 118 /** |
119 * Called when determining the output config to request to webp. | 119 * Called when determining the output config to request to webp. |
120 * If the image does not have alpha, there is no need to premultiply. | 120 * If the image does not have alpha, there is no need to premultiply. |
121 * If the caller wants unpremultiplied colors, that is respected. | 121 * If the caller wants unpremultiplied colors, that is respected. |
122 */ | 122 */ |
123 bool shouldPremultiply() const { | 123 bool shouldPremultiply() const { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 return false; | 293 return false; |
294 } | 294 } |
295 | 295 |
296 decodedBitmap->setConfig(config, width, height, 0); | 296 decodedBitmap->setConfig(config, width, height, 0); |
297 | 297 |
298 decodedBitmap->setIsOpaque(!fHasAlpha); | 298 decodedBitmap->setIsOpaque(!fHasAlpha); |
299 | 299 |
300 return true; | 300 return true; |
301 } | 301 } |
302 | 302 |
303 bool SkWEBPImageDecoder::onBuildTileIndex(SkStream* stream, | 303 bool SkWEBPImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, |
304 int *width, int *height) { | 304 int *width, int *height) { |
305 int origWidth, origHeight, hasAlpha; | 305 int origWidth, origHeight, hasAlpha; |
306 if (!webp_parse_header(stream, &origWidth, &origHeight, &hasAlpha)) { | 306 if (!webp_parse_header(stream, &origWidth, &origHeight, &hasAlpha)) { |
307 return false; | 307 return false; |
308 } | 308 } |
309 | 309 |
310 if (!stream->rewind()) { | 310 if (!stream->rewind()) { |
311 SkDebugf("Failed to rewind webp stream!"); | 311 SkDebugf("Failed to rewind webp stream!"); |
312 return false; | 312 return false; |
313 } | 313 } |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 568 |
569 return ok; | 569 return ok; |
570 } | 570 } |
571 | 571 |
572 | 572 |
573 /////////////////////////////////////////////////////////////////////////////// | 573 /////////////////////////////////////////////////////////////////////////////// |
574 DEFINE_DECODER_CREATOR(WEBPImageDecoder); | 574 DEFINE_DECODER_CREATOR(WEBPImageDecoder); |
575 DEFINE_ENCODER_CREATOR(WEBPImageEncoder); | 575 DEFINE_ENCODER_CREATOR(WEBPImageEncoder); |
576 /////////////////////////////////////////////////////////////////////////////// | 576 /////////////////////////////////////////////////////////////////////////////// |
577 | 577 |
578 static SkImageDecoder* sk_libwebp_dfactory(SkStream* stream) { | 578 static SkImageDecoder* sk_libwebp_dfactory(SkStreamRewindable* stream) { |
579 int width, height, hasAlpha; | 579 int width, height, hasAlpha; |
580 if (!webp_parse_header(stream, &width, &height, &hasAlpha)) { | 580 if (!webp_parse_header(stream, &width, &height, &hasAlpha)) { |
581 return NULL; | 581 return NULL; |
582 } | 582 } |
583 | 583 |
584 // Magic matches, call decoder | 584 // Magic matches, call decoder |
585 return SkNEW(SkWEBPImageDecoder); | 585 return SkNEW(SkWEBPImageDecoder); |
586 } | 586 } |
587 | 587 |
588 static SkImageDecoder::Format get_format_webp(SkStream* stream) { | 588 static SkImageDecoder::Format get_format_webp(SkStreamRewindable* stream) { |
589 int width, height, hasAlpha; | 589 int width, height, hasAlpha; |
590 if (webp_parse_header(stream, &width, &height, &hasAlpha)) { | 590 if (webp_parse_header(stream, &width, &height, &hasAlpha)) { |
591 return SkImageDecoder::kWEBP_Format; | 591 return SkImageDecoder::kWEBP_Format; |
592 } | 592 } |
593 return SkImageDecoder::kUnknown_Format; | 593 return SkImageDecoder::kUnknown_Format; |
594 } | 594 } |
595 | 595 |
596 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { | 596 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { |
597 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; | 597 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; |
598 } | 598 } |
599 | 599 |
600 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); | 600 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); |
601 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); | 601 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); |
602 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); | 602 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); |
OLD | NEW |