SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); }
uint32_t uniqueID() const { return fUniqueID; }
SkAlphaType alphaType() const;
+
+ /**
+ * Returns true fi the image will be drawn as a mask, with no intrinsic color of its own.
+ */
+ bool isAlphaOnly() const;
bool isOpaque() const { return SkAlphaTypeIsOpaque(this->alphaType()); }
/**
return as_IB(this)->onIsLazyGenerated();
}
+bool SkImage::isAlphaOnly() const {
+ return as_IB(this)->onImageInfo().colorType() == kAlpha_8_SkColorType;
+}
+
//////////////////////////////////////////////////////////////////////////////////////
#if !SK_SUPPORT_GPU
}
#endif
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+#include "SkPictureRecorder.h"
+
+static sk_sp<SkPicture> make_picture() {
+ SkPictureRecorder recorder;
+ SkCanvas* canvas = recorder.beginRecording({ 0, 0, 10, 10 });
+ canvas->drawColor(SK_ColorRED);
+ return recorder.finishRecordingAsPicture();
+}
+
+DEF_TEST(Image_isAlphaOnly, reporter) {
+ SkPMColor pmColors = 0;
+ SkPixmap pmap = {
+ SkImageInfo::MakeN32Premul(1, 1),
+ &pmColors,
+ sizeof(pmColors)
+ };
+ for (auto& image : {
+ SkImage::MakeRasterCopy(pmap),
+ GetResourceAsImage("mandrill_128.png"),
+ GetResourceAsImage("color_wheel.jpg"),
+ SkImage::MakeFromPicture(make_picture(), { 10, 10 }, nullptr, nullptr),
+ })
+ {
+ REPORTER_ASSERT(reporter, image->isAlphaOnly() == false);
+ }
+
+ REPORTER_ASSERT(reporter, SkImage::MakeRasterCopy({
+ SkImageInfo::MakeA8(1, 1), (uint8_t*)&pmColors, 1})->isAlphaOnly() == true);
+}