add SkColorSpace param to SkPixmap::erase()
We don't have a way to erase with a non-sRGB color. Update the P3 gm to test this, removing the SkBitmap erase case where there's no option for even an SkColor4f, let alone non-sRGB. I'm not sure it's really important to have one when we've got this on pixmap. Updated release notes. Change-Id: Ie98270d3f83e041593b4c6b2da8e325b36d4ff18 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/285341 Commit-Queue: Mike Klein <mtklein@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
13b6cf697f
commit
d5cba9d000
@ -8,6 +8,12 @@ Milestone 84
|
||||
|
||||
* <insert new release note here>
|
||||
|
||||
* SkBitmap and SkPixmap's erase() methods now treat their color parameters
|
||||
consistently with the rest of Skia, with all SkColors and any untagged
|
||||
SkColor4fs interpreted as sRGB, not as a color in the bitmap's color space.
|
||||
SkPixmap::erase(SkColor4f) now takes an SkColorSpace, so you can pass
|
||||
pixmap.colorSpace() if you want the old behavior.
|
||||
|
||||
* SkCamera.h and SkMatrix44.h are DEPRECATED.
|
||||
Use SkM44 if you want to have 3d transformations.
|
||||
|
||||
|
19
gm/p3.cpp
19
gm/p3.cpp
@ -152,21 +152,6 @@ DEF_SIMPLE_GM(p3, canvas, 450, 1300) {
|
||||
|
||||
canvas->translate(0,80);
|
||||
|
||||
// Draw a P3 red bitmap, using SkBitmap::eraseColor().
|
||||
{
|
||||
SkBitmap bm;
|
||||
bm.allocPixels(SkImageInfo::Make(60,60, kRGBA_F16_SkColorType, kPremul_SkAlphaType, p3));
|
||||
|
||||
bm.eraseColor(0xffff0000/*in P3*/);
|
||||
|
||||
canvas->drawBitmap(bm, 10,10);
|
||||
compare_pixel("drawBitmap P3 red, from SkBitmap::eraseColor()",
|
||||
canvas, 10,10,
|
||||
{1,0,0,1}, p3.get());
|
||||
}
|
||||
|
||||
canvas->translate(0,80);
|
||||
|
||||
// Draw a P3 red bitmap, using SkPixmap::erase().
|
||||
{
|
||||
SkBitmap bm;
|
||||
@ -175,7 +160,7 @@ DEF_SIMPLE_GM(p3, canvas, 450, 1300) {
|
||||
// At the moment only SkPixmap has an erase() that takes an SkColor4f.
|
||||
SkPixmap pm;
|
||||
SkAssertResult(bm.peekPixels(&pm));
|
||||
SkAssertResult(pm.erase({1,0,0,1} /*in p3*/));
|
||||
SkAssertResult(pm.erase({1,0,0,1}, p3.get()));
|
||||
|
||||
canvas->drawBitmap(bm, 10,10);
|
||||
compare_pixel("drawBitmap P3 red, from SkPixmap::erase",
|
||||
@ -193,7 +178,7 @@ DEF_SIMPLE_GM(p3, canvas, 450, 1300) {
|
||||
// At the moment only SkPixmap has an erase() that takes an SkColor4f.
|
||||
SkPixmap pm;
|
||||
SkAssertResult(bm.peekPixels(&pm));
|
||||
SkAssertResult(pm.erase({1,0,0,1} /*in p3*/));
|
||||
SkAssertResult(pm.erase({1,0,0,1}, p3.get()));
|
||||
|
||||
SkPaint paint;
|
||||
paint.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
|
||||
|
@ -700,7 +700,21 @@ public:
|
||||
|
||||
example: https://fiddle.skia.org/c/@Pixmap_erase_3
|
||||
*/
|
||||
bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const;
|
||||
bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const {
|
||||
return this->erase(color, nullptr, subset);
|
||||
}
|
||||
|
||||
/** Writes color to pixels bounded by subset; returns true on success.
|
||||
if subset is nullptr, writes colors pixels inside bounds(). Returns false if
|
||||
colorType() is kUnknown_SkColorType, if subset is not nullptr and does
|
||||
not intersect bounds(), or if subset is nullptr and bounds() is empty.
|
||||
|
||||
@param color unpremultiplied color to write
|
||||
@param cs SkColorSpace of color
|
||||
@param subset bounding integer SkRect of pixels to write; may be nullptr
|
||||
@return true if pixels are changed
|
||||
*/
|
||||
bool erase(const SkColor4f& color, SkColorSpace* cs, const SkIRect* subset = nullptr) const;
|
||||
|
||||
private:
|
||||
const void* fPixels;
|
||||
|
@ -174,10 +174,10 @@ bool SkPixmap::erase(SkColor color, const SkIRect& subset) const {
|
||||
return this->erase(SkColor4f::FromColor(color), &subset);
|
||||
}
|
||||
|
||||
bool SkPixmap::erase(const SkColor4f& color, const SkIRect* subset) const {
|
||||
bool SkPixmap::erase(const SkColor4f& color, SkColorSpace* cs, const SkIRect* subset) const {
|
||||
SkPaint paint;
|
||||
paint.setBlendMode(SkBlendMode::kSrc);
|
||||
paint.setColor4f(color, nullptr);
|
||||
paint.setColor4f(color, cs);
|
||||
|
||||
SkIRect clip = this->bounds();
|
||||
if (subset && !clip.intersect(*subset)) {
|
||||
|
Loading…
Reference in New Issue
Block a user