 Chromium Code Reviews
 Chromium Code Reviews Issue 25275004:
  store SkAlphaType inside SkBitmap, on road to support unpremul  (Closed) 
  Base URL: https://skia.googlecode.com/svn/trunk
    
  
    Issue 25275004:
  store SkAlphaType inside SkBitmap, on road to support unpremul  (Closed) 
  Base URL: https://skia.googlecode.com/svn/trunk| OLD | NEW | 
|---|---|
| 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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 if (reallyHasAlpha && this->getRequireUnpremultipliedColors() && | 459 if (reallyHasAlpha && this->getRequireUnpremultipliedColors() && | 
| 460 SkBitmap::kARGB_8888_Config != decodedBitmap->config()) { | 460 SkBitmap::kARGB_8888_Config != decodedBitmap->config()) { | 
| 461 // If the caller wants an unpremultiplied bitmap, and we let them get | 461 // If the caller wants an unpremultiplied bitmap, and we let them get | 
| 462 // away with a config other than 8888, and it has alpha after all, | 462 // away with a config other than 8888, and it has alpha after all, | 
| 463 // return false, since the result will have premultiplied colors. | 463 // return false, since the result will have premultiplied colors. | 
| 464 return false; | 464 return false; | 
| 465 } | 465 } | 
| 466 if (SkBitmap::kA8_Config == decodedBitmap->config()) { | 466 if (SkBitmap::kA8_Config == decodedBitmap->config()) { | 
| 467 reallyHasAlpha = true; | 467 reallyHasAlpha = true; | 
| 468 } | 468 } | 
| 469 decodedBitmap->setIsOpaque(!reallyHasAlpha); | 469 | 
| 470 SkAlphaType alphaType = kOpaque_SkAlphaType; | |
| 471 if (reallyHasAlpha) { | |
| 472 if (this->getRequireUnpremultipliedColors()) { | |
| 473 alphaType = kUnpremul_SkAlphaType; | |
| 474 } else { | |
| 475 alphaType = kPremul_SkAlphaType; | |
| 476 } | |
| 477 } | |
| 478 decodedBitmap->setAlphaType(alphaType); | |
| 470 return true; | 479 return true; | 
| 471 } | 480 } | 
| 472 | 481 | 
| 473 | 482 | 
| 474 | 483 | 
| 475 bool SkPNGImageDecoder::getBitmapConfig(png_structp png_ptr, png_infop info_ptr, | 484 bool SkPNGImageDecoder::getBitmapConfig(png_structp png_ptr, png_infop info_ptr, | 
| 476 SkBitmap::Config* SK_RESTRICT configp, | 485 SkBitmap::Config* SK_RESTRICT configp, | 
| 477 bool* SK_RESTRICT hasAlphap, | 486 bool* SK_RESTRICT hasAlphap, | 
| 478 SkPMColor* SK_RESTRICT theTranspColorp) { | 487 SkPMColor* SK_RESTRICT theTranspColorp) { | 
| 479 png_uint_32 origWidth, origHeight; | 488 png_uint_32 origWidth, origHeight; | 
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 } | 941 } | 
| 933 } | 942 } | 
| 934 } | 943 } | 
| 935 | 944 | 
| 936 if (0 != theTranspColor) { | 945 if (0 != theTranspColor) { | 
| 937 reallyHasAlpha |= substituteTranspColor(&decodedBitmap, theTranspColor); | 946 reallyHasAlpha |= substituteTranspColor(&decodedBitmap, theTranspColor); | 
| 938 } | 947 } | 
| 939 if (SkBitmap::kA8_Config == decodedBitmap.config()) { | 948 if (SkBitmap::kA8_Config == decodedBitmap.config()) { | 
| 940 reallyHasAlpha = true; | 949 reallyHasAlpha = true; | 
| 941 } | 950 } | 
| 942 decodedBitmap.setIsOpaque(!reallyHasAlpha); | 951 decodedBitmap.setAlphaType(reallyHasAlpha ? kPremul_SkAlphaType : kOpaque_Sk AlphaType); | 
| 
scroggo
2013/10/18 19:32:40
This should also check for getRequireUnpremultipli
 | |
| 943 | 952 | 
| 944 if (swapOnly) { | 953 if (swapOnly) { | 
| 945 bm->swap(decodedBitmap); | 954 bm->swap(decodedBitmap); | 
| 946 return true; | 955 return true; | 
| 947 } | 956 } | 
| 948 return this->cropBitmap(bm, &decodedBitmap, sampleSize, region.x(), region.y (), | 957 return this->cropBitmap(bm, &decodedBitmap, sampleSize, region.x(), region.y (), | 
| 949 region.width(), region.height(), 0, rect.y()); | 958 region.width(), region.height(), 0, rect.y()); | 
| 950 } | 959 } | 
| 951 #endif | 960 #endif | 
| 952 | 961 | 
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1247 return SkImageDecoder::kUnknown_Format; | 1256 return SkImageDecoder::kUnknown_Format; | 
| 1248 } | 1257 } | 
| 1249 | 1258 | 
| 1250 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { | 1259 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { | 
| 1251 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; | 1260 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; | 
| 1252 } | 1261 } | 
| 1253 | 1262 | 
| 1254 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); | 1263 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); | 
| 1255 static SkImageDecoder_FormatReg gFormatReg(get_format_png); | 1264 static SkImageDecoder_FormatReg gFormatReg(get_format_png); | 
| 1256 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); | 1265 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); | 
| OLD | NEW |