Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: src/images/SkImageDecoder_libwebp.cpp

Issue 849103004: Make SkStream *not* ref counted. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase, just in case. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/images/SkImageDecoder_libpng.cpp ('k') | src/images/SkJpegUtility.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 if (sk_64_asS32(size) > (0x7FFFFFFF >> 2)) { 88 if (sk_64_asS32(size) > (0x7FFFFFFF >> 2)) {
89 return false; 89 return false;
90 } 90 }
91 } 91 }
92 return true; 92 return true;
93 } 93 }
94 94
95 class SkWEBPImageDecoder: public SkImageDecoder { 95 class SkWEBPImageDecoder: public SkImageDecoder {
96 public: 96 public:
97 SkWEBPImageDecoder() { 97 SkWEBPImageDecoder() {
98 fInputStream = NULL;
99 fOrigWidth = 0; 98 fOrigWidth = 0;
100 fOrigHeight = 0; 99 fOrigHeight = 0;
101 fHasAlpha = 0; 100 fHasAlpha = 0;
102 } 101 }
103 virtual ~SkWEBPImageDecoder() {
104 SkSafeUnref(fInputStream);
105 }
106 102
107 Format getFormat() const SK_OVERRIDE { 103 Format getFormat() const SK_OVERRIDE {
108 return kWEBP_Format; 104 return kWEBP_Format;
109 } 105 }
110 106
111 protected: 107 protected:
112 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) S K_OVERRIDE; 108 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) S K_OVERRIDE;
113 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) SK_OVERRIDE; 109 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) SK_OVERRIDE;
114 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; 110 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE;
115 111
116 private: 112 private:
117 /** 113 /**
118 * Called when determining the output config to request to webp. 114 * Called when determining the output config to request to webp.
119 * If the image does not have alpha, there is no need to premultiply. 115 * If the image does not have alpha, there is no need to premultiply.
120 * If the caller wants unpremultiplied colors, that is respected. 116 * If the caller wants unpremultiplied colors, that is respected.
121 */ 117 */
122 bool shouldPremultiply() const { 118 bool shouldPremultiply() const {
123 return SkToBool(fHasAlpha) && !this->getRequireUnpremultipliedColors(); 119 return SkToBool(fHasAlpha) && !this->getRequireUnpremultipliedColors();
124 } 120 }
125 121
126 bool setDecodeConfig(SkBitmap* decodedBitmap, int width, int height); 122 bool setDecodeConfig(SkBitmap* decodedBitmap, int width, int height);
127 123
128 SkStream* fInputStream; 124 SkAutoTDelete<SkStream> fInputStream;
129 int fOrigWidth; 125 int fOrigWidth;
130 int fOrigHeight; 126 int fOrigHeight;
131 int fHasAlpha; 127 int fHasAlpha;
132 128
133 typedef SkImageDecoder INHERITED; 129 typedef SkImageDecoder INHERITED;
134 }; 130 };
135 131
136 ////////////////////////////////////////////////////////////////////////// 132 //////////////////////////////////////////////////////////////////////////
137 133
138 #ifdef TIME_DECODE 134 #ifdef TIME_DECODE
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 alphaType = kUnpremul_SkAlphaType; 305 alphaType = kUnpremul_SkAlphaType;
310 } else { 306 } else {
311 alphaType = kPremul_SkAlphaType; 307 alphaType = kPremul_SkAlphaType;
312 } 308 }
313 } 309 }
314 return decodedBitmap->setInfo(SkImageInfo::Make(width, height, colorType, al phaType)); 310 return decodedBitmap->setInfo(SkImageInfo::Make(width, height, colorType, al phaType));
315 } 311 }
316 312
317 bool SkWEBPImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, 313 bool SkWEBPImageDecoder::onBuildTileIndex(SkStreamRewindable* stream,
318 int *width, int *height) { 314 int *width, int *height) {
315 SkAutoTDelete<SkStreamRewindable> streamDeleter(stream);
319 int origWidth, origHeight, hasAlpha; 316 int origWidth, origHeight, hasAlpha;
320 if (!webp_parse_header(stream, &origWidth, &origHeight, &hasAlpha)) { 317 if (!webp_parse_header(stream, &origWidth, &origHeight, &hasAlpha)) {
321 return false; 318 return false;
322 } 319 }
323 320
324 if (!stream->rewind()) { 321 if (!stream->rewind()) {
325 SkDebugf("Failed to rewind webp stream!"); 322 SkDebugf("Failed to rewind webp stream!");
326 return false; 323 return false;
327 } 324 }
328 325
329 *width = origWidth; 326 *width = origWidth;
330 *height = origHeight; 327 *height = origHeight;
331 328
332 SkRefCnt_SafeAssign(this->fInputStream, stream); 329 this->fInputStream.reset(streamDeleter.detach());
333 this->fOrigWidth = origWidth; 330 this->fOrigWidth = origWidth;
334 this->fOrigHeight = origHeight; 331 this->fOrigHeight = origHeight;
335 this->fHasAlpha = hasAlpha; 332 this->fHasAlpha = hasAlpha;
336 333
337 return true; 334 return true;
338 } 335 }
339 336
340 static bool is_config_compatible(const SkBitmap& bitmap) { 337 static bool is_config_compatible(const SkBitmap& bitmap) {
341 const SkColorType ct = bitmap.colorType(); 338 const SkColorType ct = bitmap.colorType();
342 return ct == kARGB_4444_SkColorType || ct == kRGB_565_SkColorType || ct == k N32_SkColorType; 339 return ct == kARGB_4444_SkColorType || ct == kRGB_565_SkColorType || ct == k N32_SkColorType;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 return SkImageDecoder::kUnknown_Format; 670 return SkImageDecoder::kUnknown_Format;
674 } 671 }
675 672
676 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { 673 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) {
677 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL L; 674 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL L;
678 } 675 }
679 676
680 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); 677 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory);
681 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); 678 static SkImageDecoder_FormatReg gFormatReg(get_format_webp);
682 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); 679 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory);
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libpng.cpp ('k') | src/images/SkJpegUtility.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698