virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmap(); make_checkerboard(); fInitialized = true; } canvas->clear(0x00000000); SkPaint paint; for (int i = 0; i < 4; i++) { SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; SkIRect cropRect = SkIRect::MakeXYWH(i * 12, i * 8, bitmap->width() - i * 8, bitmap->height() - i * 12); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); SkAutoTUnref<SkImageFilter> tileInput(SkBitmapSource::Create(*bitmap)); SkScalar dx = SkIntToScalar(i*5); SkScalar dy = SkIntToScalar(i*10); SkAutoTUnref<SkImageFilter> filter( SkOffsetImageFilter::Create(dx, dy, tileInput, &rect)); paint.setImageFilter(filter); drawClippedBitmap(canvas, *bitmap, paint, SK_Scalar1, cropRect); canvas->translate(SkIntToScalar(bitmap->width() + MARGIN), 0); } SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); SkAutoTUnref<SkImageFilter> filter( SkOffsetImageFilter::Create(SkIntToScalar(-5), SkIntToScalar(-10), NULL, &rect)); paint.setImageFilter(filter); drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(2), cropRect); }
void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorBLACK); SkPaint paint; for (int i = 0; i < 4; i++) { const SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; SkIRect cropRect = SkIRect::MakeXYWH(i * 12, i * 8, bitmap->width() - i * 8, bitmap->height() - i * 12); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); SkAutoTUnref<SkImageFilter> tileInput(SkBitmapSource::Create(*bitmap)); SkScalar dx = SkIntToScalar(i*5); SkScalar dy = SkIntToScalar(i*10); SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(dx, dy, tileInput, &rect)); paint.setImageFilter(filter); drawClippedBitmap(canvas, *bitmap, paint, 1, cropRect); canvas->translate(SkIntToScalar(bitmap->width() + MARGIN), 0); } SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(-5, -10, NULL, &rect)); paint.setImageFilter(filter); drawClippedBitmap(canvas, fBitmap, paint, 2, cropRect); }
virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmap(); make_checkerboard(); fInitialized = true; } canvas->clear(0x00000000); SkPaint paint; int x = 0, y = 0; for (size_t i = 0; i < 4; i++) { SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; SkIRect cropRect = SkIRect::MakeXYWH(x + i * 12, y + i * 8, bitmap->width() - i * 8, bitmap->height() - i * 12); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); SkAutoTUnref<SkImageFilter> tileInput(SkNEW_ARGS(SkBitmapSource, (*bitmap))); SkScalar dx = SkIntToScalar(i*5); SkScalar dy = SkIntToScalar(i*10); SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( SkOffsetImageFilter, (dx, dy, tileInput, &rect))); paint.setImageFilter(filter); drawClippedBitmap(canvas, *bitmap, paint, SkIntToScalar(x), SkIntToScalar(y)); x += bitmap->width() + MARGIN; if (x + bitmap->width() > WIDTH) { x = 0; y += bitmap->height() + MARGIN; } } }
DEF_FUZZ(SerializedImageFilter, f) { fuzz = f; SkPaint paint; paint.setImageFilter(make_serialized_image_filter()); SkBitmap bitmap; SkCanvas canvas(bitmap); drawClippedBitmap(&canvas, 0, 0, paint); }
void onDraw(int loops, SkCanvas* canvas) override { SkPaint paint; sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); // Displacement, with 1 alpha component (which isn't pre-multiplied) paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ.get()))->unref(); for (int i = 0; i < loops; i++) { drawClippedBitmap(canvas, 100, 0, paint); } }
static void do_fuzz(SkCanvas* canvas) { SkImageFilter* filter = make_serialized_image_filter(); #ifdef SK_FUZZER_IS_VERBOSE static uint32_t numFilters = 0; static uint32_t numValidFilters = 0; if (0 == numFilters) { printf("Fuzzing with %u\n", kSeed); } numFilters++; if (filter) { numValidFilters++; } printf("Filter no : %u. Valid filters so far : %u\r", numFilters, numValidFilters); fflush(stdout); #endif SkPaint paint; SkSafeUnref(paint.setImageFilter(filter)); drawClippedBitmap(canvas, 0, 0, paint); }
virtual void onDraw(SkCanvas* canvas) { if (!fOnce) { make_bitmap(); fOnce = true; } struct { int fWidth, fHeight; int fRadiusX, fRadiusY; } samples[] = { { 140, 140, 0, 0 }, { 140, 140, 0, 2 }, { 140, 140, 2, 0 }, { 140, 140, 2, 2 }, { 24, 24, 25, 25 }, }; SkPaint paint; SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(25, 20, 100, 80)); for (unsigned j = 0; j < 4; ++j) { for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) { const SkImageFilter::CropRect* cr = j & 0x02 ? &cropRect : NULL; if (j & 0x01) { paint.setImageFilter(SkErodeImageFilter::Create( samples[i].fRadiusX, samples[i].fRadiusY, NULL, cr))->unref(); } else { paint.setImageFilter(SkDilateImageFilter::Create( samples[i].fRadiusX, samples[i].fRadiusY, NULL, cr))->unref(); } drawClippedBitmap(canvas, paint, i * 140, j * 140); } } }
virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmaps(); fInitialized = true; } canvas->clear(0x00000000); SkPaint paint; SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unref(); drawClippedBitmap(canvas, 0, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unref(); drawClippedBitmap(canvas, 100, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unref(); drawClippedBitmap(canvas, 200, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ))->unref(); drawClippedBitmap(canvas, 300, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ))->unref(); drawClippedBitmap(canvas, 400, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 0, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 100, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 200, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 300, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 400, 100, paint); SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(30, 30, 40, 40)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 0, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 100, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 200, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 300, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 400, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 0, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 100, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 200, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 300, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 400, 300, paint); // Tests for images of different sizes displ.reset(SkBitmapSource::Create(fSmall)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 0, 400, paint); displ.reset(SkBitmapSource::Create(fLarge)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 100, 400, paint); displ.reset(SkBitmapSource::Create(fLargeW)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 200, 400, paint); displ.reset(SkBitmapSource::Create(fLargeH)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 300, 400, paint); // Test for no given displacement input. In this case, both displacement // and color should use the same bitmap, given to SkCanvas::drawBitmap() // as an input argument. paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, NULL))->unref(); drawClippedBitmap(canvas, 400, 400, paint); }
virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmap(); fInitialized = true; } canvas->clear(0xFF101010); SkPaint checkPaint; checkPaint.setColor(0xFF202020); for (int y = 0; y < HEIGHT; y += 16) { for (int x = 0; x < WIDTH; x += 16) { canvas->save(); canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), checkPaint); canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), checkPaint); canvas->restore(); } } SkPoint3 pointLocation(0, 0, SkIntToScalar(10)); SkScalar azimuthRad = SkDegreesToRadians(SkIntToScalar(225)); SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5)); SkPoint3 distantDirection(SkScalarMul(SkScalarCos(azimuthRad), SkScalarCos(elevationRad)), SkScalarMul(SkScalarSin(azimuthRad), SkScalarCos(elevationRad)), SkScalarSin(elevationRad)); SkPoint3 spotLocation(SkIntToScalar(-10), SkIntToScalar(-10), SkIntToScalar(20)); SkPoint3 spotTarget(SkIntToScalar(40), SkIntToScalar(40), 0); SkScalar spotExponent = SK_Scalar1; SkScalar cutoffAngle = SkIntToScalar(15); SkScalar kd = SkIntToScalar(2); SkScalar ks = SkIntToScalar(1); SkScalar shininess = SkIntToScalar(8); SkScalar surfaceScale = SkIntToScalar(1); SkColor white(0xFFFFFFFF); SkPaint paint; SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65)); int y = 0; for (int i = 0; i < 2; i++) { const SkImageFilter::CropRect* cr = (i == 0) ? NULL : &cropRect; paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 0, y); paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(distantDirection, white, surfaceScale, kd, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 110, y); paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 220, y); y += 110; paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(pointLocation, white, surfaceScale, ks, shininess, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 0, y); paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular(distantDirection, white, surfaceScale, ks, shininess, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 110, y); paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shininess, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 220, y); y += 110; } }
virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmap(); make_checkerboard(); fInitialized = true; } canvas->clear(0x00000000); SkPaint paint; const struct { SkXfermode::Mode fMode; const char* fLabel; } gModes[] = { { SkXfermode::kClear_Mode, "Clear" }, { SkXfermode::kSrc_Mode, "Src" }, { SkXfermode::kDst_Mode, "Dst" }, { SkXfermode::kSrcOver_Mode, "SrcOver" }, { SkXfermode::kDstOver_Mode, "DstOver" }, { SkXfermode::kSrcIn_Mode, "SrcIn" }, { SkXfermode::kDstIn_Mode, "DstIn" }, { SkXfermode::kSrcOut_Mode, "SrcOut" }, { SkXfermode::kDstOut_Mode, "DstOut" }, { SkXfermode::kSrcATop_Mode, "SrcATop" }, { SkXfermode::kDstATop_Mode, "DstATop" }, { SkXfermode::kXor_Mode, "Xor" }, { SkXfermode::kPlus_Mode, "Plus" }, { SkXfermode::kModulate_Mode, "Modulate" }, { SkXfermode::kScreen_Mode, "Screen" }, { SkXfermode::kOverlay_Mode, "Overlay" }, { SkXfermode::kDarken_Mode, "Darken" }, { SkXfermode::kLighten_Mode, "Lighten" }, { SkXfermode::kColorDodge_Mode, "ColorDodge" }, { SkXfermode::kColorBurn_Mode, "ColorBurn" }, { SkXfermode::kHardLight_Mode, "HardLight" }, { SkXfermode::kSoftLight_Mode, "SoftLight" }, { SkXfermode::kDifference_Mode, "Difference" }, { SkXfermode::kExclusion_Mode, "Exclusion" }, { SkXfermode::kMultiply_Mode, "Multiply" }, { SkXfermode::kHue_Mode, "Hue" }, { SkXfermode::kSaturation_Mode, "Saturation" }, { SkXfermode::kColor_Mode, "Color" }, { SkXfermode::kLuminosity_Mode, "Luminosity" }, }; int x = 0, y = 0; SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard))); for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode)); SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( SkXfermodeImageFilter, (mode, background))); paint.setImageFilter(filter); drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScalar(y)); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; y += fBitmap.height() + MARGIN; } } // Test arithmetic mode as image filter SkAutoTUnref<SkXfermode> mode(SkArithmeticMode::Create(0, SK_Scalar1, SK_Scalar1, 0)); SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(SkXfermodeImageFilter, (mode, background))); paint.setImageFilter(filter); drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScalar(y)); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; y += fBitmap.height() + MARGIN; } // Test NULL mode filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (NULL, background))); paint.setImageFilter(filter); drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScalar(y)); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; y += fBitmap.height() + MARGIN; } // Test offsets on SrcMode (uses fixed-function blend) SkAutoTUnref<SkImageFilter> foreground(SkNEW_ARGS(SkBitmapSource, (fBitmap))); SkAutoTUnref<SkImageFilter> offsetForeground(SkNEW_ARGS(SkOffsetImageFilter, (SkIntToScalar(4), SkIntToScalar(-4), foreground))); SkAutoTUnref<SkImageFilter> offsetBackground(SkNEW_ARGS(SkOffsetImageFilter, (SkIntToScalar(4), SkIntToScalar(4), background))); mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground, offsetForeground))); paint.setImageFilter(filter); canvas->save(); canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(fBitmap.width() + 4), SkIntToScalar(fBitmap.height() + 4))); canvas->drawPaint(paint); canvas->restore(); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; y += fBitmap.height() + MARGIN; } // Test offsets on Darken (uses shader blend) mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode)); filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground, offsetForeground))); paint.setImageFilter(filter); canvas->save(); canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(fBitmap.width() + 4), SkIntToScalar(fBitmap.height() + 4))); canvas->drawPaint(paint); canvas->restore(); }