| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
| 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 "SkAtomics.h" | 8 #include "SkAtomics.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 SkPMColor c = SkSwizzle_BGRA_to_PMColor(addr[0]); | 594 SkPMColor c = SkSwizzle_BGRA_to_PMColor(addr[0]); |
| 595 return SkUnPreMultiply::PMColorToColor(c); | 595 return SkUnPreMultiply::PMColorToColor(c); |
| 596 } | 596 } |
| 597 case kRGBA_8888_SkColorType: { | 597 case kRGBA_8888_SkColorType: { |
| 598 uint32_t* addr = this->getAddr32(x, y); | 598 uint32_t* addr = this->getAddr32(x, y); |
| 599 SkPMColor c = SkSwizzle_RGBA_to_PMColor(addr[0]); | 599 SkPMColor c = SkSwizzle_RGBA_to_PMColor(addr[0]); |
| 600 return SkUnPreMultiply::PMColorToColor(c); | 600 return SkUnPreMultiply::PMColorToColor(c); |
| 601 } | 601 } |
| 602 case kRGBA_F16_SkColorType: { | 602 case kRGBA_F16_SkColorType: { |
| 603 const uint64_t* addr = (const uint64_t*)fPixels + y * (fRowBytes >>
3) + x; | 603 const uint64_t* addr = (const uint64_t*)fPixels + y * (fRowBytes >>
3) + x; |
| 604 Sk4f p4 = SkHalfToFloat_finite(addr[0]); | 604 Sk4f p4 = SkHalfToFloat_01(addr[0]); |
| 605 if (p4[3]) { | 605 if (p4[3]) { |
| 606 float inva = 1 / p4[3]; | 606 float inva = 1 / p4[3]; |
| 607 p4 = p4 * Sk4f(inva, inva, inva, 1); | 607 p4 = p4 * Sk4f(inva, inva, inva, 1); |
| 608 } | 608 } |
| 609 SkColor c; | 609 SkColor c; |
| 610 SkNx_cast<uint8_t>(p4 * Sk4f(255) + Sk4f(0.5f)).store(&c); | 610 SkNx_cast<uint8_t>(p4 * Sk4f(255) + Sk4f(0.5f)).store(&c); |
| 611 // p4 is RGBA, but we want BGRA, so we need to swap next | 611 // p4 is RGBA, but we want BGRA, so we need to swap next |
| 612 return SkSwizzle_RB(c); | 612 return SkSwizzle_RB(c); |
| 613 } | 613 } |
| 614 default: | 614 default: |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 | 1138 |
| 1139 bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) { | 1139 bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) { |
| 1140 const size_t snugRB = buffer->readUInt(); | 1140 const size_t snugRB = buffer->readUInt(); |
| 1141 if (0 == snugRB) { // no pixels | 1141 if (0 == snugRB) { // no pixels |
| 1142 return false; | 1142 return false; |
| 1143 } | 1143 } |
| 1144 | 1144 |
| 1145 SkImageInfo info; | 1145 SkImageInfo info; |
| 1146 info.unflatten(*buffer); | 1146 info.unflatten(*buffer); |
| 1147 | 1147 |
| 1148 // If there was an error reading "info" or if it is bogus, | 1148 // If there was an error reading "info" or if it is bogus, |
| 1149 // don't use it to compute minRowBytes() | 1149 // don't use it to compute minRowBytes() |
| 1150 if (!buffer->validate(SkColorTypeValidateAlphaType(info.colorType(), | 1150 if (!buffer->validate(SkColorTypeValidateAlphaType(info.colorType(), |
| 1151 info.alphaType()))) { | 1151 info.alphaType()))) { |
| 1152 return false; | 1152 return false; |
| 1153 } | 1153 } |
| 1154 | 1154 |
| 1155 const size_t ramRB = info.minRowBytes(); | 1155 const size_t ramRB = info.minRowBytes(); |
| 1156 const int height = SkMax32(info.height(), 0); | 1156 const int height = SkMax32(info.height(), 0); |
| 1157 const uint64_t snugSize = sk_64_mul(snugRB, height); | 1157 const uint64_t snugSize = sk_64_mul(snugRB, height); |
| 1158 const uint64_t ramSize = sk_64_mul(ramRB, height); | 1158 const uint64_t ramSize = sk_64_mul(ramRB, height); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 /////////////////////////////////////////////////////////////////////////////// | 1349 /////////////////////////////////////////////////////////////////////////////// |
| 1350 | 1350 |
| 1351 #ifdef SK_DEBUG | 1351 #ifdef SK_DEBUG |
| 1352 void SkImageInfo::validate() const { | 1352 void SkImageInfo::validate() const { |
| 1353 SkASSERT(fWidth >= 0); | 1353 SkASSERT(fWidth >= 0); |
| 1354 SkASSERT(fHeight >= 0); | 1354 SkASSERT(fHeight >= 0); |
| 1355 SkASSERT(SkColorTypeIsValid(fColorType)); | 1355 SkASSERT(SkColorTypeIsValid(fColorType)); |
| 1356 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1356 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
| 1357 } | 1357 } |
| 1358 #endif | 1358 #endif |
| OLD | NEW |