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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(SkStream *stream, int *width, int *height) SK_
OVERRIDE; |
114 virtual bool onDecodeRegion(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 bool setDecodeConfig(SkBitmap* decodedBitmap, int width, int height); | 118 bool setDecodeConfig(SkBitmap* decodedBitmap, int width, int height); |
119 SkStream* fInputStream; | 119 SkStream* fInputStream; |
120 int fOrigWidth; | 120 int fOrigWidth; |
121 int fOrigHeight; | 121 int fOrigHeight; |
122 int fHasAlpha; | 122 int fHasAlpha; |
123 | 123 |
124 typedef SkImageDecoder INHERITED; | 124 typedef SkImageDecoder INHERITED; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 return true; | 314 return true; |
315 } | 315 } |
316 | 316 |
317 static bool is_config_compatible(const SkBitmap& bitmap) { | 317 static bool is_config_compatible(const SkBitmap& bitmap) { |
318 SkBitmap::Config config = bitmap.config(); | 318 SkBitmap::Config config = bitmap.config(); |
319 return config == SkBitmap::kARGB_4444_Config || | 319 return config == SkBitmap::kARGB_4444_Config || |
320 config == SkBitmap::kRGB_565_Config || | 320 config == SkBitmap::kRGB_565_Config || |
321 config == SkBitmap::kARGB_8888_Config; | 321 config == SkBitmap::kARGB_8888_Config; |
322 } | 322 } |
323 | 323 |
324 bool SkWEBPImageDecoder::onDecodeRegion(SkBitmap* decodedBitmap, | 324 bool SkWEBPImageDecoder::onDecodeSubset(SkBitmap* decodedBitmap, |
325 const SkIRect& region) { | 325 const SkIRect& region) { |
326 SkIRect rect = SkIRect::MakeWH(fOrigWidth, fOrigHeight); | 326 SkIRect rect = SkIRect::MakeWH(fOrigWidth, fOrigHeight); |
327 | 327 |
328 if (!rect.intersect(region)) { | 328 if (!rect.intersect(region)) { |
329 // If the requested region is entirely outsides the image, return false | 329 // If the requested region is entirely outsides the image, return false |
330 return false; | 330 return false; |
331 } | 331 } |
332 | 332 |
333 const int sampleSize = this->getSampleSize(); | 333 const int sampleSize = this->getSampleSize(); |
334 SkScaledBitmapSampler sampler(rect.width(), rect.height(), sampleSize); | 334 SkScaledBitmapSampler sampler(rect.width(), rect.height(), sampleSize); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 return SkImageDecoder::kUnknown_Format; | 595 return SkImageDecoder::kUnknown_Format; |
596 } | 596 } |
597 | 597 |
598 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { | 598 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { |
599 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; | 599 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; |
600 } | 600 } |
601 | 601 |
602 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); | 602 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); |
603 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_webp
); | 603 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_webp
); |
604 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact
ory); | 604 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact
ory); |
OLD | NEW |