Treat all alpha-only images equally

We were inconsistent about special treatment for kAlpha_8 vs. other
alpha-only color types (other code paths were already adjusted).
Hopefully, we can remove this special behavior entirely, but as long
as we have this code, let's be somewhat principled.

Change-Id: I373a3c5e8c917d911b55b265631ca964c780a31d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/472996
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2021-11-17 14:58:27 -05:00 committed by SkCQ
parent f1660bf1ba
commit ddbe115d27
3 changed files with 11 additions and 8 deletions

View File

@ -6,6 +6,7 @@
*/ */
#include "include/core/SkColorSpace.h" #include "include/core/SkColorSpace.h"
#include "include/private/SkImageInfoPriv.h"
#include "src/core/SkArenaAlloc.h" #include "src/core/SkArenaAlloc.h"
#include "src/core/SkColorSpacePriv.h" #include "src/core/SkColorSpacePriv.h"
#include "src/core/SkColorSpaceXformSteps.h" #include "src/core/SkColorSpaceXformSteps.h"
@ -120,16 +121,16 @@ public:
SkRasterPipeline p(fAlloc); SkRasterPipeline p(fAlloc);
p.append_load(fSource.colorType(), &fSrcPtr); p.append_load(fSource.colorType(), &fSrcPtr);
if (fSource.colorType() == kAlpha_8_SkColorType) { if (SkColorTypeIsAlphaOnly(fSource.colorType())) {
// The color for A8 images comes from the (sRGB) paint color. // The color for A8 images comes from the (sRGB) paint color.
p.append_set_rgb(fAlloc, fPaintColor); p.append_set_rgb(fAlloc, fPaintColor);
p.append(SkRasterPipeline::premul); p.append(SkRasterPipeline::premul);
} }
if (auto dstCS = fDst.colorSpace()) { if (auto dstCS = fDst.colorSpace()) {
auto srcCS = fSource.colorSpace(); auto srcCS = fSource.colorSpace();
if (!srcCS || fSource.colorType() == kAlpha_8_SkColorType) { if (!srcCS || SkColorTypeIsAlphaOnly(fSource.colorType())) {
// We treat untagged images as sRGB. // We treat untagged images as sRGB.
// A8 images get their r,g,b from the paint color, so they're also sRGB. // Alpha-only images get their r,g,b from the paint color, so they're also sRGB.
srcCS = sk_srgb_singleton(); srcCS = sk_srgb_singleton();
} }
auto srcAT = fSource.isOpaque() ? kOpaque_SkAlphaType auto srcAT = fSource.isOpaque() ? kOpaque_SkAlphaType

View File

@ -17,6 +17,7 @@
#include "include/core/SkString.h" #include "include/core/SkString.h"
#include "include/core/SkStrokeRec.h" #include "include/core/SkStrokeRec.h"
#include "include/private/SkColorData.h" #include "include/private/SkColorData.h"
#include "include/private/SkImageInfoPriv.h"
#include "include/private/SkMacros.h" #include "include/private/SkMacros.h"
#include "include/private/SkTemplates.h" #include "include/private/SkTemplates.h"
#include "include/private/SkTo.h" #include "include/private/SkTo.h"
@ -968,8 +969,8 @@ void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix,
return; return;
} }
if (bitmap.colorType() != kAlpha_8_SkColorType if (!SkColorTypeIsAlphaOnly(bitmap.colorType()) &&
&& SkTreatAsSprite(matrix, bitmap.dimensions(), sampling, *paint)) { SkTreatAsSprite(matrix, bitmap.dimensions(), sampling, *paint)) {
// //
// It is safe to call lock pixels now, since we know the matrix is // It is safe to call lock pixels now, since we know the matrix is
// (more or less) identity. // (more or less) identity.

View File

@ -7,6 +7,7 @@
#include "src/shaders/SkImageShader.h" #include "src/shaders/SkImageShader.h"
#include "include/private/SkImageInfoPriv.h"
#include "src/core/SkArenaAlloc.h" #include "src/core/SkArenaAlloc.h"
#include "src/core/SkColorSpacePriv.h" #include "src/core/SkColorSpacePriv.h"
#include "src/core/SkColorSpaceXformSteps.h" #include "src/core/SkColorSpaceXformSteps.h"
@ -317,7 +318,7 @@ sk_sp<SkShader> SkMakeBitmapShaderForPaint(const SkPaint& paint, const SkBitmap&
if (!s) { if (!s) {
return nullptr; return nullptr;
} }
if (src.colorType() == kAlpha_8_SkColorType && paint.getShader()) { if (SkColorTypeIsAlphaOnly(src.colorType()) && paint.getShader()) {
// Compose the image shader with the paint's shader. Alpha images+shaders should output the // Compose the image shader with the paint's shader. Alpha images+shaders should output the
// texture's alpha multiplied by the shader's color. DstIn (d*sa) will achieve this with // texture's alpha multiplied by the shader's color. DstIn (d*sa) will achieve this with
// the source image and dst shader (MakeBlend takes dst first, src second). // the source image and dst shader (MakeBlend takes dst first, src second).
@ -517,8 +518,8 @@ bool SkImageShader::doStages(const SkStageRec& rec, TransformShader* updater) co
SkColorSpace* cs = pm.colorSpace(); SkColorSpace* cs = pm.colorSpace();
SkAlphaType at = pm.alphaType(); SkAlphaType at = pm.alphaType();
// Color for A8 images comes from the paint. TODO: all alpha images? none? // Color for alpha-only images comes from the paint.
if (pm.colorType() == kAlpha_8_SkColorType) { if (SkColorTypeIsAlphaOnly(pm.colorType())) {
SkColor4f rgb = rec.fPaint.getColor4f(); SkColor4f rgb = rec.fPaint.getColor4f();
p->append_set_rgb(alloc, rgb); p->append_set_rgb(alloc, rgb);