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:
parent
f1660bf1ba
commit
ddbe115d27
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "include/core/SkColorSpace.h"
|
||||
#include "include/private/SkImageInfoPriv.h"
|
||||
#include "src/core/SkArenaAlloc.h"
|
||||
#include "src/core/SkColorSpacePriv.h"
|
||||
#include "src/core/SkColorSpaceXformSteps.h"
|
||||
@ -120,16 +121,16 @@ public:
|
||||
SkRasterPipeline p(fAlloc);
|
||||
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.
|
||||
p.append_set_rgb(fAlloc, fPaintColor);
|
||||
p.append(SkRasterPipeline::premul);
|
||||
}
|
||||
if (auto dstCS = fDst.colorSpace()) {
|
||||
auto srcCS = fSource.colorSpace();
|
||||
if (!srcCS || fSource.colorType() == kAlpha_8_SkColorType) {
|
||||
if (!srcCS || SkColorTypeIsAlphaOnly(fSource.colorType())) {
|
||||
// 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();
|
||||
}
|
||||
auto srcAT = fSource.isOpaque() ? kOpaque_SkAlphaType
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "include/core/SkString.h"
|
||||
#include "include/core/SkStrokeRec.h"
|
||||
#include "include/private/SkColorData.h"
|
||||
#include "include/private/SkImageInfoPriv.h"
|
||||
#include "include/private/SkMacros.h"
|
||||
#include "include/private/SkTemplates.h"
|
||||
#include "include/private/SkTo.h"
|
||||
@ -968,8 +969,8 @@ void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix,
|
||||
return;
|
||||
}
|
||||
|
||||
if (bitmap.colorType() != kAlpha_8_SkColorType
|
||||
&& SkTreatAsSprite(matrix, bitmap.dimensions(), sampling, *paint)) {
|
||||
if (!SkColorTypeIsAlphaOnly(bitmap.colorType()) &&
|
||||
SkTreatAsSprite(matrix, bitmap.dimensions(), sampling, *paint)) {
|
||||
//
|
||||
// It is safe to call lock pixels now, since we know the matrix is
|
||||
// (more or less) identity.
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "src/shaders/SkImageShader.h"
|
||||
|
||||
#include "include/private/SkImageInfoPriv.h"
|
||||
#include "src/core/SkArenaAlloc.h"
|
||||
#include "src/core/SkColorSpacePriv.h"
|
||||
#include "src/core/SkColorSpaceXformSteps.h"
|
||||
@ -317,7 +318,7 @@ sk_sp<SkShader> SkMakeBitmapShaderForPaint(const SkPaint& paint, const SkBitmap&
|
||||
if (!s) {
|
||||
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
|
||||
// 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).
|
||||
@ -517,8 +518,8 @@ bool SkImageShader::doStages(const SkStageRec& rec, TransformShader* updater) co
|
||||
SkColorSpace* cs = pm.colorSpace();
|
||||
SkAlphaType at = pm.alphaType();
|
||||
|
||||
// Color for A8 images comes from the paint. TODO: all alpha images? none?
|
||||
if (pm.colorType() == kAlpha_8_SkColorType) {
|
||||
// Color for alpha-only images comes from the paint.
|
||||
if (SkColorTypeIsAlphaOnly(pm.colorType())) {
|
||||
SkColor4f rgb = rec.fPaint.getColor4f();
|
||||
p->append_set_rgb(alloc, rgb);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user