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

Side by Side Diff: src/images/SkImageDecoder_libpng.cpp

Issue 167763003: Fix issue in image decoders where the bitmap config was not properly set. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: comments Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/images/SkImageRef.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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 SkPMColor theTranspColor = 0; // 0 tells us not to try to match 326 SkPMColor theTranspColor = 0; // 0 tells us not to try to match
327 327
328 if (!this->getBitmapConfig(png_ptr, info_ptr, &config, &hasAlpha, &theTransp Color)) { 328 if (!this->getBitmapConfig(png_ptr, info_ptr, &config, &hasAlpha, &theTransp Color)) {
329 return false; 329 return false;
330 } 330 }
331 331
332 const int sampleSize = this->getSampleSize(); 332 const int sampleSize = this->getSampleSize();
333 SkScaledBitmapSampler sampler(origWidth, origHeight, sampleSize); 333 SkScaledBitmapSampler sampler(origWidth, origHeight, sampleSize);
334 decodedBitmap->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight ()); 334 decodedBitmap->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight ());
335 335
336 // we should communicate alphaType, even if we early-return in bounds-only-m ode.
337 if (this->getRequireUnpremultipliedColors()) {
338 decodedBitmap->setAlphaType(kUnpremul_SkAlphaType);
339 }
340
336 if (SkImageDecoder::kDecodeBounds_Mode == mode) { 341 if (SkImageDecoder::kDecodeBounds_Mode == mode) {
337 return true; 342 return true;
338 } 343 }
339 344
340 // from here down we are concerned with colortables and pixels 345 // from here down we are concerned with colortables and pixels
341 346
342 // we track if we actually see a non-opaque pixels, since sometimes a PNG se ts its colortype 347 // we track if we actually see a non-opaque pixels, since sometimes a PNG se ts its colortype
343 // to |= PNG_COLOR_MASK_ALPHA, but all of its pixels are in fact opaque. We care, since we 348 // to |= PNG_COLOR_MASK_ALPHA, but all of its pixels are in fact opaque. We care, since we
344 // draw lots faster if we can flag the bitmap has being opaque 349 // draw lots faster if we can flag the bitmap has being opaque
345 bool reallyHasAlpha = false; 350 bool reallyHasAlpha = false;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 return false; 476 return false;
472 default: { 477 default: {
473 // Fall through to finish the decode. This config either 478 // Fall through to finish the decode. This config either
474 // supports unpremul or it is irrelevant because it has no 479 // supports unpremul or it is irrelevant because it has no
475 // alpha (or only alpha). 480 // alpha (or only alpha).
476 // These brackets prevent a warning. 481 // These brackets prevent a warning.
477 } 482 }
478 } 483 }
479 } 484 }
480 485
481 SkAlphaType alphaType = kOpaque_SkAlphaType; 486 if (!reallyHasAlpha) {
482 if (reallyHasAlpha) { 487 decodedBitmap->setAlphaType(kOpaque_SkAlphaType);
483 if (this->getRequireUnpremultipliedColors()) {
484 alphaType = kUnpremul_SkAlphaType;
485 } else {
486 alphaType = kPremul_SkAlphaType;
487 }
488 } 488 }
489 decodedBitmap->setAlphaType(alphaType);
490 return true; 489 return true;
491 } 490 }
492 491
493 492
494 493
495 bool SkPNGImageDecoder::getBitmapConfig(png_structp png_ptr, png_infop info_ptr, 494 bool SkPNGImageDecoder::getBitmapConfig(png_structp png_ptr, png_infop info_ptr,
496 SkBitmap::Config* SK_RESTRICT configp, 495 SkBitmap::Config* SK_RESTRICT configp,
497 bool* SK_RESTRICT hasAlphap, 496 bool* SK_RESTRICT hasAlphap,
498 SkPMColor* SK_RESTRICT theTranspColorp) { 497 SkPMColor* SK_RESTRICT theTranspColorp) {
499 png_uint_32 origWidth, origHeight; 498 png_uint_32 origWidth, origHeight;
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 return SkImageDecoder::kUnknown_Format; 1287 return SkImageDecoder::kUnknown_Format;
1289 } 1288 }
1290 1289
1291 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { 1290 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) {
1292 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; 1291 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL;
1293 } 1292 }
1294 1293
1295 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); 1294 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory);
1296 static SkImageDecoder_FormatReg gFormatReg(get_format_png); 1295 static SkImageDecoder_FormatReg gFormatReg(get_format_png);
1297 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); 1296 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory);
OLDNEW
« no previous file with comments | « no previous file | src/images/SkImageRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698