ok, add a8 dst support

Change-Id: Ib7f855c833c8e73f448de7c8a75f59b1a0880874
Reviewed-on: https://skia-review.googlesource.com/53600
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Mike Klein 2017-09-29 15:43:28 -04:00 committed by Skia Commit-Bot
parent 3ec9573ac3
commit 9a3478bf82
2 changed files with 32 additions and 2 deletions

View File

@ -14,6 +14,7 @@ struct SWDst : Dst {
static std::unique_ptr<Dst> Create(Options options) {
SkImageInfo info = SkImageInfo::MakeN32Premul(0,0);
if (options("ct") == "a8") { info = info.makeColorType(kAlpha_8_SkColorType); }
if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); }
if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); }
@ -41,6 +42,11 @@ struct SWDst : Dst {
static Register sw{"sw", "draw with the software backend", SWDst::Create};
static Register _8888{"8888", "alias for sw", SWDst::Create};
static Register a8{"a8", "alias for sw:ct=a8", [](Options options) {
options["ct"] = "a8";
return SWDst::Create(options);
}};
static Register _565{"565", "alias for sw:ct=565", [](Options options) {
options["ct"] = "565";
return SWDst::Create(options);

View File

@ -6,6 +6,7 @@
*/
#include "ProcStats.h"
#include "SkColorFilter.h"
#include "SkEventTracingPriv.h"
#include "SkImage.h"
#include "SkOSFile.h"
@ -135,9 +136,32 @@ struct Png : Dst {
}
SkBitmap bm;
if (!target->image()->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode)) {
return Status::Failed;
}
// SkPngEncoder can't encode A8 .pngs, and even if it could, they'd be a pain to look at.
if (bm.colorType() == kAlpha_8_SkColorType) {
SkPaint paint;
SkScalar alpha_to_opaque_gray[20] = {
0,0,0,1, 0, // red = alpha
0,0,0,1, 0, // green = alpha
0,0,0,1, 0, // blue = alpha
0,0,0,0,255, // alpha = 255
};
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(alpha_to_opaque_gray));
paint.setBlendMode(SkBlendMode::kSrc);
SkBitmap dst;
dst.allocN32Pixels(bm.width(), bm.height(), /*isOpaque=*/true);
SkCanvas canvas(dst);
canvas.drawBitmap(bm, 0,0, &paint);
bm = dst;
}
SkPixmap pm;
if (!target->image()->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode) ||
!bm.peekPixels(&pm)) {
if (!bm.peekPixels(&pm)) {
return Status::Failed;
}