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

Side by Side Diff: src/core/SkBitmap.cpp

Issue 1703013002: misc fixes to make float buffers work a little better (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | src/core/SkBlitter.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 * 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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 break; 556 break;
557 default: 557 default:
558 SkDEBUGFAIL("Can't return addr for config"); 558 SkDEBUGFAIL("Can't return addr for config");
559 base = nullptr; 559 base = nullptr;
560 break; 560 break;
561 } 561 }
562 } 562 }
563 return base; 563 return base;
564 } 564 }
565 565
566 #include "SkHalf.h"
567
566 SkColor SkBitmap::getColor(int x, int y) const { 568 SkColor SkBitmap::getColor(int x, int y) const {
567 SkASSERT((unsigned)x < (unsigned)this->width()); 569 SkASSERT((unsigned)x < (unsigned)this->width());
568 SkASSERT((unsigned)y < (unsigned)this->height()); 570 SkASSERT((unsigned)y < (unsigned)this->height());
569 571
570 switch (this->colorType()) { 572 switch (this->colorType()) {
571 case kGray_8_SkColorType: { 573 case kGray_8_SkColorType: {
572 uint8_t* addr = this->getAddr8(x, y); 574 uint8_t* addr = this->getAddr8(x, y);
573 return SkColorSetRGB(*addr, *addr, *addr); 575 return SkColorSetRGB(*addr, *addr, *addr);
574 } 576 }
575 case kAlpha_8_SkColorType: { 577 case kAlpha_8_SkColorType: {
(...skipping 16 matching lines...) Expand all
592 case kBGRA_8888_SkColorType: { 594 case kBGRA_8888_SkColorType: {
593 uint32_t* addr = this->getAddr32(x, y); 595 uint32_t* addr = this->getAddr32(x, y);
594 SkPMColor c = SkSwizzle_BGRA_to_PMColor(addr[0]); 596 SkPMColor c = SkSwizzle_BGRA_to_PMColor(addr[0]);
595 return SkUnPreMultiply::PMColorToColor(c); 597 return SkUnPreMultiply::PMColorToColor(c);
596 } 598 }
597 case kRGBA_8888_SkColorType: { 599 case kRGBA_8888_SkColorType: {
598 uint32_t* addr = this->getAddr32(x, y); 600 uint32_t* addr = this->getAddr32(x, y);
599 SkPMColor c = SkSwizzle_RGBA_to_PMColor(addr[0]); 601 SkPMColor c = SkSwizzle_RGBA_to_PMColor(addr[0]);
600 return SkUnPreMultiply::PMColorToColor(c); 602 return SkUnPreMultiply::PMColorToColor(c);
601 } 603 }
604 case kRGBA_F16_SkColorType: {
605 const uint64_t* addr = (const uint64_t*)fPixels + y * (fRowBytes >> 3) + x;
606 Sk4f p4 = SkHalfToFloat_01(addr[0]);
607 if (p4[3]) {
608 float inva = 1 / p4[3];
609 p4 = p4 * Sk4f(inva, inva, inva, 1);
610 }
611 SkColor c;
612 SkNx_cast<uint8_t>(p4 * Sk4f(255) + Sk4f(0.5f)).store(&c);
613 // p4 is RGBA, but we want BGRA, so we need to swap next
614 return SkSwizzle_RB(c);
615 }
602 default: 616 default:
603 SkASSERT(false); 617 SkASSERT(false);
604 return 0; 618 return 0;
605 } 619 }
606 SkASSERT(false); // Not reached. 620 SkASSERT(false); // Not reached.
607 return 0; 621 return 0;
608 } 622 }
609 623
610 static bool compute_is_opaque(const SkPixmap& pmap) { 624 static bool compute_is_opaque(const SkPixmap& pmap) {
611 const int height = pmap.height(); 625 const int height = pmap.height();
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 /////////////////////////////////////////////////////////////////////////////// 1351 ///////////////////////////////////////////////////////////////////////////////
1338 1352
1339 #ifdef SK_DEBUG 1353 #ifdef SK_DEBUG
1340 void SkImageInfo::validate() const { 1354 void SkImageInfo::validate() const {
1341 SkASSERT(fWidth >= 0); 1355 SkASSERT(fWidth >= 0);
1342 SkASSERT(fHeight >= 0); 1356 SkASSERT(fHeight >= 0);
1343 SkASSERT(SkColorTypeIsValid(fColorType)); 1357 SkASSERT(SkColorTypeIsValid(fColorType));
1344 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); 1358 SkASSERT(SkAlphaTypeIsValid(fAlphaType));
1345 } 1359 }
1346 #endif 1360 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkBlitter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698