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

Side by Side Diff: src/codec/SkWebpCodec.cpp

Issue 1220733013: SkCodec no longer inherits from SkImageGenerator. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Manually handle the lifetime of fScanlineDecoder. Created 5 years, 5 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/codec/SkSwizzler.cpp ('k') | tests/CodexTest.cpp » ('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 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkWebpCodec.h" 8 #include "SkWebpCodec.h"
9 #include "SkImageGenerator.h"
10 #include "SkTemplates.h" 9 #include "SkTemplates.h"
11 10
12 // A WebP decoder on top of (subset of) libwebp 11 // A WebP decoder on top of (subset of) libwebp
13 // For more information on WebP image format, and libwebp library, see: 12 // For more information on WebP image format, and libwebp library, see:
14 // https://code.google.com/speed/webp/ 13 // https://code.google.com/speed/webp/
15 // http://www.webmproject.org/code/#libwebp-webp-image-library 14 // http://www.webmproject.org/code/#libwebp-webp-image-library
16 // https://chromium.googlesource.com/webm/libwebp 15 // https://chromium.googlesource.com/webm/libwebp
17 16
18 // If moving libwebp out of skia source tree, path for webp headers must be 17 // If moving libwebp out of skia source tree, path for webp headers must be
19 // updated accordingly. Here, we enforce using local copy in webp sub-directory. 18 // updated accordingly. Here, we enforce using local copy in webp sub-directory.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 return false; 55 return false;
57 } 56 }
58 // now check that if we are 4-bytes per pixel, we also don't overflow 57 // now check that if we are 4-bytes per pixel, we also don't overflow
59 if (sk_64_asS32(size) > (0x7FFFFFFF >> 2)) { 58 if (sk_64_asS32(size) > (0x7FFFFFFF >> 2)) {
60 return false; 59 return false;
61 } 60 }
62 } 61 }
63 62
64 if (info) { 63 if (info) {
65 // FIXME: Is N32 the right type? 64 // FIXME: Is N32 the right type?
66 // Is unpremul the right type? Clients of SkImageGenerator may assume it 's the 65 // Is unpremul the right type? Clients of SkCodec may assume it's the
67 // best type, when Skia currently cannot draw unpremul (and raster is fa ster 66 // best type, when Skia currently cannot draw unpremul (and raster is fa ster
68 // with premul). 67 // with premul).
69 *info = SkImageInfo::Make(features.width, features.height, kN32_SkColorT ype, 68 *info = SkImageInfo::Make(features.width, features.height, kN32_SkColorT ype,
70 SkToBool(features.has_alpha) ? kUnpremul_SkAlp haType 69 SkToBool(features.has_alpha) ? kUnpremul_SkAlp haType
71 : kOpaque_SkAlphaT ype); 70 : kOpaque_SkAlphaT ype);
72 } 71 }
73 return true; 72 return true;
74 } 73 }
75 74
76 SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { 75 SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 default: 118 default:
120 return MODE_LAST; 119 return MODE_LAST;
121 } 120 }
122 } 121 }
123 122
124 // The WebP decoding API allows us to incrementally pass chunks of bytes as we r eceive them to the 123 // The WebP decoding API allows us to incrementally pass chunks of bytes as we r eceive them to the
125 // decoder with WebPIAppend. In order to do so, we need to read chunks from the SkStream. This size 124 // decoder with WebPIAppend. In order to do so, we need to read chunks from the SkStream. This size
126 // is arbitrary. 125 // is arbitrary.
127 static const size_t BUFFER_SIZE = 4096; 126 static const size_t BUFFER_SIZE = 4096;
128 127
129 SkImageGenerator::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, vo id* dst, 128 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
130 size_t rowBytes, const Options &, SkPMColor*, 129 const Options&, SkPMColor*, int*) {
131 int*) {
132 switch (this->rewindIfNeeded()) { 130 switch (this->rewindIfNeeded()) {
133 case kCouldNotRewind_RewindState: 131 case kCouldNotRewind_RewindState:
134 return kCouldNotRewind; 132 return kCouldNotRewind;
135 case kRewound_RewindState: 133 case kRewound_RewindState:
136 // Rewound to the beginning. Since creation only does a peek, the st ream is at the 134 // Rewound to the beginning. Since creation only does a peek, the st ream is at the
137 // correct position. 135 // correct position.
138 break; 136 break;
139 case kNoRewindNecessary_RewindState: 137 case kNoRewindNecessary_RewindState:
140 // Already at the right spot for decoding. 138 // Already at the right spot for decoding.
141 break; 139 break;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Break out of the switch statement. Continue the loop. 191 // Break out of the switch statement. Continue the loop.
194 break; 192 break;
195 default: 193 default:
196 return kInvalidInput; 194 return kInvalidInput;
197 } 195 }
198 } 196 }
199 } 197 }
200 198
201 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) 199 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream)
202 : INHERITED(info, stream) {} 200 : INHERITED(info, stream) {}
OLDNEW
« no previous file with comments | « src/codec/SkSwizzler.cpp ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698