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

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

Issue 1196643002: Prevent webp from producing 0 dimensional images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Added comment Created 5 years, 6 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 | « no previous file | 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 "SkImageGenerator.h" 9 #include "SkImageGenerator.h"
10 #include "SkTemplates.h" 10 #include "SkTemplates.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 if (dst.alphaType() == src.alphaType()) { 97 if (dst.alphaType() == src.alphaType()) {
98 return true; 98 return true;
99 } 99 }
100 return kPremul_SkAlphaType == dst.alphaType() && 100 return kPremul_SkAlphaType == dst.alphaType() &&
101 kUnpremul_SkAlphaType == src.alphaType(); 101 kUnpremul_SkAlphaType == src.alphaType();
102 } 102 }
103 103
104 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const { 104 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const {
105 SkISize dim = this->getInfo().dimensions(); 105 SkISize dim = this->getInfo().dimensions();
106 dim.fWidth = SkScalarRoundToInt(desiredScale * dim.fWidth); 106 // SkCodec treats zero dimensional images as errors, so the minimum size
107 dim.fHeight = SkScalarRoundToInt(desiredScale * dim.fHeight); 107 // that we will recommend is 1x1.
108 dim.fWidth = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fWidth));
109 dim.fHeight = SkTMax(1, SkScalarRoundToInt(desiredScale * dim.fHeight));
108 return dim; 110 return dim;
109 } 111 }
110 112
111 static WEBP_CSP_MODE webp_decode_mode(SkColorType ct, bool premultiply) { 113 static WEBP_CSP_MODE webp_decode_mode(SkColorType ct, bool premultiply) {
112 switch (ct) { 114 switch (ct) {
113 case kBGRA_8888_SkColorType: 115 case kBGRA_8888_SkColorType:
114 return premultiply ? MODE_bgrA : MODE_BGRA; 116 return premultiply ? MODE_bgrA : MODE_BGRA;
115 case kRGBA_8888_SkColorType: 117 case kRGBA_8888_SkColorType:
116 return premultiply ? MODE_rgbA : MODE_RGBA; 118 return premultiply ? MODE_rgbA : MODE_RGBA;
117 default: 119 default:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Break out of the switch statement. Continue the loop. 193 // Break out of the switch statement. Continue the loop.
192 break; 194 break;
193 default: 195 default:
194 return kInvalidInput; 196 return kInvalidInput;
195 } 197 }
196 } 198 }
197 } 199 }
198 200
199 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) 201 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream)
200 : INHERITED(info, stream) {} 202 : INHERITED(info, stream) {}
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698