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

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

Issue 1240143002: Add the ability to decode a subset to SkCodec. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix line endings 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
« dm/DMSrcSink.cpp ('K') | « include/codec/SkCodec.h ('k') | no next file » | 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 "SkTemplates.h" 9 #include "SkTemplates.h"
10 10
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return MODE_LAST; 119 return MODE_LAST;
120 } 120 }
121 } 121 }
122 122
123 // 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
124 // 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
125 // is arbitrary. 125 // is arbitrary.
126 static const size_t BUFFER_SIZE = 4096; 126 static const size_t BUFFER_SIZE = 4096;
127 127
128 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, 128 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
129 const Options&, SkPMColor*, int*) { 129 const Options& options, SkPMColor*, int *) {
130 switch (this->rewindIfNeeded()) { 130 switch (this->rewindIfNeeded()) {
131 case kCouldNotRewind_RewindState: 131 case kCouldNotRewind_RewindState:
132 return kCouldNotRewind; 132 return kCouldNotRewind;
133 case kRewound_RewindState: 133 case kRewound_RewindState:
134 // 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
135 // correct position. 135 // correct position.
136 break; 136 break;
137 case kNoRewindNecessary_RewindState: 137 case kNoRewindNecessary_RewindState:
138 // Already at the right spot for decoding. 138 // Already at the right spot for decoding.
139 break; 139 break;
140 } 140 }
141 141
142 if (!conversion_possible(dstInfo, this->getInfo())) { 142 if (!conversion_possible(dstInfo, this->getInfo())) {
143 return kInvalidConversion; 143 return kInvalidConversion;
144 } 144 }
145 145
146 WebPDecoderConfig config; 146 WebPDecoderConfig config;
147 if (0 == WebPInitDecoderConfig(&config)) { 147 if (0 == WebPInitDecoderConfig(&config)) {
148 // ABI mismatch. 148 // ABI mismatch.
149 // FIXME: New enum for this? 149 // FIXME: New enum for this?
150 return kInvalidInput; 150 return kInvalidInput;
151 } 151 }
152 152
153 // Free any memory associated with the buffer. Must be called last, so we de clare it first. 153 // Free any memory associated with the buffer. Must be called last, so we de clare it first.
154 SkAutoTCallVProc<WebPDecBuffer, WebPFreeDecBuffer> autoFree(&(config.output) ); 154 SkAutoTCallVProc<WebPDecBuffer, WebPFreeDecBuffer> autoFree(&(config.output) );
155 155
156 SkISize dimensions = dstInfo.dimensions(); 156 SkIRect bounds = SkIRect::MakeSize(this->getInfo().dimensions());
157 if (this->getInfo().dimensions() != dimensions) { 157 if (!options.fSubset.isEmpty()) {
158 // Caller is requesting a subset.
159 if (!bounds.intersect(options.fSubset)) {
160 // The subset is out of bounds.
161 return kInvalidParameters;
162 }
163
164 // This is tricky. libwebp snaps the top and left to even values. Rather than claim we
165 // supported this, when we really did something different, report that we cannot
emmaleer 2015/07/17 22:31:05 What is the different thing we did, instead of cro
scroggo 2015/07/20 14:25:42 Done. Please take a look and let me know if you th
166 // handle it.
167 if (!SkIsAlign2(bounds.fLeft) || !SkIsAlign2(bounds.fTop)) {
168 return kInvalidParameters;
169 }
170
171 config.options.use_cropping = 1;
172 config.options.crop_left = bounds.fLeft;
173 config.options.crop_top = bounds.fTop;
174 config.options.crop_width = bounds.width();
175 config.options.crop_height = bounds.height();
176 }
177
178 SkISize dstDimensions = dstInfo.dimensions();
179 if (bounds.size() != dstDimensions) {
158 // Caller is requesting scaling. 180 // Caller is requesting scaling.
159 config.options.use_scaling = 1; 181 config.options.use_scaling = 1;
160 config.options.scaled_width = dimensions.width(); 182 config.options.scaled_width = dstDimensions.width();
161 config.options.scaled_height = dimensions.height(); 183 config.options.scaled_height = dstDimensions.height();
emmaleer 2015/07/17 22:31:05 Should we check that the width and height are bein
scroggo 2015/07/20 14:25:42 Not sure. As I understand it, libwebp allows scali
162 } 184 }
163 185
164 config.output.colorspace = webp_decode_mode(dstInfo.colorType(), 186 config.output.colorspace = webp_decode_mode(dstInfo.colorType(),
165 dstInfo.alphaType() == kPremul_SkAlphaType); 187 dstInfo.alphaType() == kPremul_SkAlphaType);
166 config.output.u.RGBA.rgba = (uint8_t*) dst; 188 config.output.u.RGBA.rgba = (uint8_t*) dst;
167 config.output.u.RGBA.stride = (int) rowBytes; 189 config.output.u.RGBA.stride = (int) rowBytes;
168 config.output.u.RGBA.size = dstInfo.getSafeSize(rowBytes); 190 config.output.u.RGBA.size = dstInfo.getSafeSize(rowBytes);
169 config.output.is_external_memory = 1; 191 config.output.is_external_memory = 1;
170 192
171 SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(NULL, 0, &confi g)); 193 SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(NULL, 0, &confi g));
(...skipping 19 matching lines...) Expand all
191 // Break out of the switch statement. Continue the loop. 213 // Break out of the switch statement. Continue the loop.
192 break; 214 break;
193 default: 215 default:
194 return kInvalidInput; 216 return kInvalidInput;
195 } 217 }
196 } 218 }
197 } 219 }
198 220
199 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) 221 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream)
200 : INHERITED(info, stream) {} 222 : INHERITED(info, stream) {}
OLDNEW
« dm/DMSrcSink.cpp ('K') | « include/codec/SkCodec.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698