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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 91 } |
92 | 92 |
93 class SkWEBPImageDecoder: public SkImageDecoder { | 93 class SkWEBPImageDecoder: public SkImageDecoder { |
94 public: | 94 public: |
95 SkWEBPImageDecoder() { | 95 SkWEBPImageDecoder() { |
96 fOrigWidth = 0; | 96 fOrigWidth = 0; |
97 fOrigHeight = 0; | 97 fOrigHeight = 0; |
98 fHasAlpha = 0; | 98 fHasAlpha = 0; |
99 } | 99 } |
100 | 100 |
101 Format getFormat() const SK_OVERRIDE { | 101 Format getFormat() const override { |
102 return kWEBP_Format; | 102 return kWEBP_Format; |
103 } | 103 } |
104 | 104 |
105 protected: | 105 protected: |
106 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) S
K_OVERRIDE; | 106 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) o
verride; |
107 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) SK_OVERRIDE; | 107 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) override; |
108 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; | 108 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override; |
109 | 109 |
110 private: | 110 private: |
111 /** | 111 /** |
112 * Called when determining the output config to request to webp. | 112 * Called when determining the output config to request to webp. |
113 * If the image does not have alpha, there is no need to premultiply. | 113 * If the image does not have alpha, there is no need to premultiply. |
114 * If the caller wants unpremultiplied colors, that is respected. | 114 * If the caller wants unpremultiplied colors, that is respected. |
115 */ | 115 */ |
116 bool shouldPremultiply() const { | 116 bool shouldPremultiply() const { |
117 return SkToBool(fHasAlpha) && !this->getRequireUnpremultipliedColors(); | 117 return SkToBool(fHasAlpha) && !this->getRequireUnpremultipliedColors(); |
118 } | 118 } |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 } | 576 } |
577 | 577 |
578 static int stream_writer(const uint8_t* data, size_t data_size, | 578 static int stream_writer(const uint8_t* data, size_t data_size, |
579 const WebPPicture* const picture) { | 579 const WebPPicture* const picture) { |
580 SkWStream* const stream = (SkWStream*)picture->custom_ptr; | 580 SkWStream* const stream = (SkWStream*)picture->custom_ptr; |
581 return stream->write(data, data_size) ? 1 : 0; | 581 return stream->write(data, data_size) ? 1 : 0; |
582 } | 582 } |
583 | 583 |
584 class SkWEBPImageEncoder : public SkImageEncoder { | 584 class SkWEBPImageEncoder : public SkImageEncoder { |
585 protected: | 585 protected: |
586 bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) SK_OVERRID
E; | 586 bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) override; |
587 | 587 |
588 private: | 588 private: |
589 typedef SkImageEncoder INHERITED; | 589 typedef SkImageEncoder INHERITED; |
590 }; | 590 }; |
591 | 591 |
592 bool SkWEBPImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bm, | 592 bool SkWEBPImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bm, |
593 int quality) { | 593 int quality) { |
594 const bool hasAlpha = !bm.isOpaque(); | 594 const bool hasAlpha = !bm.isOpaque(); |
595 int bpp = -1; | 595 int bpp = -1; |
596 const ScanlineImporter scanline_import = ChooseImporter(bm.colorType(), hasA
lpha, &bpp); | 596 const ScanlineImporter scanline_import = ChooseImporter(bm.colorType(), hasA
lpha, &bpp); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 return SkImageDecoder::kUnknown_Format; | 668 return SkImageDecoder::kUnknown_Format; |
669 } | 669 } |
670 | 670 |
671 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { | 671 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { |
672 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; | 672 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; |
673 } | 673 } |
674 | 674 |
675 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); | 675 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); |
676 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); | 676 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); |
677 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); | 677 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); |
OLD | NEW |