OLD | NEW |
---|---|
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 "SkBmpCodec.h" | 8 #include "SkBmpCodec.h" |
9 #include "SkCodec_libico.h" | 9 #include "SkCodec_libico.h" |
10 #include "SkCodec_libpng.h" | 10 #include "SkCodec_libpng.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 , fEmbeddedCodecs(codecs) | 199 , fEmbeddedCodecs(codecs) |
200 {} | 200 {} |
201 | 201 |
202 /* | 202 /* |
203 * Chooses the best dimensions given the desired scale | 203 * Chooses the best dimensions given the desired scale |
204 */ | 204 */ |
205 SkISize SkIcoCodec::onGetScaledDimensions(float desiredScale) const { | 205 SkISize SkIcoCodec::onGetScaledDimensions(float desiredScale) const { |
206 // We set the dimensions to the largest candidate image by default. | 206 // We set the dimensions to the largest candidate image by default. |
207 // Regardless of the scale request, this is the largest image that we | 207 // Regardless of the scale request, this is the largest image that we |
208 // will decode. | 208 // will decode. |
209 if (desiredScale >= 1.0) { | |
210 return this->getInfo().dimensions(); | |
211 } | |
212 | |
213 int origWidth = this->getInfo().width(); | 209 int origWidth = this->getInfo().width(); |
214 int origHeight = this->getInfo().height(); | 210 int origHeight = this->getInfo().height(); |
215 float desiredSize = desiredScale * origWidth * origHeight; | 211 float desiredSize = desiredScale * origWidth * origHeight; |
216 // At least one image will have smaller error than this initial value | 212 // At least one image will have smaller error than this initial value |
217 float minError = ((float) (origWidth * origHeight)) - desiredSize + 1.0f; | 213 float minError = ((float) (origWidth * origHeight)) - desiredSize + 1.0f; |
218 int32_t minIndex = -1; | 214 int32_t minIndex = -1; |
219 for (int32_t i = 0; i < fEmbeddedCodecs->count(); i++) { | 215 for (int32_t i = 0; i < fEmbeddedCodecs->count(); i++) { |
220 int width = fEmbeddedCodecs->operator[](i)->getInfo().width(); | 216 int width = fEmbeddedCodecs->operator[](i)->getInfo().width(); |
221 int height = fEmbeddedCodecs->operator[](i)->getInfo().height(); | 217 int height = fEmbeddedCodecs->operator[](i)->getInfo().height(); |
222 float error = SkTAbs(((float) (width * height)) - desiredSize); | 218 float error = SkTAbs(((float) (width * height)) - desiredSize); |
223 if (error < minError) { | 219 if (error < minError) { |
224 minError = error; | 220 minError = error; |
225 minIndex = i; | 221 minIndex = i; |
226 } | 222 } |
227 } | 223 } |
228 SkASSERT(minIndex >= 0); | 224 SkASSERT(minIndex >= 0); |
229 | 225 |
230 return fEmbeddedCodecs->operator[](minIndex)->getInfo().dimensions(); | 226 return fEmbeddedCodecs->operator[](minIndex)->getInfo().dimensions(); |
231 } | 227 } |
232 | 228 |
229 bool SkIcoCodec::onDimensionsSupported(const SkISize& dim) { | |
msarett
2015/10/01 19:34:33
This is a bit redundant which I think is unfortuna
scroggo
2015/10/01 21:16:57
Agreed. Added a fixme.
| |
230 for (int32_t i = 0; i < fEmbeddedCodecs->count(); i++) { | |
231 if (fEmbeddedCodecs->operator[](i)->getInfo().dimensions() == dim) { | |
232 return true; | |
233 } | |
234 } | |
235 | |
236 return false; | |
237 } | |
238 | |
233 /* | 239 /* |
234 * Initiates the Ico decode | 240 * Initiates the Ico decode |
235 */ | 241 */ |
236 SkCodec::Result SkIcoCodec::onGetPixels(const SkImageInfo& dstInfo, | 242 SkCodec::Result SkIcoCodec::onGetPixels(const SkImageInfo& dstInfo, |
237 void* dst, size_t dstRowBytes, | 243 void* dst, size_t dstRowBytes, |
238 const Options& opts, SkPMColor* ct, | 244 const Options& opts, SkPMColor* ct, |
239 int* ptr) { | 245 int* ptr) { |
240 if (opts.fSubset) { | 246 if (opts.fSubset) { |
241 // Subsets are not supported. | 247 // Subsets are not supported. |
242 return kUnimplemented; | 248 return kUnimplemented; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 kInvalidScale == result) { | 285 kInvalidScale == result) { |
280 SkCodecPrintf("Warning: Attempt to decode candidate ico failed.\ n"); | 286 SkCodecPrintf("Warning: Attempt to decode candidate ico failed.\ n"); |
281 continue; | 287 continue; |
282 } | 288 } |
283 | 289 |
284 // On success or partial success, return the result | 290 // On success or partial success, return the result |
285 return result; | 291 return result; |
286 } | 292 } |
287 } | 293 } |
288 | 294 |
289 SkCodecPrintf("Error: No matching candidate image in ico.\n"); | 295 SkCodecPrintf("Error: No matching candidate image in ico.\n"); |
msarett
2015/10/01 19:34:34
Should we assert that this is never reached?
scroggo
2015/10/01 21:16:57
Done.
| |
290 return result; | 296 return result; |
291 } | 297 } |
OLD | NEW |