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

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

Issue 2328663002: Revert of Checking for valid colorType, alphaType, colorSpace in SkCodec (Closed)
Patch Set: Created 4 years, 3 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/SkRawCodec.cpp ('k') | tests/CodecTest.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 "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkColorSpaceXform.h" 9 #include "SkColorSpaceXform.h"
10 #include "SkWebpCodec.h" 10 #include "SkWebpCodec.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 break; 137 break;
138 default: 138 default:
139 return nullptr; 139 return nullptr;
140 } 140 }
141 141
142 SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8); 142 SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8);
143 return new SkWebpCodec(features.width, features.height, info, std::move(colo rSpace), 143 return new SkWebpCodec(features.width, features.height, info, std::move(colo rSpace),
144 streamDeleter.release(), demux.release(), std::move(d ata)); 144 streamDeleter.release(), demux.release(), std::move(d ata));
145 } 145 }
146 146
147 static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src,
148 SkColorSpaceXform* colorXform) {
149 if (!valid_alpha(dst.alphaType(), src.alphaType())) {
150 return false;
151 }
152
153 switch (dst.colorType()) {
154 case kRGBA_F16_SkColorType:
155 return nullptr != colorXform;
156 case kBGRA_8888_SkColorType:
157 case kRGBA_8888_SkColorType:
158 return true;
159 case kRGB_565_SkColorType:
160 return nullptr == colorXform && src.alphaType() == kOpaque_SkAlphaTy pe;
161 default:
162 return false;
163 }
164 }
165
147 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const { 166 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const {
148 SkISize dim = this->getInfo().dimensions(); 167 SkISize dim = this->getInfo().dimensions();
149 // SkCodec treats zero dimensional images as errors, so the minimum size 168 // SkCodec treats zero dimensional images as errors, so the minimum size
150 // that we will recommend is 1x1. 169 // that we will recommend is 1x1.
151 dim.fWidth = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fWidth)); 170 dim.fWidth = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fWidth));
152 dim.fHeight = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fHeight)); 171 dim.fHeight = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fHeight));
153 return dim; 172 return dim;
154 } 173 }
155 174
156 bool SkWebpCodec::onDimensionsSupported(const SkISize& dim) { 175 bool SkWebpCodec::onDimensionsSupported(const SkISize& dim) {
(...skipping 29 matching lines...) Expand all
186 // decode this exact subset. 205 // decode this exact subset.
187 // Leave right and bottom unmodified, so we suggest a slightly larger subset than requested. 206 // Leave right and bottom unmodified, so we suggest a slightly larger subset than requested.
188 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; 207 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1;
189 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; 208 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1;
190 return true; 209 return true;
191 } 210 }
192 211
193 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, 212 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
194 const Options& options, SkPMColor*, int *, 213 const Options& options, SkPMColor*, int *,
195 int* rowsDecodedPtr) { 214 int* rowsDecodedPtr) {
196 if (!conversion_possible(dstInfo, this->getInfo())) {
197 return kInvalidConversion;
198 }
199 215
200 std::unique_ptr<SkColorSpaceXform> colorXform = nullptr; 216 std::unique_ptr<SkColorSpaceXform> colorXform = nullptr;
201 if (needs_color_xform(dstInfo, this->getInfo())) { 217 if (needs_color_xform(dstInfo, this->getInfo())) {
202 colorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace ()), 218 colorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace ()),
203 sk_ref_sp(dstInfo.colorSpace())); 219 sk_ref_sp(dstInfo.colorSpace()));
204 SkASSERT(colorXform); 220 }
221
222 if (!webp_conversion_possible(dstInfo, this->getInfo(), colorXform.get())) {
223 return kInvalidConversion;
205 } 224 }
206 225
207 WebPDecoderConfig config; 226 WebPDecoderConfig config;
208 if (0 == WebPInitDecoderConfig(&config)) { 227 if (0 == WebPInitDecoderConfig(&config)) {
209 // ABI mismatch. 228 // ABI mismatch.
210 // FIXME: New enum for this? 229 // FIXME: New enum for this?
211 return kInvalidInput; 230 return kInvalidInput;
212 } 231 }
213 232
214 // Free any memory associated with the buffer. Must be called last, so we de clare it first. 233 // Free any memory associated with the buffer. Must be called last, so we de clare it first.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return result; 341 return result;
323 } 342 }
324 343
325 SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info, 344 SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info,
326 sk_sp<SkColorSpace> colorSpace, SkStream* stream, WebPD emuxer* demux, 345 sk_sp<SkColorSpace> colorSpace, SkStream* stream, WebPD emuxer* demux,
327 sk_sp<SkData> data) 346 sk_sp<SkData> data)
328 : INHERITED(width, height, info, stream, std::move(colorSpace)) 347 : INHERITED(width, height, info, stream, std::move(colorSpace))
329 , fDemux(demux) 348 , fDemux(demux)
330 , fData(std::move(data)) 349 , fData(std::move(data))
331 {} 350 {}
OLDNEW
« no previous file with comments | « src/codec/SkRawCodec.cpp ('k') | tests/CodecTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698