void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorBLACK); SkPaint paint; for (int i = 0; i < 4; i++) { SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get(); SkIRect cropRect = SkIRect::MakeXYWH(i * 12, i * 8, image->width() - i * 8, image->height() - i * 12); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image)); SkScalar dx = SkIntToScalar(i*5); SkScalar dy = SkIntToScalar(i*10); SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(dx, dy, tileInput, &rect)); paint.setImageFilter(filter); DrawClippedImage(canvas, image, paint, 1, cropRect); canvas->translate(SkIntToScalar(image->width() + MARGIN), 0); } SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(-5, -10, nullptr, &rect)); paint.setImageFilter(filter); DrawClippedImage(canvas, fBitmap.get(), paint, 2, cropRect); }
void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorBLACK); { sk_sp<SkImageFilter> bitmapSource(SkImageSource::Make(fImage)); sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkBlendMode::kSrcIn)); sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::move(bitmapSource))); sk_sp<SkImageFilter> erode(SkErodeImageFilter::Make(4, 4, blur)); sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Make(std::move(cf), std::move(erode))); sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(blur, color, SkBlendMode::kSrcOver)); SkPaint paint; paint.setImageFilter(std::move(merge)); canvas->drawPaint(paint); canvas->translate(SkIntToScalar(100), 0); } { sk_sp<SkImageFilter> morph(SkDilateImageFilter::Make(5, 5, nullptr)); SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, 0, SK_Scalar1, 0, 0, 0, 0, 0, SK_Scalar1, 0, 0, 0, 0, 0, 0.5f, 0 }; sk_sp<SkColorFilter> matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Make(std::move(matrixFilter), std::move(morph))); SkPaint paint; paint.setImageFilter(SkXfermodeImageFilter::Make(SkBlendMode::kSrcOver, std::move(colorMorph))); DrawClippedImage(canvas, fImage.get(), paint); canvas->translate(SkIntToScalar(100), 0); } { SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, 0, SK_Scalar1, 0, 0, 0, 0, 0, SK_Scalar1, 0, 0, 0, 0, 0, 0.5f, 0 }; sk_sp<SkColorFilter> matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Make(std::move(matrixCF), nullptr)); sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(10.0f, 10.f, matrixFilter)); SkPaint paint; paint.setImageFilter( SkXfermodeImageFilter::MakeArithmetic(0, 1, 1, 0, true, std::move(matrixFilter), std::move(offsetFilter), nullptr)); DrawClippedImage(canvas, fImage.get(), paint); canvas->translate(SkIntToScalar(100), 0); } { sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(SkIntToScalar(10), SkIntToScalar(10), nullptr)); SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), SkIntToScalar(100))); SkPaint paint; paint.setImageFilter( SkXfermodeImageFilter::Make(SkBlendMode::kSrcIn, std::move(blur), nullptr, &cropRect)); DrawClippedImage(canvas, fImage.get(), paint); canvas->translate(SkIntToScalar(100), 0); } { // Dilate -> matrix convolution. // This tests that a filter using asFragmentProcessor (matrix // convolution) correctly handles a non-zero source offset // (supplied by the dilate). sk_sp<SkImageFilter> dilate(SkDilateImageFilter::Make(5, 5, nullptr)); SkScalar kernel[9] = { SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1), SkIntToScalar(-1), SkIntToScalar( 7 ), SkIntToScalar(-1), SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1), }; SkISize kernelSize = SkISize::Make(3, 3); SkScalar gain = 1.0f, bias = SkIntToScalar(0); SkIPoint kernelOffset = SkIPoint::Make(1, 1); auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode; bool convolveAlpha = false; sk_sp<SkImageFilter> convolve(SkMatrixConvolutionImageFilter::Make(kernelSize, kernel, gain, bias, kernelOffset, tileMode, convolveAlpha, std::move(dilate))); SkPaint paint; paint.setImageFilter(std::move(convolve)); DrawClippedImage(canvas, fImage.get(), paint); canvas->translate(SkIntToScalar(100), 0); } { // Test that crop offsets are absolute, not relative to the parent's crop rect. sk_sp<SkColorFilter> cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkBlendMode::kSrcIn)); sk_sp<SkColorFilter> cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkBlendMode::kSrcIn)); SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(80), SkIntToScalar(80))); SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(60), SkIntToScalar(60))); sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Make(std::move(cf1), nullptr, &outerRect)); sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Make(std::move(cf2), std::move(color1), &innerRect)); SkPaint paint; paint.setImageFilter(std::move(color2)); paint.setColor(SK_ColorRED); canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint); canvas->translate(SkIntToScalar(100), 0); } }
bool plDynamicTextMap::MsgReceive( plMessage *msg ) { plDynamicTextMsg *textMsg = plDynamicTextMsg::ConvertNoRef( msg ); if( textMsg != nil ) { if( textMsg->fCmd & plDynamicTextMsg::kClear ) ClearToColor( textMsg->fClearColor ); if( textMsg->fCmd & plDynamicTextMsg::kSetTextColor ) SetTextColor( textMsg->fColor, textMsg->fBlockRGB ); if( (textMsg->fCmd & plDynamicTextMsg::kSetFont ) && textMsg->fString) SetFont( textMsg->fString, textMsg->fX, (uint8_t)(textMsg->fFlags) ); if( textMsg->fCmd & plDynamicTextMsg::kSetLineSpacing ) SetLineSpacing( textMsg->fLineSpacing ); if( textMsg->fCmd & plDynamicTextMsg::kSetJustify ) SetJustify( (Justify)textMsg->fFlags ); if( textMsg->fCmd & plDynamicTextMsg::kFillRect ) FillRect( textMsg->fLeft, textMsg->fTop, textMsg->fRight - textMsg->fLeft + 1, textMsg->fBottom - textMsg->fTop + 1, textMsg->fColor ); if( textMsg->fCmd & plDynamicTextMsg::kFrameRect ) FrameRect( textMsg->fLeft, textMsg->fTop, textMsg->fRight - textMsg->fLeft + 1, textMsg->fBottom - textMsg->fTop + 1, textMsg->fColor ); if( (textMsg->fCmd & plDynamicTextMsg::kDrawString ) && textMsg->fString) DrawString( textMsg->fX, textMsg->fY, textMsg->fString ); if( (textMsg->fCmd & plDynamicTextMsg::kDrawClippedString ) && textMsg->fString) DrawClippedString( textMsg->fX, textMsg->fY, textMsg->fString, textMsg->fLeft, textMsg->fTop, textMsg->fRight - textMsg->fLeft + 1, textMsg->fBottom - textMsg->fTop + 1 ); if( (textMsg->fCmd & plDynamicTextMsg::kDrawWrappedString ) && textMsg->fString) DrawWrappedString( textMsg->fX, textMsg->fY, textMsg->fString, textMsg->fRight, textMsg->fBottom ); if( textMsg->fCmd & plDynamicTextMsg::kDrawImage ) { plMipmap *mip = plMipmap::ConvertNoRef( textMsg->fImageKey ? textMsg->fImageKey->ObjectIsLoaded() : nil); if( mip != nil ) DrawImage( textMsg->fX, textMsg->fY, mip, textMsg->fFlags ? kImgBlend : kImgNoAlpha ); } if( textMsg->fCmd & plDynamicTextMsg::kDrawClippedImage ) { plMipmap *mip = plMipmap::ConvertNoRef( textMsg->fImageKey ? textMsg->fImageKey->ObjectIsLoaded() : nil); if( mip != nil ) DrawClippedImage( textMsg->fX, textMsg->fY, mip, textMsg->fLeft, textMsg->fTop, textMsg->fRight, textMsg->fBottom, textMsg->fFlags ? kImgBlend : kImgNoAlpha ); } if( textMsg->fCmd & plDynamicTextMsg::kFlush ) FlushToHost(); if( textMsg->fCmd & plDynamicTextMsg::kPurgeImage ) PurgeImage(); return true; } return plMipmap::MsgReceive( msg ); }