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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(SkStream *stream, int *width, int *height) SK_
OVERRIDE; |
114 virtual bool onDecodeRegion(SkBitmap* bitmap, const SkIRect& rect) SK_OVERRI
DE; | 114 virtual bool onDecodeRegion(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 virtual Format onGetFormat(SkStream*) const SK_OVERRIDE; |
116 | 117 |
117 private: | 118 private: |
118 bool setDecodeConfig(SkBitmap* decodedBitmap, int width, int height); | 119 bool setDecodeConfig(SkBitmap* decodedBitmap, int width, int height); |
119 SkStream* fInputStream; | 120 SkStream* fInputStream; |
120 int fOrigWidth; | 121 int fOrigWidth; |
121 int fOrigHeight; | 122 int fOrigHeight; |
122 int fHasAlpha; | 123 int fHasAlpha; |
123 | 124 |
124 typedef SkImageDecoder INHERITED; | 125 typedef SkImageDecoder INHERITED; |
125 }; | 126 }; |
126 | 127 |
| 128 SkImageDecoder::Format SkWEBPImageDecoder::onGetFormat(SkStream* stream) const { |
| 129 int width, height, hasAlpha; |
| 130 if (webp_parse_header(stream, &width, &height, &hasAlpha)) { |
| 131 return kWEBP_Format; |
| 132 } |
| 133 return kUnknown_Format; |
| 134 } |
| 135 |
127 ////////////////////////////////////////////////////////////////////////// | 136 ////////////////////////////////////////////////////////////////////////// |
128 | 137 |
129 #ifdef TIME_DECODE | 138 #ifdef TIME_DECODE |
130 | 139 |
131 #include "SkTime.h" | 140 #include "SkTime.h" |
132 | 141 |
133 class AutoTimeMillis { | 142 class AutoTimeMillis { |
134 public: | 143 public: |
135 AutoTimeMillis(const char label[]) : | 144 AutoTimeMillis(const char label[]) : |
136 fLabel(label) { | 145 fLabel(label) { |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 // Magic matches, call decoder | 595 // Magic matches, call decoder |
587 return SkNEW(SkWEBPImageDecoder); | 596 return SkNEW(SkWEBPImageDecoder); |
588 } | 597 } |
589 | 598 |
590 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { | 599 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { |
591 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; | 600 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; |
592 } | 601 } |
593 | 602 |
594 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); | 603 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); |
595 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact
ory); | 604 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact
ory); |
OLD | NEW |